Files
spellforge/scripts/autoloads/wand_preset.gd
T
2026-07-20 10:56:52 +08:00

47 lines
1.9 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## WandPreset — Core(法杖)工厂(Autoload: WandPreset
## 纯数据驱动:Core 定义唯一来源 res://data/cores.json(游戏设计器「Core」面板维护)
## 法术已迁至 SpellRegistrydata/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", [])
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}