41 lines
1.5 KiB
GDScript
41 lines
1.5 KiB
GDScript
## StatusRegistry — 状态效果注册表(Autoload: StatusRegistry)
|
||
## 纯数据驱动:唯一来源 res://data/status_effects.json(游戏设计器「状态」面板维护)
|
||
extends Node
|
||
|
||
const STATUS_JSON: String = "res://data/status_effects.json"
|
||
|
||
var _registry: Dictionary = {} # { status_id: int → StatusTypeDef }
|
||
|
||
func _ready() -> void:
|
||
if not FileAccess.file_exists(STATUS_JSON):
|
||
push_error("StatusRegistry: 缺失 res://data/status_effects.json(无状态效果定义)")
|
||
return
|
||
var data = JSON.parse_string(FileAccess.get_file_as_string(STATUS_JSON))
|
||
if not (data is Dictionary):
|
||
push_error("StatusRegistry: status_effects.json 格式错误")
|
||
return
|
||
for k in data:
|
||
var sid: int = int(k)
|
||
var d: Dictionary = data[k]
|
||
var t := StatusTypeDef.new()
|
||
t.id = sid
|
||
t.display_name = String(d.get("name", "Status %d" % sid))
|
||
t.duration = float(d.get("duration", 3.0))
|
||
t.tick_interval = float(d.get("tick_interval", 1.0))
|
||
t.stack_mode = int(d.get("stack_mode", 0))
|
||
t.max_stacks = int(d.get("max_stacks", 1))
|
||
t.dot_damage_per_tick = float(d.get("dot_damage", 0.0))
|
||
t.dot_damage_type = int(d.get("dot_damage_type", 0))
|
||
t.vfx_id = String(d.get("vfx_id", ""))
|
||
t.is_combo_tracker = bool(d.get("is_combo_tracker", false))
|
||
_registry[sid] = t
|
||
|
||
func get_type(status_id: int) -> StatusTypeDef:
|
||
return _registry.get(status_id, null)
|
||
|
||
func has_type(status_id: int) -> bool:
|
||
return _registry.has(status_id)
|
||
|
||
func get_registry_size() -> int:
|
||
return _registry.size()
|