2021-01-03 23:19:21 +00:00
|
|
|
package uix
|
|
|
|
|
2021-08-09 03:10:42 +00:00
|
|
|
import "git.kirsle.net/go/render"
|
|
|
|
|
2021-01-03 23:19:21 +00:00
|
|
|
// Functions relating to the Doodad JavaScript API for Canvas Actors.
|
|
|
|
|
|
|
|
// MakeSelfAPI generates the `Self` object for the scripting API in
|
|
|
|
// reference to a live Canvas actor in the level.
|
|
|
|
func (w *Canvas) MakeSelfAPI(actor *Actor) map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
|
|
|
"Filename": actor.Doodad().Filename,
|
|
|
|
"Title": actor.Doodad().Title,
|
|
|
|
|
|
|
|
// functions
|
2021-08-09 03:10:42 +00:00
|
|
|
"ID": actor.ID,
|
|
|
|
"GetTag": actor.Doodad().Tag,
|
|
|
|
"Position": actor.Position,
|
|
|
|
"MoveTo": func(p render.Point) {
|
|
|
|
actor.MoveTo(p)
|
|
|
|
actor.SetGrounded(false)
|
|
|
|
},
|
2021-01-03 23:19:21 +00:00
|
|
|
"SetHitbox": actor.SetHitbox,
|
|
|
|
"SetVelocity": actor.SetVelocity,
|
|
|
|
"SetMobile": actor.SetMobile,
|
|
|
|
"SetGravity": actor.SetGravity,
|
|
|
|
"AddAnimation": actor.AddAnimation,
|
|
|
|
"IsAnimating": actor.IsAnimating,
|
|
|
|
"PlayAnimation": actor.PlayAnimation,
|
|
|
|
"StopAnimation": actor.StopAnimation,
|
|
|
|
"ShowLayer": actor.ShowLayer,
|
|
|
|
"ShowLayerNamed": actor.ShowLayerNamed,
|
|
|
|
"Destroy": actor.Destroy,
|
|
|
|
"GetLinks": func() []map[string]interface{} {
|
|
|
|
var result = []map[string]interface{}{}
|
|
|
|
for _, linked := range w.GetLinkedActors(actor) {
|
|
|
|
result = append(result, w.MakeSelfAPI(linked))
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|