Documentation ¶
Index ¶
- func DrawCrosshair(e render.Engine, child ui.Widget, color render.Color, lengthPct int)
- type Actor
- func (a *Actor) AddAnimation(name string, interval int64, layers []interface{}) error
- func (a *Actor) AddItem(itemName string, quantity int)
- func (a *Actor) ClearInventory()
- func (a *Actor) Destroy()
- func (a *Actor) Doodad() *doodads.Doodad
- func (a *Actor) Freeze()
- func (a *Actor) GetBoundingRect() render.Rect
- func (a *Actor) GetOption(name string) *level.Option
- func (a *Actor) Grounded() bool
- func (a *Actor) HasGravity() bool
- func (a *Actor) HasInventory() bool
- func (a *Actor) HasItem(itemName string) int
- func (a *Actor) Hide()
- func (a *Actor) Hitbox() render.Rect
- func (a *Actor) ID() string
- func (a *Actor) Inventory() map[string]int
- func (a *Actor) Invulnerable() bool
- func (a *Actor) IsAnimating() bool
- func (a *Actor) IsFrozen() bool
- func (a *Actor) IsMobile() bool
- func (a *Actor) IsOnScreen() bool
- func (a *Actor) IsPlayer() bool
- func (a *Actor) IsWet() bool
- func (a *Actor) LayerCount() int
- func (a *Actor) ListItems() []string
- func (a *Actor) MoveBy(p render.Point)
- func (a *Actor) MoveTo(p render.Point)
- func (a *Actor) Options() []string
- func (a *Actor) PlayAnimation(name string, callback goja.Value) error
- func (a *Actor) Position() render.Point
- func (a *Actor) RemoveItem(itemName string, quantity int) bool
- func (a *Actor) SetGravity(v bool)
- func (a *Actor) SetGrounded(v bool)
- func (a *Actor) SetHitbox(x, y, w, h int)
- func (a *Actor) SetInventory(v bool)
- func (a *Actor) SetInvulnerable(v bool)
- func (a *Actor) SetMobile(v bool)
- func (a *Actor) SetNoclip(v bool)
- func (a *Actor) SetUsing(v bool)
- func (a *Actor) SetVelocity(v physics.Vector)
- func (a *Actor) SetWet(v bool)
- func (a *Actor) Show()
- func (a *Actor) ShowLayer(index int) error
- func (a *Actor) ShowLayerNamed(name string) error
- func (a *Actor) Size() render.Rect
- func (a *Actor) StopAnimation()
- func (a *Actor) TickAnimation(an *Animation) bool
- func (a *Actor) Unfreeze()
- func (a *Actor) Velocity() physics.Vector
- type Animation
- type Canvas
- func (w *Canvas) Actors() []*Actor
- func (w *Canvas) AddActor(actor *Actor) error
- func (w *Canvas) AddStroke(stroke *drawtool.Stroke)
- func (w *Canvas) Chunker() *level.Chunker
- func (w *Canvas) ClearActors()
- func (w *Canvas) Compute(e render.Engine)
- func (w *Canvas) Destroy()
- func (w *Canvas) DrawStrokes(e render.Engine, strokes []*drawtool.Stroke)
- func (c *Canvas) GetCanvasesByActorName(filename string) []*Canvas
- func (w *Canvas) GetLinkedActors(a *Actor) []*Actor
- func (w *Canvas) GetZoomMultiplier() float64
- func (w *Canvas) InstallActors(actors level.ActorMap) error
- func (w *Canvas) InstallScripts() error
- func (w *Canvas) IsCursorOver() bool
- func (w *Canvas) LinkAdd(a *Actor) error
- func (w *Canvas) Load(p *level.Palette, g *level.Chunker)
- func (w *Canvas) LoadDoodad(d *doodads.Doodad)
- func (w *Canvas) LoadDoodadToLayer(d *doodads.Doodad, index int)
- func (w *Canvas) LoadLevel(level *level.Level)
- func (w *Canvas) LoadUnloadChunks(force ...bool)
- func (w *Canvas) LoadUnloadMetrics() (inside, outside int)
- func (w *Canvas) LoadingViewport() render.Rect
- func (w *Canvas) Loop(ev *event.State) error
- func (w *Canvas) MakeScriptAPI(vm *scripting.VM)
- func (w *Canvas) MakeSelfAPI(actor *Actor) map[string]interface{}
- func (w *Canvas) Modified() bool
- func (w *Canvas) Present(e render.Engine, p render.Point)
- func (w *Canvas) PresentWallpaper(e render.Engine, p render.Point) error
- func (w *Canvas) PrintLinks()
- func (w *Canvas) RedoStroke() bool
- func (w *Canvas) RemoveActor(actor *Actor)
- func (w *Canvas) RemoveStroke(stroke *drawtool.Stroke) bool
- func (w *Canvas) ScrollBy(by render.Point)
- func (w *Canvas) ScrollTo(to render.Point)
- func (w *Canvas) SetModified(v bool)
- func (w *Canvas) SetScriptSupervisor(s *scripting.Supervisor)
- func (w *Canvas) SetSwatch(s *level.Swatch)
- func (w *Canvas) UndoStroke() bool
- func (w *Canvas) Viewport() render.Rect
- func (w *Canvas) ViewportRelative() render.Rect
- func (w *Canvas) WorldIndexAt(screenPixel render.Point) render.Point
- func (w *Canvas) ZoomDivide(value int) int
- func (w *Canvas) ZoomMultiply(value int) int
- func (w *Canvas) ZoomStroke(stroke *drawtool.Stroke) *drawtool.Stroke
- type CollideEvent
- type Crosshair
- type UseEvent
- type Wallpaper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DrawCrosshair ¶
DrawCrosshair renders a crosshair on the screen. It appears while the mouse cursor is over the child widget and draws within the bounds of the child widget.
The lengthPct is an integer ranged 0 to 100 to be a percentage length of the crosshair. A value of zero will not draw anything and just return.
Types ¶
type Actor ¶
type Actor struct { Drawing *doodads.Drawing Actor *level.Actor Canvas *Canvas LevelCanvas *Canvas // the parent Canvas of the level we reside in // contains filtered or unexported fields }
Actor is an object that marries together the three things that make a Doodad instance "tick" while inside a Canvas:
- uix.Actor is a doodads.Drawing so it fulfills doodads.Actor to be a dynamic object during gameplay.
- It has a pointer to the level.Actor indicating its static level data as defined in the map: its spawn coordinate and configuration.
- A uix.Canvas that can present the actor's graphics to the screen.
func (*Actor) AddAnimation ¶
AddAnimation installs a new animation into the scripting engine for this actor.
The layers can be an array of string names or integer indexes.
func (*Actor) AddItem ¶
AddItem adds an item doodad to the actor's inventory. Item name is usually the doodad filename.
func (*Actor) ClearInventory ¶
func (a *Actor) ClearInventory()
ClearInventory removes all items from the actor's inventory.
func (*Actor) Doodad ¶
Doodad offers access to the underlying Doodad object. Shortcut to the `.Drawing.Doodad` property path.
func (*Actor) Freeze ¶
func (a *Actor) Freeze()
Freeze an actor. For the player character, this means arrow key inputs will stop moving the actor.
func (*Actor) GetBoundingRect ¶
GetBoundingRect gets the bounding box of the actor's doodad.
func (*Actor) GetOption ¶
Get an option value from the actor. If the option is not configured, returns the default Doodad option, or nil if not there either.
func (*Actor) HasGravity ¶
HasGravity returns if gravity applies to the actor.
func (*Actor) HasInventory ¶
HasInventory returns if the actor is capable of carrying items.
func (*Actor) HasItem ¶
HasItem checks the actor's inventory for the item and returns the quantity.
A return value of -1 means the item was not found. The value 0 indicates a key item (one with no quantity). Values >= 1 would be consumable items.
func (*Actor) Hitbox ¶
Hitbox returns the actor's elected hitbox. If the JavaScript did not set a hitbox, it defers to the Doodad's metadata hitbox.
func (*Actor) Invulnerable ¶
Invulnerable returns whether the actor is marked as immortal.
func (*Actor) IsAnimating ¶
IsAnimating returns if the current actor is playing an animation.
func (*Actor) IsOnScreen ¶
IsOnScreen checks whether the actor's visual sprite box is on-screen in the level viewport.
func (*Actor) IsPlayer ¶
IsPlayer returns whether the actor is the player character. It's true when the Actor ID is "PLAYER"
func (*Actor) LayerCount ¶
LayerCount returns the number of layers in this actor's drawing.
func (*Actor) PlayAnimation ¶
PlayAnimation starts an animation and then calls a JavaScript function when the last frame has played out. Set a null function to ignore the callback.
func (*Actor) RemoveItem ¶
RemoveItem removes a quantity of an item from the actor's inventory.
Provide a quantity of 0 to remove the item completely. Otherwise provides a number greater than zero and you will subtract this quantity from the item. If the item then is at <= zero, it is removed from inventory.
func (*Actor) SetGravity ¶
SetGravity configures whether the actor is affected by gravity.
func (*Actor) SetGrounded ¶
SetGrounded sets the actor's grounded value. If true, also sets their Y velocity to zero.
func (*Actor) SetInventory ¶
SetInventory configures whether the actor is capable of carrying items.
func (*Actor) SetInvulnerable ¶
SetInvulnerable sets the actor's immortal flag.
func (*Actor) SetMobile ¶
SetMobile configures whether the actor is a mobile character (i.e. is the player or a mobile enemy). Mobile characters can set off certain traps when touched but non-mobile actors don't set each other off if touching.
func (*Actor) SetNoclip ¶
SetNoclip sets the noclip setting for an actor. If true, the actor can clip through level geometry.
func (*Actor) SetUsing ¶
SetUsing enables the "Use Key" flag, mainly for the player character to activate certain doodads in the level.
func (*Actor) SetVelocity ¶
SetVelocity updates the actor's velocity vector.
func (*Actor) ShowLayerNamed ¶
ShowLayerNamed sets the actor's ActiveLayer to the one named.
func (*Actor) StopAnimation ¶
func (a *Actor) StopAnimation()
StopAnimation stops any current animations.
func (*Actor) TickAnimation ¶
TickAnimation advances an animation forward.
This method is called by canvas.Loop() only when the actor is currently `animating` and their current animation's nextFrameAt has been reached by the current time.Now().
Returns true when the animation has finished and false if there is still more frames left to animate.
type Animation ¶
type Animation struct { Name string Interval time.Duration Layers []int // contains filtered or unexported fields }
Animation holds a named animation for a doodad script.
type Canvas ¶
type Canvas struct { ui.Frame Palette *level.Palette // Editable and Scrollable go hand in hand and, if you initialize a // NewCanvas() with editable=true, they are both enabled. Editable bool // Clicking will edit pixels of this canvas. Scrollable bool // Cursor keys will scroll the viewport of this canvas. Zoom int // Zoom level on the canvas. // Set this if your Canvas is a small fixed size (e.g. in doodad dropper), // so that doodads will crop their texture (if chunk size larger than your // Canvas) as to not overflow the canvas bounds. Not needed for Level canvases. CroppedSize bool // Toogle for doodad canvases in the Level Editor to show their buttons. ShowDoodadButtons bool OnDoodadConfig func(*Actor) // Custom label to place in the lower-right corner of the canvas. // Used for e.g. the quantity badge on Inventory items. CornerLabel string // Selected draw tool/mode, default Pencil, for editable canvases. Tool drawtool.Tool BrushSize int // thickness of selected brush // MaskColor will force every pixel to render as this color regardless of // the palette index of that pixel. Otherwise pixels behave the same and // the palette does work as normal. Set to render.Invisible (zero value) // to remove the mask. MaskColor render.Color // Actor ID to follow the camera on automatically, i.e. the main player. FollowActor string // Debug tools // NoLimitScroll suppresses the scroll limit for bounded levels. NoLimitScroll bool // Show custom mouse cursors over this canvas (eg. editor tools) FancyCursors bool // PlayScene can set whether the Levelpack has a valid signature on it, so that // in InstallActors() we can allow a levelpack to load attached doodads on free // mode for their levels. IsSignedLevelPack *levelpack.LevelPack // filled in ONLY IF SIGNED. // When the Canvas wants to delete Actors, but ultimately it is upstream // that controls the actors. Upstream should delete them and then reinstall // the actor list from scratch. OnDeleteActors func([]*Actor) OnDragStart func(*level.Actor) // -- WHEN Canvas.Tool is "Link" -- // When the Canvas wants to link two actors together. Arguments are the IDs // of the two actors. OnLinkActors func(a, b *Actor) // Collision handlers for level geometry. OnLevelCollision func(*Actor, *collision.Collide) // Handler when a doodad script called Actors.SetPlayerCharacter. // The filename.doodad is given. OnSetPlayerCharacter func(filename string) // Handler for when a doodad script calls Level.ResetTimer(). OnResetTimer func() // We inherit the ui.Widget which manages the width and height. Scroll render.Point // Scroll offset for which parts of canvas are visible. // contains filtered or unexported fields }
Canvas is a custom ui.Widget that manages a single drawing.
func NewCanvas ¶
NewCanvas initializes a Canvas widget.
size is the Chunker size (uint8)
If editable is true, Scrollable is also set to true, which means the arrow keys will scroll the canvas viewport which is desirable in Edit Mode.
func (*Canvas) AddActor ¶
AddActor injects additional actors into the canvas, such as a Player doodad.
func (*Canvas) AddStroke ¶
AddStroke installs a new Stroke to be superimposed over drawing data in the canvas.
The stroke is added to the canvas's map by its ID so it can be removed later. The stroke must have a non-zero ID value set or this function will panic. drawtool.NewStroke() creates an initialized Stroke object to use here.
func (*Canvas) ClearActors ¶
func (w *Canvas) ClearActors()
ClearActors removes all the actors from the Canvas.
func (*Canvas) Destroy ¶
func (w *Canvas) Destroy()
Destroy the canvas.
This function satisfies the ui.Widget interface but it also calls Teardown() methods on the level or doodad as well as any level actors, which frees up SDL2 texture memory.
Note: the rest of the data can be garbage collected by Go normally, the textures are able to regenerate themselves again if needed.
func (*Canvas) DrawStrokes ¶
DrawStrokes is the common base function behind presentStrokes and presentActorLinks to actually draw the lines to the canvas.
func (*Canvas) GetCanvasesByActorName ¶
GetCanvasesByActorName searches a (level) canvas's installed actors and returns any of them having this Title or Filename, with filename being more precise.
func (*Canvas) GetLinkedActors ¶
GetLinkedActors returns the live Actor instances (Play Mode) which are linked to the live actor given.
func (*Canvas) GetZoomMultiplier ¶
GetZoomMultiplier parses the .Zoom integer and returns a multiplier.
Examples:
Zoom = 0: neutral (100% scale, 1x) Zoom = 1: 2x zoom Zoom = 2: 4x zoom Zoom = 3: 8x zoom Zoom = -1: 0.5x zoom Zoom = -2: 0.25x zoom
func (*Canvas) InstallActors ¶
InstallActors adds external Actors to the canvas to be superimposed on top of the drawing.
func (*Canvas) InstallScripts ¶
InstallScripts loads all the current actors' scripts into the scripting engine supervisor.
func (*Canvas) IsCursorOver ¶
IsCursorOver returns true if the mouse cursor is physically over top of the canvas's widget space.
func (*Canvas) LoadDoodad ¶
LoadDoodad initializes a Canvas from a Doodad object.
func (*Canvas) LoadDoodadToLayer ¶
LoadDoodadToLayer initializes a Canvas from a Doodad object and picks a layer to load.
func (*Canvas) LoadUnloadChunks ¶
LoadUnloadChunks optimizes memory for (level) canvases by warming up chunk images that fall within the LoadingViewport and freeing chunks that are outside of it.
func (*Canvas) LoadUnloadMetrics ¶
LoadUnloadMetrics returns the canvas's stored metrics from the LoadUnloadChunks function, for the debug overlay.
func (*Canvas) LoadingViewport ¶
LoadingViewport is the viewport of chunks that ought to be preloaded and ready to display soon. It is the Viewport of chunks on screen + a margin of neighboring chunks outside the screen.
For memory optimization, chunks falling inside this viewport have their Go image.Image rendered and cached ready to convert to an SDL2 Texture when they come on screen. Chunks outside of the LoadingViewport can be unloaded (textures and images freed) to keep memory consumption on large levels under control.
func (*Canvas) Loop ¶
Loop is called on the scene's event loop to handle mouse interaction with the canvas, i.e. to edit it.
func (*Canvas) MakeScriptAPI ¶
MakeScriptAPI makes several useful globals available to doodad scripts such as Actors.At()
func (*Canvas) MakeSelfAPI ¶
MakeSelfAPI generates the `Self` object for the scripting API in reference to a live Canvas actor in the level.
func (*Canvas) Modified ¶
Modified returns whether the canvas has been modified since it was last loaded. Methods like Load and LoadFile will set modified to false, and commitStroke sets it to true.
func (*Canvas) PresentWallpaper ¶
PresentWallpaper draws the wallpaper. Point p is the one given to Canvas.Present(), i.e., the position of the top-left corner of the Canvas widget relative to the application window.
func (*Canvas) PrintLinks ¶
func (w *Canvas) PrintLinks()
PrintLinks is a debug function that describes all actor links to console.
func (*Canvas) RedoStroke ¶
RedoStroke rolls the level's UndoHistory forwards again and replays the recently undone changes.
func (*Canvas) RemoveActor ¶
RemoveActor removes the actor from the canvas.
func (*Canvas) RemoveStroke ¶
RemoveStroke uninstalls a Stroke from the canvas using its ID.
Returns true if the stroke existed to begin with, false if not.
func (*Canvas) SetModified ¶
SetModified sets the modified bit on the canvas.
func (*Canvas) SetScriptSupervisor ¶
func (w *Canvas) SetScriptSupervisor(s *scripting.Supervisor)
SetScriptSupervisor assigns the Canvas scripting supervisor to enable interaction with actor scripts.
func (*Canvas) UndoStroke ¶
UndoStroke rolls back the level's UndoHistory and deletes the pixels last added to the level. Returns false and emits a warning to the log if the canvas has no level loaded properly.
func (*Canvas) Viewport ¶
Viewport returns a rect containing the viewable drawing coordinates in this canvas. The X,Y values are the scroll offset (top left) and the W,H values are the scroll offset plus the width/height of the Canvas widget.
The Viewport rect are the Absolute World Coordinates of the drawing that are visible inside the Canvas. The X,Y is the top left World Coordinate and the W,H are the bottom right World Coordinate, making this rect an absolute slice of the world. For a normal rect with a relative width and height, use ViewportRelative().
The rect X,Y are the negative Scroll Value. The rect W,H are the Canvas widget size minus the Scroll Value.
func (*Canvas) ViewportRelative ¶
ViewportRelative returns a relative viewport where the Width and Height values are zero-relative: so you can use it with point.Inside(viewport) to see if a World Index point should be visible on screen.
The rect X,Y are the negative Scroll Value The rect W,H are the Canvas widget size.
func (*Canvas) WorldIndexAt ¶
WorldIndexAt returns the World Index that corresponds to a Screen Pixel on the screen. If the screen pixel is the mouse coordinate (relative to the application window) this will return the World Index of the pixel below the mouse cursor.
func (*Canvas) ZoomDivide ¶
ZoomDivide divides an integer by the zoom inversely.
The algo is: int(float64(value) * divider)
Where the divider is a map of:
w.Zoom => divider -2 => 4 -1 => 2 0 => 1 1 => 0.675* 2 => 0.5 3 => 0.404*
The 0.675 and 0.404 numbers I don't understand but were discovered the hard way when the 1.5x and 2.5x zoom levels were coming out jank. Expected to be 0.25 and 0.75.
func (*Canvas) ZoomMultiply ¶
ZoomMultiply multiplies a width or height value by the Zoom Multiplier and returns the modified integer.
Usage is like:
// when building a render.Rect destination box. dest.W *= ZoomMultiply(dest.W) dest.H *= ZoomMultiply(dest.H)
type CollideEvent ¶
type CollideEvent struct { Actor *Actor Overlap render.Rect InHitbox bool // If the two elected hitboxes are overlapping Settled bool // Movement phase finished, actor script can fire actions }
CollideEvent holds data sent to an actor's Collide handler.
type UseEvent ¶
type UseEvent struct {
Actor *Actor
}
UseEvent holds data sent to an actor's OnUse handler.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package magicform helps create simple form layouts with go/ui.
|
Package magicform helps create simple form layouts with go/ui. |