From 69ddcddba60cd5708a82cc2a55573c64acec6882 Mon Sep 17 00:00:00 2001 From: Joywayer Date: Fri, 31 Jul 2026 11:32:10 +0800 Subject: [PATCH] =?UTF-8?q?docs(attr):=20=E8=A1=A5=E8=AE=B0=E8=B4=A7?= =?UTF-8?q?=E6=9E=B6=20C=20=E7=9A=84=E5=9B=9E=E8=AF=BB=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E9=99=B7=E9=98=B1=EF=BC=9B=E7=95=B8=E5=BD=A2=E6=9D=A1=E7=9B=AE?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E8=AF=B4=E6=98=8E=E6=95=B4=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=B7=B2=E6=8B=92=E7=BB=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 纯注释改动,无行为变更。 1. get_save_data 的货架 C 文档块补回读顺序:_modifiers 必须先 assign + _recompute_attrs(),再赋 hp。反过来会让新加的 hp = minf(hp, hp_max) 拿 未加成的 hp_max 去钳,静默吞血(评审复现:回读 hp=180/100 → 换杖重算后 100/100,丢 80 HP)。今天不可达(hp_max 恒 100),但持久化 _modifiers 一 落地即活,而这个文档块正是那位实现者会读的地方。 2. 畸形条目的 push_error 补「整个文件已拒绝加载」——守卫是 return,一个坏 条目会让四个属性全部退回声明默认值,原文案读起来像只影响那一个键。 3. ATTRIBUTES_JSON 补「数据源」分区横幅,与文件自身风格一致。 Co-Authored-By: Claude Opus 5 --- scripts/autoloads/player_stats.gd | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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