From 6f3c6c88c02b6a9fd8252f622514adf3478e9ffd Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Sat, 28 Aug 2021 17:50:54 +1000 Subject: [PATCH] no more draworderer --- engine/billboard.go | 1 - engine/camera.go | 5 ++++- engine/debug.go | 1 - engine/fill.go | 1 - engine/interface.go | 7 ------- engine/scene.go | 6 +++--- engine/sprite.go | 1 - engine/tiles.go | 1 - engine/walls.go | 1 - game/aw.go | 3 +-- 10 files changed, 8 insertions(+), 19 deletions(-) diff --git a/engine/billboard.go b/engine/billboard.go index 709a623..abc9249 100644 --- a/engine/billboard.go +++ b/engine/billboard.go @@ -11,7 +11,6 @@ import ( var _ interface { Identifier Drawer - DrawOrderer ParallaxScaler Scanner } = &Billboard{} diff --git a/engine/camera.go b/engine/camera.go index 8f525a0..172799c 100644 --- a/engine/camera.go +++ b/engine/camera.go @@ -35,7 +35,7 @@ type Camera struct { game *Game } -// Draw applies transformations to opts, then calls c.Scene.Draw with it. +// Draw applies transformations to opts, then draws the contents of c.Scene. func (c *Camera) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) { if c.Scene.IsHidden() { return @@ -104,6 +104,9 @@ func (c *Camera) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) { } } +// DrawOrder passes the call to c.Scene. +func (c *Camera) DrawOrder() float64 { return c.Scene.DrawOrder() } + // Update passes the call to c.Scene. func (c *Camera) Update() error { return c.Scene.Update() } diff --git a/engine/debug.go b/engine/debug.go index 1f8730b..864579d 100644 --- a/engine/debug.go +++ b/engine/debug.go @@ -12,7 +12,6 @@ import ( var _ interface { Drawer - DrawOrderer Hider } = &PerfDisplay{} diff --git a/engine/fill.go b/engine/fill.go index d2fc497..1b42ca5 100644 --- a/engine/fill.go +++ b/engine/fill.go @@ -10,7 +10,6 @@ import ( // Ensure Fill satisfies Drawer. var _ interface { Drawer - DrawOrderer Hider Identifier } = &Fill{} diff --git a/engine/interface.go b/engine/interface.go index c42c6d4..cd460c7 100644 --- a/engine/interface.go +++ b/engine/interface.go @@ -17,7 +17,6 @@ var ( ColliderType = reflect.TypeOf((*Collider)(nil)).Elem() DisablerType = reflect.TypeOf((*Disabler)(nil)).Elem() DrawerType = reflect.TypeOf((*Drawer)(nil)).Elem() - DrawOrdererType = reflect.TypeOf((*DrawOrderer)(nil)).Elem() DrawUpdaterType = reflect.TypeOf((*DrawUpdater)(nil)).Elem() HiderType = reflect.TypeOf((*Hider)(nil)).Elem() IdentifierType = reflect.TypeOf((*Identifier)(nil)).Elem() @@ -36,7 +35,6 @@ var ( ColliderType, DisablerType, DrawerType, - DrawOrdererType, DrawUpdaterType, HiderType, IdentifierType, @@ -80,10 +78,6 @@ type Disabler interface { // (so that hiding the parent can hide the children, etc). type Drawer interface { Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) -} - -// DrawOrderer components can provide a number for determining draw order. -type DrawOrderer interface { DrawOrder() float64 } @@ -148,7 +142,6 @@ type Scener interface { Bounder Disabler Drawer - DrawOrderer Hider Identifier Prepper diff --git a/engine/scene.go b/engine/scene.go index 4ec90df..7208490 100644 --- a/engine/scene.go +++ b/engine/scene.go @@ -49,8 +49,8 @@ func (s *Scene) Prepare(game *Game) error { // (among layers without a Z, or those with equal Z). func (s *Scene) sortByDrawOrder() { sort.SliceStable(s.Components, func(i, j int) bool { - a, aok := s.Components[i].(DrawOrderer) - b, bok := s.Components[j].(DrawOrderer) + a, aok := s.Components[i].(Drawer) + b, bok := s.Components[j].(Drawer) if aok && bok { return a.DrawOrder() < b.DrawOrder() } @@ -81,7 +81,7 @@ func (s *Scene) Update() error { // Check if the updates put the components out of order; if so, sort cz := -math.MaxFloat64 // fun fact: this is min float64 for _, c := range s.Components { - z, ok := c.(DrawOrderer) + z, ok := c.(Drawer) if !ok { continue } diff --git a/engine/sprite.go b/engine/sprite.go index 2fca087..ea8695c 100644 --- a/engine/sprite.go +++ b/engine/sprite.go @@ -11,7 +11,6 @@ import ( var _ interface { Identifier Drawer - DrawOrderer Scanner Updater } = &Sprite{} diff --git a/engine/tiles.go b/engine/tiles.go index 456a703..716fb23 100644 --- a/engine/tiles.go +++ b/engine/tiles.go @@ -12,7 +12,6 @@ var _ interface { Identifier Collider Drawer - DrawOrderer Hider Scanner Updater diff --git a/engine/walls.go b/engine/walls.go index b9f6293..e350caa 100644 --- a/engine/walls.go +++ b/engine/walls.go @@ -15,7 +15,6 @@ var ( _ interface { Drawer - DrawOrderer Disabler Hider Prepper diff --git a/game/aw.go b/game/aw.go index b3a40a0..ee68d2d 100644 --- a/game/aw.go +++ b/game/aw.go @@ -12,8 +12,7 @@ import ( var _ interface { engine.Identifier - engine.Drawer // provided by Sprite - engine.DrawOrderer // provided by Sprite + engine.Drawer // provided by Sprite engine.Disabler engine.Hider // provided by Sprite engine.Prepper