一键导入
godot-extract-resources
当 Godot 代码中存在硬编码的游戏数据(如 const 数组、字典或内嵌值)时使用。检测内联数据 如敌人属性、物品定义、关卡配置等。自动提取为 .tres Resource 文件,使数据在编辑器中 可见、易于修改,并支持数据驱动的设计。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
当 Godot 代码中存在硬编码的游戏数据(如 const 数组、字典或内嵌值)时使用。检测内联数据 如敌人属性、物品定义、关卡配置等。自动提取为 .tres Resource 文件,使数据在编辑器中 可见、易于修改,并支持数据驱动的设计。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
当 Godot 代码中存在通过 get_node()、get_parent() 或直接引用产生的紧耦合依赖时使用。 检测耦合模式并将其转换为基于 Signal 的通信方式。组件变得独立、可测试且可复用。 在改进架构的同时精确保留原有行为。
当 Godot 代码中存在相互冲突的操作导致未定义行为时使用。检测同一属性在多处设置 (_ready、_process、代码+编辑器)、同一 Signal 多次连接、冲突的物理模式、 竞争的动画等问题。自动通过明确的所有权归属解决冲突。
用于创建带有自定义面板、停靠栏和工具的 Godot 编辑器插件。生成 plugin.cfg 配置、 EditorPlugin 脚本模板、自定义编辑器 UI 组件,并集成 ProjectSettings。按照 Godot 4.x 最佳实践创建完整的插件结构。
当构建 Godot 功能时,代码使用 .new() 创建节点而非使用场景时触发。 检测 Timer.new()、Area2D.new()、Sprite2D.new() 等代码创建的对象。 自动生成 .tscn 场景文件,更新父脚本使用 @onready 引用,并创建可复用的组件库。
当 Godot 项目在编辑器(.tscn)和代码(.gd)之间存在位置冲突、相机跟随背景、 或运行时位置与编辑器预览不匹配时使用。编排所有 3 个位置同步子技能: sync-static-positions、sync-camera-positions 和 sync-parallax。 每个操作针对特定的位置冲突类型。
在开发 Godot 游戏时需要为 GDScript 类、Signal、场景初始化和集成流程提供全面的测试覆盖时使用。 生成 GUT 框架单元测试、集成测试、Mock/Stub 辅助工具和 CI/CD 测试运行器配置。
| name | godot-extract-resources |
| version | 3.0.0 |
| displayName | 将数据提取为 Resource |
| description | 当 Godot 代码中存在硬编码的游戏数据(如 const 数组、字典或内嵌值)时使用。检测内联数据 如敌人属性、物品定义、关卡配置等。自动提取为 .tres Resource 文件,使数据在编辑器中 可见、易于修改,并支持数据驱动的设计。 |
| author | Asreonn |
| license | MIT |
| category | game-development |
| type | tool |
| difficulty | beginner |
| audience | ["developers"] |
| keywords | ["godot","resources","data-driven","const-arrays","dictionaries","tres-files","gdscript","game-data"] |
| platforms | ["macos","linux","windows"] |
| repository | https://github.com/asreonn/godot-superpowers |
| homepage | https://github.com/asreonn/godot-superpowers#readme |
| permissions | {"filesystem":{"read":[".gd",".tres"],"write":[".gd",".tres",".tscn"]},"git":true} |
| behavior | {"auto_rollback":true,"validation":true,"git_commits":true} |
| outputs | Resource 文件(.tres)、Resource 脚本定义、更新后的引用代码、git 提交 |
| requirements | Git 仓库, Godot 4.x |
| execution | 全自动执行,保留数据完整性 |
| integration | godot-refactor 编排器的一部分,创建数据驱动的架构 |
数据属于 Resource,而非代码。 硬编码的值会使迭代缓慢且容易出错。
查找如下模式:
# enemy.gd
const ENEMY_DATA = {
"goblin": {"health": 50, "speed": 100, "damage": 10},
"orc": {"health": 100, "speed": 80, "damage": 20},
"dragon": {"health": 500, "speed": 150, "damage": 50}
}
转换为:
# enemy_stats.gd
class_name EnemyStats
extends Resource
@export var enemy_name: String
@export var health: int
@export var speed: float
@export var damage: int
创建 Resource 文件:
resources/enemies/goblin.tresresources/enemies/orc.tresresources/enemies/dragon.tres更新代码:
# enemy.gd
@export var stats: EnemyStats
func _ready():
health = stats.health
speed = stats.speed
damage = stats.damage
识别以下模式:
const 数组包含大量物品、敌人、关卡或配置的游戏。
希望无需修改代码即可快速调整数值。
非程序员需要编辑游戏数据。
外部数据文件可实现 Mod 支持。
转换前(硬编码数据):
# item_manager.gd
const ITEMS = [
{
"id": "health_potion",
"name": "Health Potion",
"description": "Restores 50 HP",
"heal_amount": 50,
"icon": "res://icons/potion.png"
},
{
"id": "sword",
"name": "Iron Sword",
"description": "A basic sword",
"damage": 15,
"icon": "res://icons/sword.png"
}
]
func get_item(id: String):
for item in ITEMS:
if item.id == id:
return item
return null
转换后(基于 Resource):
# item_data.gd
class_name ItemData
extends Resource
@export var id: String
@export var item_name: String
@export_multiline var description: String
@export var icon: Texture2D
@export_group("Stats")
@export var heal_amount: int
@export var damage: int
# item_manager.gd
@export var items: Array[ItemData]
func get_item(id: String) -> ItemData:
for item in items:
if item.id == id:
return item
return null
创建的文件:
resources/items/health_potion.tresresources/items/iron_sword.tres单一值(属性、设置、常量)。
Resource 引用其他 Resource(武器 + 属性 + 效果)。
不同类别的 Resource 数组。
基础 Resource 类与特化变体。
resources/ 或 scripts/resources/ 中的 Resource 类定义识别数据类型:
按类别组织:
resources/items/ - 物品数据resources/enemies/ - 敌人属性resources/levels/ - 关卡配置resources/abilities/ - 技能定义可与以下技能配合使用:
以下情况不需要提取:
合理硬编码数据的示例:
const PI = 3.14159const MAX_PLAYERS = 4(引擎限制)resources/
├── items/
│ ├── consumables/
│ │ ├── health_potion.tres
│ │ └── mana_potion.tres
│ └── weapons/
│ ├── iron_sword.tres
│ └── steel_axe.tres
├── enemies/
│ ├── goblin.tres
│ ├── orc.tres
│ └── dragon.tres
└── levels/
├── level_1.tres
└── level_2.tres
| 转换前(硬编码) | 转换后(Resource) |
|---|---|
const STATS = {...} | @export var stats: Stats |
var data = ITEMS[0] | var data = preload("item.tres") |
if type == "fire": | if ability.element == Element.FIRE: |
const CONFIG = {...} | @export var config: GameConfig |