archived/godot-desktop-app/SKILL.md
Godot 4.x 桌面应用开发模板技能。当用户使用 Godot 引擎开发桌面应用(非游戏)时使用此技能,涵盖架构设计、GDScript 编码模式、UI 管理、状态持久化、模块化插件系统等。触发场景包括:(1) 新建 Godot 桌面应用项目 (2) 设计 Godot 应用架构 (3) 实现 GraphEdit/GraphNode 可视化编辑器 (4) GDScript 4.x 编码模式参考 (5) 桌面应用 UI/窗口/面板管理 (6) 项目状态持久化和配置管理。
npx skillsauth add cruldra/skills godot-desktop-appInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
基于 Arrow(叙事设计工具)项目提炼的 Godot 4.x 桌面应用开发最佳实践。
Godot 桌面应用采用 中央事件调度 + 模块化核心 + 可扩展插件 三层架构:
Main (根节点)
├── CentralMind # 中央事件调度器,应用的"大脑"
├── Configuration # 配置生命周期管理
├── MainUserInterface # UI/面板/主题管理
├── ProjectManagement # 项目 CRUD 和持久化
├── NodeTypes # 模块化插件发现与加载
└── Editor # 业务 UI(GraphEdit 编辑器等)
request_mind 信号 → central_event_dispatcher 路由通信class_name Module + class Handler 模式,外部类做声明,内部类做实现call_deferred() / set_deferred()gl_compatibility(桌面应用无需高级渲染)project.godot 中配置:
application/run/low_processor_mode = true(降低空闲 CPU 占用)display/window/subwindows/embed_subwindows = false(允许独立子窗口)application/config/custom_user_dir_nameMain 根节点的 _ready() 中初始化所有核心引用# main.gd
extends Node
@onready var Mind = $Mind
@onready var Configs = $Configs
@onready var UI = $UserInterface
var _MIND: CentralMind.Mind
var _CONFIGS: Configuration.ConfigHandler
var _UI: MainUserInterface.UiManager
func _ready() -> void:
_CONFIGS = Configs.setup(self)
_UI = UI.setup(self, _CONFIGS)
_MIND = Mind.setup(self, _CONFIGS)
# 解析 CLI 参数
_handle_cli_args()
详细的架构模式、数据结构和实现指南,见 references/architecture.md。
包含:
GDScript 4.x 特有的编码模式和最佳实践,见 references/gdscript-patterns.md。
包含:
标准的 Godot 桌面应用项目目录结构,见 references/project-structure.md。
包含:
# 三种面板类型
enum PanelType { BLOCKING, STATEFUL, DEFAULT_OPEN }
# BLOCKING: 模态面板,打开时阻止其他操作(如项目选择器)
# STATEFUL: 可记忆开关状态的面板(如属性检查器)
# DEFAULT_OPEN: 默认打开的面板
func _save_window_state() -> void:
var config = {
"window": {
"screen": get_window().current_screen,
"maximized": (get_window().mode == Window.MODE_MAXIMIZED),
"size": [get_window().size.x, get_window().size.y],
"position": [get_window().position.x, get_window().position.y]
},
"panels": _panel_visibility_map
}
_config_handler.save(config)
func _restore_window_state(config: Dictionary) -> void:
var win = config.get("window", {})
if win.has("screen"):
get_window().current_screen = win.screen
if win.get("maximized", false):
get_window().mode = Window.MODE_MAXIMIZED
else:
get_window().size = Vector2i(win.size[0], win.size[1])
get_window().position = Vector2i(win.position[0], win.position[1])
func _notification(what: int) -> void:
if what == NOTIFICATION_WM_CLOSE_REQUEST:
_save_all_state()
get_tree().quit()
func _save_all_state() -> void:
_UI._save_window_state()
_CONFIGS.confirm() # TEMPORARY → CONFIRMED
if _has_unsaved_changes:
_auto_save_project()
| 格式 | 适用场景 | 方法 |
|------|---------|------|
| JSON | 项目数据、可人读 | JSON.stringify() / JSON.parse_string() |
| Variant | 内部缓存、高性能 | var_to_str() / str_to_var() |
| ConfigFile | INI 风格配置 | ConfigFile.save() / .load() |
# 项目列表文件结构 (project_list.json)
{
"projects": [
{ "title": "项目A", "last_save": 1706000000, "path": "/path/to/project.json" }
]
}
# 单个项目文件结构
{
"title": "我的项目",
"entry": "scene_001",
"meta": { "authors": [], "last_save": 0, "editor": "1.0.0" },
"resources": {
"scenes": {},
"nodes": {},
"variables": {},
"characters": {}
}
}
GraphEdit 是 Godot 桌面应用中实现节点图编辑器的核心控件。
# grid_graph_edit.gd
extends GraphEdit
func _ready() -> void:
# 连接信号
connection_request.connect(_on_connection_request)
disconnection_request.connect(_on_disconnection_request)
node_selected.connect(_on_node_selected)
node_deselected.connect(_on_node_deselected)
delete_nodes_request.connect(_on_delete_nodes_request)
func _on_connection_request(from_node, from_port, to_node, to_port) -> void:
connect_node(from_node, from_port, to_node, to_port)
_notify_mind("node_connected", { ... })
# 每个节点类型继承 GraphNode
extends GraphNode
var _node_id: int
var _node_resource: Dictionary
var _node_map: Dictionary # 引用中央数据
func _update_node(data: Dictionary) -> void:
# 从数据更新 UI
pass
func _read_node() -> Dictionary:
# 从 UI 读取数据
return {}
将项目数据嵌入 HTML 模板实现独立运行的导出:
func export_as_html(project: Dictionary, template_path: String, output_path: String) -> void:
var template = FileAccess.get_file_as_string(template_path)
var data_json = JSON.stringify(project)
var html = template.replace("{{PROJECT_DATA}}", data_json)
var file = FileAccess.open(output_path, FileAccess.WRITE)
file.store_string(html)
遍历节点提取可翻译文本:
func export_csv(project: Dictionary) -> PackedStringArray:
var lines: PackedStringArray = ["key,original,translation"]
for node_id in project.resources.nodes:
var node = project.resources.nodes[node_id]
# 提取含文本的字段
for field in _get_translatable_fields(node):
lines.append("%s,%s," % [field.key, field.value])
return lines
low_processor_mode,否则空闲时 CPU 占用过高false 允许独立弹窗(文件对话框等)call_deferred() 或 set_deferred() 避免竞态@warning_ignore("unused_variable") 等抑制已知警告custom_user_dir_name 隔离应用数据,避免污染默认 Godot 目录OS.get_cmdline_args() 支持 --sandbox、--config-dir 等启动参数testing
智能体 UAT 验收测试技能。用于验证智能体在真实场景下的表现是否满足预期。支持任意智能体框架(langchain、langgraph、deepagents、crewai 等)。触发词:测试智能体、验收测试、agent test、UAT
tools
Use when you need to create a Gitea issue, update its spec/plan markers, read or merge an issue's state JSON, or post a PR review comment in a repo that uses the spx CLI (superpowers-vscode workflow).
development
Use when implementing, modifying, refactoring, or reviewing code and the agent must follow explicit coding standards for simplicity, readability, maintainability, testability, project conventions, and minimal safe changes.
development
Use when integrating the deepagents SDK into a Python project — creating agents, configuring backends, adding subagents, middleware, memory, or skills. Also use when debugging deepagents agents or choosing between StateBackend, FilesystemBackend, and LocalShellBackend.