## SpellRegistry — 法术注册表(Autoload: SpellRegistry) ## 纯数据驱动:唯一来源 res://data/spells.json(游戏设计器「法术」面板维护) ## 无硬编码回退——法术定义只存在于 JSON。 extends Node const JSON_DATA_PATH: String = "res://data/spells.json" var _registry: Dictionary = {} # { spell_id: String → SpellNode } func _ready() -> void: if not FileAccess.file_exists(JSON_DATA_PATH): push_error("SpellRegistry: 缺失 res://data/spells.json(无任何法术定义)") return var data = JSON.parse_string(FileAccess.get_file_as_string(JSON_DATA_PATH)) if not (data is Dictionary): push_error("SpellRegistry: spells.json 格式错误(应为对象)") return for sid in data: _registry[String(sid)] = _spell_from_dict(String(sid), data[sid]) func _spell_from_dict(sid: String, d: Dictionary) -> SpellNode: var n := SpellNode.new() n.id = sid n.type = int(d.get("type", 0)) n.display_name = String(d.get("display_name", sid)) n.description = String(d.get("description", "")) n.element_tags = d.get("element_tags", []) n.meta = d.get("meta", {}) return n ## 运行时动态注册(如共鸣产出、未来扩展),非数据来源 func register_spell(spell: SpellNode) -> void: if spell and spell.id != "": _registry[spell.id] = spell func get_spell(id: String) -> SpellNode: return _registry.get(id, null) func get_all_ids() -> Array: return _registry.keys() func has_spell(id: String) -> bool: return _registry.has(id) func get_registry_size() -> int: return _registry.size()