Implemented scene events and callback handlers for those events. Manager defaults also added.

This commit is contained in:
2023-08-23 01:24:43 -04:00
parent f2b3f371c4
commit 5da470937e
6 changed files with 179 additions and 59 deletions

View File

@@ -1,6 +1,7 @@
package splashmenu
import (
"cosmos/diego/groovy"
"image/color"
"log"
@@ -34,14 +35,19 @@ func init() {
type Splash struct {
bgcolor color.RGBA
completed bool
increment int
events map[groovy.SceneEvent]func()
}
// GetSceneEvents implements groovy.Scene.
func (*Splash) GetSceneEvents() []groovy.SceneEvent {
return nil
}
func NewSplash() Splash {
return Splash{
bgcolor: color.RGBA{0xFF, 0xFF, 0xFF, 0xFF},
completed: false,
bgcolor: color.RGBA{0xFF, 0xFF, 0xFF, 0xFF},
events: make(map[groovy.SceneEvent]func()),
}
}
@@ -58,12 +64,12 @@ func (s *Splash) Update() error {
s.bgcolor.B = (s.bgcolor.B - 2) % 0xFF
if s.bgcolor.R == 0x00 {
s.completed = true
s.events[groovy.COMPLETED]()
}
return nil
}
func (s *Splash) Completed() bool {
return s.completed
func (s Splash) SetEventHandler(event groovy.SceneEvent, f func()) {
s.events[event] = f
}