diff --git a/scripts/autoloads/player_stats.gd b/scripts/autoloads/player_stats.gd index e5af11b..f2c5d3f 100644 --- a/scripts/autoloads/player_stats.gd +++ b/scripts/autoloads/player_stats.gd @@ -5,6 +5,7 @@ extends Node signal stats_changed signal leveled_up(new_level: int) +# ── 数据源 ──────────────────────────────────────────── const ATTRIBUTES_JSON: String = "res://data/attributes.json" # ── HP ─────────────────────────────────────────────── @@ -152,6 +153,8 @@ func reset_for_run() -> void: ## · source == "core" 的那条**不要**持久化——它在换杖时由 combat_manager._rebuild_wand 重建。 ## · 回读须用 _modifiers.assign(...):JSON.parse_string / data.get(..., []) 产出的是无类型 ## Array,直接 `=` 赋给 Array[Dictionary] 会运行时类型错误。 +## · 回读顺序:_modifiers 必须先 assign + _recompute_attrs(),再赋 hp。反过来会让 +## _recompute_attrs 的 hp = minf(hp, hp_max) 拿未加成的 hp_max 去钳,静默吞血。 func get_save_data() -> Dictionary: return {"hp": hp, "gold": gold, "xp": xp, "level": level} @@ -176,7 +179,7 @@ func _load_attr_definitions() -> void: # 逐条守卫:畸形条目(如 "move_speed": 200)会让 _compute_attr 的 Dictionary 赋值硬崩 for k in parsed: if not (parsed[k] is Dictionary): - push_error("PlayerStats: attributes.json 的「%s」应为对象" % k) + push_error("PlayerStats: attributes.json 的「%s」应为对象,整个文件已拒绝加载" % k) return _attr_def = parsed