doodads

package
v0.0.0-...-1f00af5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2024 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("file not found")
)

Errors.

Functions

func ListBuiltin

func ListBuiltin() ([]string, error)

ListBuiltin returns a listing of all built-in doodads. Exactly like ListDoodads() but doesn't return user home folder doodads.

func ListDoodads

func ListDoodads() ([]string, error)

ListDoodads returns a listing of all available doodads between all locations, including user doodads.

func SortByName

func SortByName(list []*Doodad)

SortByName orders an array of loaded Doodads by their titles.

Types

type Actor

type Actor interface {
	ID() string

	// Position and velocity, not saved to disk.
	Position() render.Point // DEPRECATED
	Velocity() render.Point // DEPRECATED for uix.Actor
	Size() render.Rect
	Grounded() bool
	SetGrounded(bool)

	// Movement commands.
	MoveBy(render.Point) // Add {X,Y} to current Position.
	MoveTo(render.Point) // Set current Position to {X,Y}.
}

Actor is a reusable run-time drawing component used in Doodle. Actors are an active instance of a Doodad which have a position, velocity, etc.

type Doodad

type Doodad struct {
	level.Base
	Filename string             `json:"-"` // used internally, not saved in json
	Hidden   bool               `json:"hidden,omitempty"`
	Palette  *level.Palette     `json:"palette"`
	Size     render.Rect        `json:"size"` // doodad dimensions
	Script   string             `json:"script"`
	Hitbox   render.Rect        `json:"hitbox"`
	Layers   []Layer            `json:"layers"`
	Tags     map[string]string  `json:"data"`    // arbitrary key/value data storage
	Options  map[string]*Option `json:"options"` // runtime options for a doodad

	// Undo history, temporary live data not persisted to the level file.
	UndoHistory *drawtool.History `json:"-"`
}

Doodad is a reusable component for Levels that have scripts and graphics.

func Deserialize

func Deserialize(filename string, bin []byte) (*Doodad, error)

Deserialize loads a doodad from its bytes format.

func FromGzip

func FromGzip(data []byte) (*Doodad, error)

FromGzip deserializes a gzip compressed doodad JSON.

func FromJSON

func FromJSON(filename string, data []byte) (*Doodad, error)

FromJSON loads a doodad from JSON string (gzip supported).

func FromZipfile

func FromZipfile(data []byte) (*Doodad, error)

FromZipfile reads a doodad from zipfile format.

func LoadFile

func LoadFile(filename string) (*Doodad, error)

LoadFile reads a doodad file from disk, checking a few locations.

It checks for embedded bindata, system-level doodads on the filesystem, and then user-owned doodads in their profile folder.

func LoadJSON

func LoadJSON(filename string) (*Doodad, error)

LoadJSON loads a map from JSON file.

func New

func New(dimensions ...int) *Doodad

New creates a new Doodad.

You can give it one or two values for dimensions:

- New(size int) creates a square doodad (classic) - New(width, height int) lets you have a different width x height.

func NewDummy

func NewDummy(size int) *Doodad

NewDummy creates a placeholder dummy doodad with a giant "X" across it.

func (*Doodad) AddLayer

func (d *Doodad) AddLayer(name string, chunker *level.Chunker) Layer

AddLayer adds a new layer to the doodad. Call this rather than appending your own layer so it points the Zipfile and layer number in. The chunker is optional - pass nil and a new blank chunker is created.

func (*Doodad) AsJSON

func (d *Doodad) AsJSON() ([]byte, error)

AsJSON returns it just as JSON without any fancy gzip/zip magic.

func (*Doodad) ChunkSize

func (d *Doodad) ChunkSize() int

ChunkSize returns the chunk size of the Doodad's first layer.

func (*Doodad) ChunkSize8

func (d *Doodad) ChunkSize8() uint8

ChunkSize8 returns the chunk size of the Doodad's first layer as its actual uint8 value.

func (*Doodad) Inflate

func (d *Doodad) Inflate()

Inflate attaches the pixels to their swatches after loading from disk.

func (*Doodad) Loop

func (d *Doodad) Loop() error

Loop may be called each loop to allow the level to maintain its memory usage, e.g., for chunks not requested recently from a zipfile level to free those from RAM.

func (*Doodad) Rect

func (d *Doodad) Rect() render.Rect

Rect returns a rect of the ChunkSize for scaling a Canvas widget.

func (*Doodad) ReloadZipfile

func (d *Doodad) ReloadZipfile(data []byte) error

ReloadZipfile re-reads the level's zipfile after a write.

func (*Doodad) Serialize

func (d *Doodad) Serialize() ([]byte, error)

Serialize encodes a doodad to bytes and returns them, instead of writing to a file.

func (*Doodad) SetOption

func (d *Doodad) SetOption(name, dataType, v string) string

SetOption sets an actor option, safely.

func (*Doodad) Tag

func (d *Doodad) Tag(name string) string

Tag gets a value from the doodad's tags.

func (*Doodad) Teardown

func (d *Doodad) Teardown()

Teardown cleans up texture cache memory when the doodad is no longer needed by the game.

func (*Doodad) ToGzip

func (d *Doodad) ToGzip() ([]byte, error)

ToGzip serializes the doodad as gzip compressed JSON.

func (*Doodad) ToJSON

func (d *Doodad) ToJSON() ([]byte, error)

ToJSON serializes the doodad as JSON (gzip supported).

If balance.CompressLevels=true the doodad will be gzip compressed and the return value is gz bytes and not the raw JSON.

func (*Doodad) ToZipfile

func (d *Doodad) ToZipfile() ([]byte, error)

ToZipfile serializes the doodad into zipfile format.

func (*Doodad) Vacuum

func (m *Doodad) Vacuum() error

Vacuum runs any maintenance or migration tasks for the level at time of save.

It will prune broken links between actors, or migrate internal data structures to optimize storage on disk of its binary data.

func (*Doodad) WriteFile

func (d *Doodad) WriteFile(filename string) error

WriteFile saves a doodad to disk in the user's config directory.

func (*Doodad) WriteJSON

func (d *Doodad) WriteJSON(filename string) error

WriteJSON writes a Doodad to JSON on disk.

type Drawing

type Drawing struct {
	Doodad *Doodad
	// contains filtered or unexported fields
}

Drawing is a Doodad Actor that is based on drawings made inside the game.

func NewDrawing

func NewDrawing(id string, doodad *Doodad) *Drawing

NewDrawing creates a Drawing actor based on a Doodad drawing. If you pass an empty ID string, it will make a random UUIDv4 ID.

func (*Drawing) ID

func (d *Drawing) ID() string

ID to get the Drawing ID.

func (*Drawing) MoveTo

func (d *Drawing) MoveTo(to render.Point)

MoveTo an absolute world value.

NOTE: used only by unit test.

func (*Drawing) Position

func (d *Drawing) Position() render.Point

Position returns the Drawing's position.

func (*Drawing) Size

func (d *Drawing) Size() render.Rect

Size returns the Drawing's size.

type Layer

type Layer struct {
	Name    string         `json:"name"`
	Chunker *level.Chunker `json:"chunks"`
}

Layer holds a layer of drawing data for a Doodad.

type Option

type Option struct {
	Type    string      `json:"type"` // bool, str, int
	Name    string      `json:"name"`
	Default interface{} `json:"default"`
}

Options for runtime, user configurable.

func (*Option) Set

func (o *Option) Set(v string) string

Set an option value. Generally do not call this yourself - use SetOption to safely set an option which will create the map value the first time.

Directories

Path Synopsis
Package dummy implements a dummy doodads.Drawing.
Package dummy implements a dummy doodads.Drawing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL