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.
70 lines
1.1 KiB
Go
70 lines
1.1 KiB
Go
package bind
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"aego/core/clock"
|
|
"aego/core/log"
|
|
"aego/core/rng"
|
|
"aego/engine"
|
|
"aego/platform/input"
|
|
"aego/scene"
|
|
"aego/script/vm"
|
|
)
|
|
|
|
var errNoCtx = errors.New("host function called without a binding context")
|
|
|
|
type Ctx struct {
|
|
World *engine.World
|
|
Scene *scene.Scene
|
|
Input *input.State
|
|
Random *rng.Source
|
|
Log *log.ChannelLogger
|
|
Time *clock.Time
|
|
Node scene.NodeHandle
|
|
Recv scene.NodeHandle
|
|
Self vm.InstanceID
|
|
Dt float32
|
|
Fixed float32
|
|
Elapsed float64
|
|
Frame uint64
|
|
err error
|
|
}
|
|
|
|
func (c *Ctx) Fail(msg string) {
|
|
if c.err == nil {
|
|
c.err = errors.New(msg)
|
|
}
|
|
}
|
|
|
|
func (c *Ctx) Failf(format string, args ...any) {
|
|
if c.err == nil {
|
|
c.err = fmt.Errorf(format, args...)
|
|
}
|
|
}
|
|
|
|
func (c *Ctx) FailErr(err error) {
|
|
if c.err == nil && err != nil {
|
|
c.err = err
|
|
}
|
|
}
|
|
|
|
func (c *Ctx) Failed() bool {
|
|
return c.err != nil
|
|
}
|
|
|
|
func (c *Ctx) finish() error {
|
|
err := c.err
|
|
c.err = nil
|
|
return err
|
|
}
|
|
|
|
func ctxOf(m *vm.Machine) (*Ctx, error) {
|
|
c, ok := m.Env.(*Ctx)
|
|
if !ok || c == nil {
|
|
return nil, errNoCtx
|
|
}
|
|
return c, nil
|
|
}
|