Files
aego/script/bind/curve.go
T
sanspie 0fbf22a090 Stage 9.4a: curves, tween, timers
core/curve with presets, keys, wraps; KindCurve in schema, scenes, prefabs and the inspector curve editor.
modules/tween: tweens and timers in per-world pools, game and unscaled domains, script field targets via contracts/scriptfields.
Host handle types (abi.Handle, bind.Handle, manifest v5), yield on awaitable handles via contracts/scriptwait.
Script modules aego/curve, aego/tween, aego/timer; platformer enemy uses a cooldown and a fade-out tween.
Docs: tween.md, curves.md, language reference; golden for the curve editor.
2026-10-18 21:32:39 +03:00

40 lines
807 B
Go

package bind
import (
"aego/core/curve"
"aego/script/abi"
"aego/script/vm"
)
type CurveSource interface {
CurveOf(v vm.Value) (*curve.Curve, error)
}
type Curve struct {
v vm.Value
m *vm.Machine
}
var errNilCurve = &vm.Fault{Code: vm.CodeNil, Message: "curve reference is nil or its owner is gone"}
func (c Curve) IsZero() bool {
return c.v.IsZero()
}
func (c Curve) Resolve() (*curve.Curve, error) {
if c.v.IsZero() || c.m == nil {
return nil, errNilCurve
}
src, ok := c.m.Comps.(CurveSource)
if !ok {
return nil, errNilCurve
}
return src.CurveOf(c.v)
}
func curveCodec[T any](c *codec[T]) {
c.ref = abi.T(abi.Curve)
c.get = func(m *vm.Machine, w []vm.Value) T { return cast[T](Curve{v: w[0], m: m}) }
c.put = func(_ *vm.Machine, w []vm.Value, v T) { w[0] = cast[Curve](v).v }
}