From 359da9f24fe3858ad8e11ad5b7a1ee11978d358f Mon Sep 17 00:00:00 2001 From: Joywayer Date: Mon, 3 Aug 2026 10:56:57 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E8=AE=A2=E6=AD=A3=20enum=20Curve=20?= =?UTF-8?q?=E2=86=92=20PriceCurve=EF=BC=88=E4=B8=8E=20Godot=20=E5=86=85?= =?UTF-8?q?=E7=BD=AE=20Curve=20=E8=B5=84=E6=BA=90=E7=B1=BB=E5=86=B2?= =?UTF-8?q?=E7=AA=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task 1 实现时发现:enum Curve 在 4.7.1 解析期即报 "member Curve shadows a native class"——与引擎内置的 Curve 资源类同名。 实现者做了独立最小复现,确认与 class_name 无关。 spec §2.1 与计划 Task 1 的代码块都写着 enum Curve,若不订正,Task 2 的简报 会从计划里抄到错误的类型名。下游一律用 PriceFormula.PriceCurve。 Co-Authored-By: Claude Opus 5 --- .../2026-07-31-shelf-c-attribute-shop.md | 22 +++++++++---------- ...026-07-31-shelf-c-attribute-shop-design.md | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs_dev/plans/2026-07-31-shelf-c-attribute-shop.md b/docs_dev/plans/2026-07-31-shelf-c-attribute-shop.md index f723475..e152cca 100644 --- a/docs_dev/plans/2026-07-31-shelf-c-attribute-shop.md +++ b/docs_dev/plans/2026-07-31-shelf-c-attribute-shop.md @@ -61,7 +61,7 @@ Expected: `Switched to a new branch 'feat/shelf-c-attribute-shop'` **Interfaces:** - Consumes: 无(零依赖) -- Produces: `PriceFormula.compute(spec: Dictionary, purchased: int) -> int`;`PriceFormula.curve_from_string(s: String) -> PriceFormula.Curve`;`enum Curve { GEOMETRIC, LINEAR, FLAT }` +- Produces: `PriceFormula.compute(spec: Dictionary, purchased: int) -> int`;`PriceFormula.curve_from_string(s: String) -> PriceFormula.Curve`;`enum PriceCurve { GEOMETRIC, LINEAR, FLAT }` > 纯函数,**先写断言、看它失败、再实现**。断言经 `execute_editor_script` 执行(项目无测试框架)。 @@ -86,20 +86,20 @@ Create `scripts/domain/price_formula.gd`: class_name PriceFormula extends RefCounted -enum Curve { GEOMETRIC, LINEAR, FLAT } +enum PriceCurve { GEOMETRIC, LINEAR, FLAT } -const _CURVE_BY_NAME: Dictionary[String, Curve] = { - "geometric": Curve.GEOMETRIC, - "linear": Curve.LINEAR, - "flat": Curve.FLAT, +const _CURVE_BY_NAME: Dictionary[String, PriceCurve] = { + "geometric": PriceCurve.GEOMETRIC, + "linear": PriceCurve.LINEAR, + "flat": PriceCurve.FLAT, } ## JSON 的 curve 字符串 → 枚举;未知值 push_error 并回退 GEOMETRIC -static func curve_from_string(s: String) -> Curve: +static func curve_from_string(s: String) -> PriceCurve: if _CURVE_BY_NAME.has(s): return _CURVE_BY_NAME[s] push_error("PriceFormula: 未知 curve「%s」,回退 geometric" % s) - return Curve.GEOMETRIC + return PriceCurve.GEOMETRIC ## 唯一的价格入口 ## spec —— 数据文件里的定价段,读 price_base / price_growth / curve @@ -109,12 +109,12 @@ static func compute(spec: Dictionary, purchased: int) -> int: var base: float = float(spec.get("price_base", 0.0)) var growth: float = float(spec.get("price_growth", 1.0)) var n: int = maxi(purchased, 0) - var curve: Curve = curve_from_string(String(spec.get("curve", "geometric"))) + var curve: PriceCurve = curve_from_string(String(spec.get("curve", "geometric"))) var raw: float = 0.0 match curve: - Curve.LINEAR: + PriceCurve.LINEAR: raw = base + float(n) * growth - Curve.FLAT: + PriceCurve.FLAT: raw = base _: raw = base * pow(growth, float(n)) diff --git a/docs_dev/specs/2026-07-31-shelf-c-attribute-shop-design.md b/docs_dev/specs/2026-07-31-shelf-c-attribute-shop-design.md index 0943bf1..05a4d11 100644 --- a/docs_dev/specs/2026-07-31-shelf-c-attribute-shop-design.md +++ b/docs_dev/specs/2026-07-31-shelf-c-attribute-shop-design.md @@ -93,14 +93,14 @@ class_name PriceFormula extends RefCounted -enum Curve { GEOMETRIC, LINEAR, FLAT } +enum PriceCurve { GEOMETRIC, LINEAR, FLAT } ## 唯一入口。spec 来自数据文件;本模块**不认识**「属性/法杖/装备」,只认识 {price_base, price_growth, curve} ## purchased —— 已购次数(0 = 首次购买) static func compute(spec: Dictionary, purchased: int) -> int ## curve 字符串 → 枚举;未知值 push_error 并回退 GEOMETRIC -static func curve_from_string(s: String) -> Curve +static func curve_from_string(s: String) -> PriceCurve ``` | curve | 公式 |