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 | 公式 |