Noah Petherbridge
9a51ac39f9
* New doodad: Invisible Warp Door * All warp doors require the player to be grounded (if affected by gravity) to open them. No jumping or falling thru and opening a warp door mid-air! * Title Screen now randomly selects from a couple of levels. * Title Screen: if it fails to load a level it sets up a basic blank level with a wallpaper instead. * New developer shell command: titlescreen <level> Opens the MainScene with a custom user level as the background. * Add Auto-save to the Editor to save your drawing every 5 minutes * Add a MenuBar to the Play Scene for easier navigation to other features of the game. * Doodad JS API: time.Since() now available.
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package scripting
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/log"
|
|
"git.kirsle.net/apps/doodle/pkg/physics"
|
|
"git.kirsle.net/apps/doodle/pkg/shmem"
|
|
"git.kirsle.net/apps/doodle/pkg/sound"
|
|
"git.kirsle.net/go/render"
|
|
)
|
|
|
|
// JSProxy offers a function API interface to expose to Doodad javascripts.
|
|
// These methods safely give the JS access to important attributes and functions
|
|
// without exposing unintended API surface area in the process.
|
|
type JSProxy map[string]interface{}
|
|
|
|
// NewJSProxy initializes the API structure for JavaScript binding.
|
|
func NewJSProxy(vm *VM) JSProxy {
|
|
return JSProxy{
|
|
// Console logging.
|
|
"console": map[string]interface{}{
|
|
"log": log.Info,
|
|
"debug": log.Debug,
|
|
"warn": log.Warn,
|
|
"error": log.Error,
|
|
},
|
|
|
|
// Audio API.
|
|
"Sound": map[string]interface{}{
|
|
"Play": sound.PlaySound,
|
|
},
|
|
|
|
// Type constructors.
|
|
"RGBA": render.RGBA,
|
|
"Point": render.NewPoint,
|
|
"Vector": physics.NewVector,
|
|
|
|
// Useful types and functions.
|
|
"Flash": shmem.Flash,
|
|
"GetTick": func() uint64 {
|
|
return shmem.Tick
|
|
},
|
|
"time": map[string]interface{}{
|
|
"Now": time.Now,
|
|
"Since": time.Since,
|
|
"Add": func(t time.Time, ms int64) time.Time {
|
|
return t.Add(time.Duration(ms) * time.Millisecond)
|
|
},
|
|
"Hour": time.Hour,
|
|
"Minute": time.Minute,
|
|
"Second": time.Second,
|
|
"Millisecond": time.Millisecond,
|
|
"Microsecond": time.Microsecond,
|
|
},
|
|
|
|
// Bindings into the VM.
|
|
"Events": vm.Events,
|
|
"setTimeout": vm.SetTimeout,
|
|
"setInterval": vm.SetInterval,
|
|
"clearTimeout": vm.ClearTimer,
|
|
"clearInterval": vm.ClearTimer,
|
|
|
|
// Self for an actor to inspect themselves.
|
|
"Self": vm.Self,
|
|
}
|
|
}
|