no more draworderer

This commit is contained in:
Josh Deprez 2021-08-28 17:50:54 +10:00
parent 0e64c4a994
commit 6f3c6c88c0
10 changed files with 8 additions and 19 deletions

View file

@ -11,7 +11,6 @@ import (
var _ interface { var _ interface {
Identifier Identifier
Drawer Drawer
DrawOrderer
ParallaxScaler ParallaxScaler
Scanner Scanner
} = &Billboard{} } = &Billboard{}

View file

@ -35,7 +35,7 @@ type Camera struct {
game *Game 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) { func (c *Camera) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
if c.Scene.IsHidden() { if c.Scene.IsHidden() {
return 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. // Update passes the call to c.Scene.
func (c *Camera) Update() error { return c.Scene.Update() } func (c *Camera) Update() error { return c.Scene.Update() }

View file

@ -12,7 +12,6 @@ import (
var _ interface { var _ interface {
Drawer Drawer
DrawOrderer
Hider Hider
} = &PerfDisplay{} } = &PerfDisplay{}

View file

@ -10,7 +10,6 @@ import (
// Ensure Fill satisfies Drawer. // Ensure Fill satisfies Drawer.
var _ interface { var _ interface {
Drawer Drawer
DrawOrderer
Hider Hider
Identifier Identifier
} = &Fill{} } = &Fill{}

View file

@ -17,7 +17,6 @@ var (
ColliderType = reflect.TypeOf((*Collider)(nil)).Elem() ColliderType = reflect.TypeOf((*Collider)(nil)).Elem()
DisablerType = reflect.TypeOf((*Disabler)(nil)).Elem() DisablerType = reflect.TypeOf((*Disabler)(nil)).Elem()
DrawerType = reflect.TypeOf((*Drawer)(nil)).Elem() DrawerType = reflect.TypeOf((*Drawer)(nil)).Elem()
DrawOrdererType = reflect.TypeOf((*DrawOrderer)(nil)).Elem()
DrawUpdaterType = reflect.TypeOf((*DrawUpdater)(nil)).Elem() DrawUpdaterType = reflect.TypeOf((*DrawUpdater)(nil)).Elem()
HiderType = reflect.TypeOf((*Hider)(nil)).Elem() HiderType = reflect.TypeOf((*Hider)(nil)).Elem()
IdentifierType = reflect.TypeOf((*Identifier)(nil)).Elem() IdentifierType = reflect.TypeOf((*Identifier)(nil)).Elem()
@ -36,7 +35,6 @@ var (
ColliderType, ColliderType,
DisablerType, DisablerType,
DrawerType, DrawerType,
DrawOrdererType,
DrawUpdaterType, DrawUpdaterType,
HiderType, HiderType,
IdentifierType, IdentifierType,
@ -80,10 +78,6 @@ type Disabler interface {
// (so that hiding the parent can hide the children, etc). // (so that hiding the parent can hide the children, etc).
type Drawer interface { type Drawer interface {
Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions)
}
// DrawOrderer components can provide a number for determining draw order.
type DrawOrderer interface {
DrawOrder() float64 DrawOrder() float64
} }
@ -148,7 +142,6 @@ type Scener interface {
Bounder Bounder
Disabler Disabler
Drawer Drawer
DrawOrderer
Hider Hider
Identifier Identifier
Prepper Prepper

View file

@ -49,8 +49,8 @@ func (s *Scene) Prepare(game *Game) error {
// (among layers without a Z, or those with equal Z). // (among layers without a Z, or those with equal Z).
func (s *Scene) sortByDrawOrder() { func (s *Scene) sortByDrawOrder() {
sort.SliceStable(s.Components, func(i, j int) bool { sort.SliceStable(s.Components, func(i, j int) bool {
a, aok := s.Components[i].(DrawOrderer) a, aok := s.Components[i].(Drawer)
b, bok := s.Components[j].(DrawOrderer) b, bok := s.Components[j].(Drawer)
if aok && bok { if aok && bok {
return a.DrawOrder() < b.DrawOrder() 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 // Check if the updates put the components out of order; if so, sort
cz := -math.MaxFloat64 // fun fact: this is min float64 cz := -math.MaxFloat64 // fun fact: this is min float64
for _, c := range s.Components { for _, c := range s.Components {
z, ok := c.(DrawOrderer) z, ok := c.(Drawer)
if !ok { if !ok {
continue continue
} }

View file

@ -11,7 +11,6 @@ import (
var _ interface { var _ interface {
Identifier Identifier
Drawer Drawer
DrawOrderer
Scanner Scanner
Updater Updater
} = &Sprite{} } = &Sprite{}

View file

@ -12,7 +12,6 @@ var _ interface {
Identifier Identifier
Collider Collider
Drawer Drawer
DrawOrderer
Hider Hider
Scanner Scanner
Updater Updater

View file

@ -15,7 +15,6 @@ var (
_ interface { _ interface {
Drawer Drawer
DrawOrderer
Disabler Disabler
Hider Hider
Prepper Prepper

View file

@ -13,7 +13,6 @@ import (
var _ interface { var _ interface {
engine.Identifier engine.Identifier
engine.Drawer // provided by Sprite engine.Drawer // provided by Sprite
engine.DrawOrderer // provided by Sprite
engine.Disabler engine.Disabler
engine.Hider // provided by Sprite engine.Hider // provided by Sprite
engine.Prepper engine.Prepper