diff --git a/engine/game.go b/engine/game.go index 71cada6..548d048 100644 --- a/engine/game.go +++ b/engine/game.go @@ -3,6 +3,7 @@ package engine import ( "encoding/gob" "io/fs" + "log" "sync" "github.com/hajimehoshi/ebiten/v2" @@ -59,6 +60,9 @@ func (g *Game) RegisterComponent(c interface{}) { return } g.dbmu.Lock() + if _, exists := g.db[id]; exists { + log.Printf("duplicate id %q", id) + } g.db[id] = c g.dbmu.Unlock() } diff --git a/game/aw.go b/game/aw.go index dba5d33..7be4b0f 100644 --- a/game/aw.go +++ b/game/aw.go @@ -10,11 +10,24 @@ import ( "github.com/hajimehoshi/ebiten/v2/inpututil" ) +var ( + _ engine.Identifier = &Awakeman{} + _ engine.Drawer = &Awakeman{} // provided by Sprite + _ engine.DrawOrderer = &Awakeman{} // provided by Sprite + _ engine.Disabler = &Awakeman{} + _ engine.Hider = &Awakeman{} // provided by Sprite + _ engine.Prepper = &Awakeman{} + _ engine.Scanner = &Awakeman{} + _ engine.Updater = &Awakeman{} +) + func init() { gob.Register(&Awakeman{}) } type Awakeman struct { + engine.ID + engine.Disabled engine.Sprite CameraID string @@ -32,6 +45,10 @@ type Awakeman struct { } func (aw *Awakeman) Update() error { + if aw.Disabled { + return nil + } + // TODO: better cheat for noclip if inpututil.IsKeyJustPressed(ebiten.KeyN) { aw.noclip = !aw.noclip diff --git a/main.go b/main.go index 647112b..4c99869 100644 --- a/main.go +++ b/main.go @@ -94,6 +94,45 @@ func repl(g *engine.Game) { g.Prepare() g.Enable() g.Show() + case "tree": + var c interface{} = g + if len(tok) == 2 { + // subtree + id := tok[1] + c = g.Component(id) + if c == nil { + log.Printf("Component %q not found", id) + break + } + } + type item struct { + c interface{} + depth int + } + stack := []item{{c, 0}} + for len(stack) > 0 { + tail := len(stack) - 1 + x := stack[tail] + stack = stack[:tail] + c := x.c + + indent := "" + if x.depth > 0 { + indent = strings.Repeat(" ", x.depth-1) + "↳ " + } + i, ok := c.(engine.Identifier) + if ok { + log.Printf("%s%T %s", indent, c, i.Ident()) + } else { + log.Printf("%s%T", indent, c) + } + + if s, ok := c.(engine.Scanner); ok { + for _, y := range s.Scan() { + stack = append(stack, item{y, x.depth + 1}) + } + } + } } } if err := sc.Err(); err != nil {