Noah Petherbridge
7866f618da
A new property is added to the Doodad struct: Hitbox (Rect). The uix.Actor for Play Mode will defer to the Doodad.Hitbox until the JavaScript has manually set its own via Self.SetHitbox(). So in effect, scripts no longer need to worry about their hitbox! The one assigned to the Doodad will be the default. Scripts can check if their hitbox is zero before setting a default: if (Self.Hitbox().IsZero()) { var size = Self.Size() // get doodad canvas size Self.SetHitbox(0, 0, size, size) // the full square } The built-in generic doodad scripts have made this change, so that your simple doodad can have a custom hitbox defined easily using in-game tools. Other changes: * New script: Generic Collectible Item. Selecting it will add a "quantity" tag to your doodad, to easily configure the script. * JavaScript API: "Self.Hitbox()" returns your doodad's current hitbox. You can check "Self.Hitbox.IsZero()" to check if it's empty.
55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
package uix
|
|
|
|
import "git.kirsle.net/go/render"
|
|
|
|
// 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
|
|
"ID": actor.ID,
|
|
"Size": func() render.Rect {
|
|
var size = actor.Doodad().ChunkSize()
|
|
return render.NewRect(size, size)
|
|
},
|
|
"GetTag": actor.Doodad().Tag,
|
|
"Position": actor.Position,
|
|
"MoveTo": func(p render.Point) {
|
|
actor.MoveTo(p)
|
|
actor.SetGrounded(false)
|
|
},
|
|
"SetHitbox": actor.SetHitbox,
|
|
"Hitbox": actor.Hitbox,
|
|
"SetVelocity": actor.SetVelocity,
|
|
"SetMobile": actor.SetMobile,
|
|
"SetInventory": actor.SetInventory,
|
|
"HasInventory": actor.HasInventory,
|
|
"SetGravity": actor.SetGravity,
|
|
"AddAnimation": actor.AddAnimation,
|
|
"IsAnimating": actor.IsAnimating,
|
|
"IsPlayer": actor.IsPlayer,
|
|
"PlayAnimation": actor.PlayAnimation,
|
|
"StopAnimation": actor.StopAnimation,
|
|
"ShowLayer": actor.ShowLayer,
|
|
"ShowLayerNamed": actor.ShowLayerNamed,
|
|
"Inventory": actor.Inventory,
|
|
"AddItem": actor.AddItem,
|
|
"RemoveItem": actor.RemoveItem,
|
|
"HasItem": actor.HasItem,
|
|
"ClearInventory": actor.ClearInventory,
|
|
"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
|
|
},
|
|
}
|
|
}
|