49 lines
2.1 KiB
GDScript
49 lines
2.1 KiB
GDScript
## WandPreset — Core(法杖)工厂(Autoload: WandPreset)
|
||
## 纯数据驱动:Core 定义唯一来源 res://data/cores.json(游戏设计器「Core」面板维护)
|
||
## 法术已迁至 SpellRegistry(data/spells.json),此处不再定义法术。
|
||
extends Node
|
||
|
||
const CORES_JSON: String = "res://data/cores.json"
|
||
var _json_cores: Dictionary = {}
|
||
|
||
func _ready() -> void:
|
||
if not FileAccess.file_exists(CORES_JSON):
|
||
push_error("WandPreset: 缺失 res://data/cores.json(无 Core 定义)")
|
||
return
|
||
var data = JSON.parse_string(FileAccess.get_file_as_string(CORES_JSON))
|
||
if data is Dictionary:
|
||
_json_cores = data
|
||
else:
|
||
push_error("WandPreset: cores.json 格式错误")
|
||
|
||
## 按 ID 创建 Core(纯 cores.json);未知 ID 报错并返回错误安全默认(5 槽 LINEAR)
|
||
func make_core_by_id(cid: String) -> CoreDefinition:
|
||
if _json_cores.has(cid):
|
||
return _core_from_dict(cid, _json_cores[cid])
|
||
push_error("WandPreset: Core '%s' 不在 cores.json" % cid)
|
||
return _core_from_dict(cid, {})
|
||
|
||
func _core_from_dict(cid: String, d: Dictionary) -> CoreDefinition:
|
||
var c := CoreDefinition.new()
|
||
c.id = cid
|
||
c.display_name = String(d.get("display_name", cid))
|
||
c.slot_count = int(d.get("slot_count", 5))
|
||
c.topology = int(d.get("topology", 0))
|
||
c.cpu_limit = int(d.get("cpu_limit", 5))
|
||
c.cast_interval = float(d.get("cast_interval", 0.5))
|
||
c.feature_tags = int(d.get("feature_tags", 0))
|
||
c.grid_rows = int(d.get("grid_rows", 1))
|
||
c.grid_cols = int(d.get("grid_cols", 5))
|
||
c.edges = d.get("edges", [])
|
||
c.base_mana_max = float(d.get("mana_max", 100.0))
|
||
c.base_mana_regen = float(d.get("mana_regen", 5.0))
|
||
return c
|
||
|
||
## 默认装备(combat_test 等用):wand_basic + 第一个 ACTION 法术
|
||
func make_default_loadout() -> Dictionary:
|
||
var core: CoreDefinition = make_core_by_id("wand_basic")
|
||
var spell: SpellNode = SpellRegistry.get_spell("action_spark_bolt")
|
||
var spells: Array = [spell] if spell else []
|
||
var compiled = SpellEvaluator.compile_wand(core, spells)
|
||
return {"core": core, "spells": spells, "compiled": compiled}
|