docs: 订正 enum Curve → PriceCurve(与 Godot 内置 Curve 资源类冲突)

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 <noreply@anthropic.com>
This commit is contained in:
2026-08-03 10:56:57 +08:00
co-authored by Claude Opus 5
parent c6e89a0787
commit 359da9f24f
2 changed files with 13 additions and 13 deletions
@@ -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))
@@ -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 | 公式 |