From 900eaea6970ffbe49e4546813c31d7050bde61b3 Mon Sep 17 00:00:00 2001 From: Joywayer Date: Mon, 3 Aug 2026 11:27:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(shop):=20=E8=B4=A7=E6=9E=B6=20C=20?= =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E6=AC=A1=E6=95=B0=E8=BF=9B=E5=B1=80=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=A1=A3=EF=BC=88schema=202=E2=86=923=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 只存次数不存加成——加成是派生物,回读时经 _apply_attr_purchases 重建。 这也躲开了 E3-① 记录的坑:_modifiers 是 Array[Dictionary],而 JSON 回读的 无类型 Array 直接 = 赋值是运行时类型错误,必须 .assign();存派生源头则不涉及。 回读顺序:attr_purchases 必须早于 load_save_data。后者设 hp,而重建加成会经 _recompute_attrs 触发 hp = minf(hp, hp_max);顺序颠倒会拿未加成的 hp_max 去钳, 静默吞血(hp_max 可买到 180 后即可复现)。 Co-Authored-By: Claude Opus 5 --- scripts/autoloads/profile_manager.gd | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/autoloads/profile_manager.gd b/scripts/autoloads/profile_manager.gd index adbac5c..ccbdcbc 100644 --- a/scripts/autoloads/profile_manager.gd +++ b/scripts/autoloads/profile_manager.gd @@ -7,7 +7,7 @@ ## - NOTIFICATION_WM_CLOSE_REQUEST 尽力写最后一笔 extends Node -const SCHEMA_VERSION: int = 2 # v2:新增 wand(Core/deck/bench)持久化 +const SCHEMA_VERSION: int = 3 # v3:新增 attr_purchases(货架 C 属性购买次数) const PATH_A: String = "user://run_a.json" const PATH_B: String = "user://run_b.json" @@ -63,6 +63,9 @@ func load_run() -> Dictionary: func apply_run(data: Dictionary) -> void: if data.is_empty(): return + # 必须早于 load_save_data:后者设 hp,而 _apply_attr_purchases 会经 _recompute_attrs + # 触发 hp = minf(hp, hp_max)。顺序颠倒会拿未加成的 hp_max 去钳,静默吞血。 + ShopManager.apply_attr_purchases_save(data.get("attr_purchases", {})) PlayerStats.load_save_data(data.get("player_stats", {})) WaveManager.current_wave = int(data.get("wave_num", 0)) var shop_seed: int = int(data.get("shop_seed", 0)) @@ -90,6 +93,7 @@ func _collect_run_data() -> Dictionary: "wave_num": WaveManager.current_wave, "shop_seed": ShopManager.get_shop_seed(), "player_stats": PlayerStats.get_save_data(), + "attr_purchases": ShopManager.get_attr_purchases_save(), } if is_instance_valid(_wand_provider) and _wand_provider.has_method("get_wand_save_data"): d["wand"] = _wand_provider.get_wand_save_data() @@ -115,4 +119,7 @@ func _migrate_run(data: Dictionary) -> Dictionary: if ver < 2: # v1→v2: 旧档无 wand 字段;apply_run 检测缺失即保留默认法杖,无需补字段 data["schema_version"] = 2 + if ver < 3: + # v2→v3: 旧档无 attr_purchases;apply_run 的 data.get(..., {}) 已处理缺失,无需补字段 + data["schema_version"] = 3 return data