feat(task): 支持kuyo模拟器启动

This commit is contained in:
YXHXianYu 2025-03-12 13:17:04 +08:00
parent 28a8e9d280
commit b7805a24ae
6 changed files with 114 additions and 18 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -392,6 +392,15 @@ class MissionRewardConfig(ConfigBaseModel):
enabled: bool = False
"""是否启用领取任务奖励"""
class StartGameConfig(ConfigBaseModel):
enabled: bool = True
"""
是否启用自动启动游戏默认为True
"""
class StartKuyoAndGameConfig(ConfigBaseModel):
enabled: bool = False
"""是否启用自动启动Kuyo与游戏"""
class BaseConfig(ConfigBaseModel):
purchase: PurchaseConfig = PurchaseConfig()
@ -415,6 +424,11 @@ class BaseConfig(ConfigBaseModel):
mission_reward: MissionRewardConfig = MissionRewardConfig()
"""领取任务奖励配置"""
start_game: StartGameConfig = StartGameConfig()
"""启动游戏配置"""
start_kuyo_and_game: StartKuyoAndGameConfig = StartKuyoAndGameConfig()
"""启动Kuyo与游戏配置"""
def conf() -> BaseConfig:

View File

@ -2,29 +2,17 @@
import logging
from kotonebot import task, device, image, cropped, AdaptiveWait, sleep, ocr
from kotonebot.backend.context.task_action import action
from kotonebot.errors import GameUpdateNeededError
from . import R
from .common import Priority
from .common import Priority, conf
from .actions.loading import loading
from .actions.scenes import at_home, goto_home
from .actions.commu import is_at_commu, handle_unread_commu
logger = logging.getLogger(__name__)
@task('启动游戏', priority=Priority.START_GAME)
def start_game():
"""
启动游戏直到游戏进入首页为止
执行前游戏必须处于未启动状态
"""
# TODO: 包名放到配置文件里
if device.current_package() == 'com.bandainamcoent.idolmaster_gakuen':
logger.info("Game already started")
if not at_home():
logger.info("Not at home, going to home")
goto_home()
return
device.launch_app('com.bandainamcoent.idolmaster_gakuen')
@action('启动游戏公共部分')
def start_game_common():
# [screenshots/startup/1.png]
image.wait_for(R.Daily.ButonLinkData, timeout=30)
sleep(2)
@ -52,6 +40,26 @@ def start_game():
device.click_center()
wait()
@task('启动游戏', priority=Priority.START_GAME)
def start_game():
"""
启动游戏直到游戏进入首页为止
执行前游戏必须处于未启动状态
"""
if not conf().start_game.enabled:
logger.info('"Start game" is disabled.')
return
# TODO: 包名放到配置文件里
if device.current_package() == 'com.bandainamcoent.idolmaster_gakuen':
logger.info("Game already started")
if not at_home():
logger.info("Not at home, going to home")
goto_home()
return
device.launch_app('com.bandainamcoent.idolmaster_gakuen')
start_game_common()
if __name__ == '__main__':
import logging
logging.basicConfig(level=logging.INFO, format='[%(asctime)s] [%(levelname)s] [%(name)s] [%(funcName)s] [%(lineno)d] %(message)s')

View File

@ -0,0 +1,45 @@
"""启动kuyo加速器以及游戏领取登录奖励直到首页为止"""
import logging
from kotonebot import task, device, image, cropped, AdaptiveWait, sleep, ocr
from kotonebot.errors import GameUpdateNeededError
from kotonebot.tasks.start_game import start_game_common
from . import R
from .common import Priority, conf
from .actions.loading import loading
from .actions.scenes import at_home, goto_home
from .actions.commu import is_at_commu, handle_unread_commu
logger = logging.getLogger(__name__)
@task('启动kuyo以及游戏', priority=Priority.START_GAME)
def start_kuyo_and_game():
"""
启动游戏直到游戏进入首页为止
执行前游戏必须处于未启动状态
"""
if not conf().start_kuyo_and_game.enabled:
logger.info('"Start kuyo and game" is disabled.')
return
# TODO: 包名放到配置文件里
if device.current_package() == 'org.kuyo.game':
logger.warning("Kuyo already started")
return
if device.current_package() == 'com.bandainamcoent.idolmaster_gakuen':
logger.warning("Game already started")
return
# 启动kuyo
device.launch_app('org.kuyo.game')
image.wait_for(R.Kuyo.ButtonTab3Speedup, timeout=10)
device.click()
image.wait_for(R.Kuyo.ButtonStartGame, timeout=10)
device.click()
# 启动游戏
start_game_common()
if __name__ == '__main__':
import logging
logging.basicConfig(level=logging.INFO, format='[%(asctime)s] [%(levelname)s] [%(name)s] [%(funcName)s] [%(lineno)d] %(message)s')
logger.setLevel(logging.DEBUG)
start_kuyo_and_game()

View File

@ -13,10 +13,11 @@ import gradio as gr
from kotonebot.backend.context import task_registry, ContextStackVars
from kotonebot.config.manager import load_config, save_config
from kotonebot.tasks import start_game
from kotonebot.tasks.common import (
BaseConfig, APShopItems, PurchaseConfig, ActivityFundsConfig,
PresentsConfig, AssignmentConfig, ContestConfig, ProduceConfig,
MissionRewardConfig, PIdol, DailyMoneyShopItems, ProduceAction
MissionRewardConfig, PIdol, DailyMoneyShopItems, ProduceAction, StartGameConfig, StartKuyoAndGameConfig
)
from kotonebot.config.base_config import UserConfig, BackendConfig
from kotonebot.backend.bot import KotoneBot
@ -257,6 +258,8 @@ class KotoneBotUI:
prefer_lesson_ap: bool,
actions_order: List[str],
mission_reward_enabled: bool,
start_game_enabled: bool,
start_kuyo_and_game_enabled: bool
) -> str:
ap_items_enum: List[Literal[0, 1, 2, 3]] = []
ap_items_map: Dict[str, APShopItems] = {
@ -317,6 +320,12 @@ class KotoneBotUI:
),
mission_reward=MissionRewardConfig(
enabled=mission_reward_enabled
),
start_game=StartGameConfig(
enabled=start_game_enabled
),
start_kuyo_and_game=StartKuyoAndGameConfig(
enabled=start_kuyo_and_game_enabled
)
)
@ -702,6 +711,24 @@ class KotoneBotUI:
info=MissionRewardConfig.model_fields['enabled'].description
)
# 启动游戏设置
with gr.Column():
gr.Markdown("### 启动游戏设置")
start_game_enabled = gr.Checkbox(
label="是否启动自动启动游戏",
value=self.current_config.options.start_game.enabled,
info=StartGameConfig.model_fields['enabled'].description
)
# 启动Kuyo与游戏设置
with gr.Column():
gr.Markdown("### 启动Kuyo与游戏设置")
start_kuyo_and_game_enabled = gr.Checkbox(
label="是否启动自动启动Kuyo与游戏",
value=self.current_config.options.start_kuyo_and_game.enabled,
info=StartKuyoAndGameConfig.model_fields['enabled'].description
)
save_btn = gr.Button("保存设置")
result = gr.Markdown()
@ -716,6 +743,8 @@ class KotoneBotUI:
contest,
*produce_settings,
mission_reward,
start_game_enabled,
start_kuyo_and_game_enabled,
]
save_btn.click(
@ -752,7 +781,7 @@ class KotoneBotUI:
def _create_whats_new_tab(self) -> None:
"""创建更新日志标签页,并显示最新版本更新内容"""
with gr.Tab("更新日志"):
from ..tasks.metadata import WHATS_NEW
from kotonebot.tasks.metadata import WHATS_NEW
gr.Markdown(WHATS_NEW)
def _create_screen_tab(self) -> None: