Skip to content

文件:manage.py

TUI 管理器基于 Textual,实现关卡列表的新增、排序、启停与同步。

Doctor(配置与插件体检)

运行:

bash
python manage.py doctor

会校验 config/*.json 的结构,并检查 levels/services/ 里的模块能否导入、是否提供 router

模板常量

LEVEL_TEMPLATE

新建关卡时写入 levels/<module>/__init__.py 的模板字符串。 包含 routerCURRENT_LEVEL_INDEXset_level_index/verify 标准接口。

Class: CreateLevelScreen(ModalScreen[dict | None])

职责:收集新关卡的 slugmodulename

方法

  • compose(self) -> ComposeResult
    生成输入框与按钮布局。
  • on_button_pressed(self, event: Button.Pressed) -> None
    Cancel:dismiss(None);Create:校验输入后 dismiss({...})

Class: LevelManagerApp(App)

职责:展示与管理关卡列表。

键位绑定

  • q: Quit
  • space: Enable/Disable
  • shift+up: Move Up
  • shift+down: Move Down
  • n: New
  • s: Sync

方法

  • __init__(self) -> None
    载入 map.jsonself._map
  • compose(self) -> ComposeResult
    生成 Header/DataTable/Footer。
  • on_mount(self) -> None
    初始化表格列并渲染。
  • _refresh_table(self) -> None
    self._map 重新渲染表格。
  • _save(self) -> None
    保存 map.json
  • _selected_index(self) -> int | None
    获取当前选中行。
  • action_toggle(self) -> None
    切换 enabled 状态。
  • action_move_up(self) -> None / action_move_down(self) -> None
    调整关卡顺序。
  • action_new_level(self) -> None
    打开 CreateLevelScreen
  • _handle_new_level(self, result: dict | None) -> None
    追加关卡映射并生成关卡模块目录。
  • _create_level_module(self, module: str) -> None
    创建 levels/<module>/__init__.py
  • action_sync_levels(self) -> None
    扫描 levels/ 新目录并追加到 map(默认禁用)。