2019-07-02 22:24:46 +00:00
|
|
|
package scripting
|
|
|
|
|
2021-08-16 03:17:53 +00:00
|
|
|
import "git.kirsle.net/go/render"
|
|
|
|
|
2019-07-02 22:24:46 +00:00
|
|
|
/*
|
|
|
|
RegisterEventHooks attaches the supervisor level event hooks into a JS VM.
|
|
|
|
|
|
|
|
Names registered:
|
|
|
|
|
|
|
|
- EndLevel(): for a doodad to exit the level. Panics if the OnLevelExit
|
|
|
|
handler isn't defined.
|
|
|
|
*/
|
|
|
|
func RegisterEventHooks(s *Supervisor, vm *VM) {
|
|
|
|
vm.Set("EndLevel", func() {
|
2021-08-09 04:54:37 +00:00
|
|
|
if s.onLevelFail == nil {
|
|
|
|
panic("JS FailLevel(): No OnLevelFail handler attached to script supervisor")
|
2019-07-02 22:24:46 +00:00
|
|
|
}
|
|
|
|
s.onLevelExit()
|
|
|
|
})
|
2021-08-09 04:54:37 +00:00
|
|
|
vm.Set("FailLevel", func(message string) {
|
|
|
|
if s.onLevelFail == nil {
|
|
|
|
panic("JS FailLevel(): No OnLevelFail handler attached to script supervisor")
|
|
|
|
}
|
|
|
|
s.onLevelFail(message)
|
|
|
|
})
|
2021-08-16 03:17:53 +00:00
|
|
|
vm.Set("SetCheckpoint", func(p render.Point) {
|
|
|
|
if s.onSetCheckpoint == nil {
|
|
|
|
panic("JS SetCheckpoint(): No OnSetCheckpoint handler attached to script supervisor")
|
|
|
|
}
|
|
|
|
s.onSetCheckpoint(p)
|
|
|
|
})
|
2019-07-02 22:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnLevelExit registers an event hook for when a Level Exit doodad is reached.
|
|
|
|
func (s *Supervisor) OnLevelExit(handler func()) {
|
|
|
|
s.onLevelExit = handler
|
|
|
|
}
|
2021-08-09 04:54:37 +00:00
|
|
|
|
|
|
|
// OnLevelFail registers an event hook for level failures (doodads killing the player).
|
|
|
|
func (s *Supervisor) OnLevelFail(handler func(string)) {
|
|
|
|
s.onLevelFail = handler
|
|
|
|
}
|
2021-08-16 03:17:53 +00:00
|
|
|
|
|
|
|
// OnSetCheckpoint registers an event hook for setting player checkpoints.
|
|
|
|
func (s *Supervisor) OnSetCheckpoint(handler func(render.Point)) {
|
|
|
|
s.onSetCheckpoint = handler
|
|
|
|
}
|