fxedit

package
v0.0.0-...-94fff03 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 26 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fxedit is the "fx" tool of wpix-editor: it makes a particle effect, an *.fx.json file (package particles), without knowing which components are involved. It plays the effect in the shell's engine, shows the fields that matter as a panel and writes the whole file back in canonical form (fxfile.Encode).

The preview plays the model through the engine's own effect loader and particle system: the tool serves the current text from the shell's overlay filesystem and a change is a hot reload of that file.

Everything but tool.go is plain Go without Ebiten: the presets and built-in sprites, the edits, the visibility rules and the panel are tested without a window. The package never imports debugui; the shell draws the panel. See doc/design/tool-shell.md#tools.

Index

Constants

View Source
const (
	IDPreset  = "fx.preset"
	IDApply   = "fx.apply"
	IDKeep    = "fx.keep"
	IDRestart = "fx.restart"

	IDImage       = "look.image"
	IDShader      = "look.shader"
	IDParamPrefix = "look.param."  // + marker index
	IDRawPrefix   = "look.params." // + 0..3, without markers
	IDBlend       = "look.blend"
	IDColor       = "look.color"
	IDChange      = "look.change"
	IDEndColor    = "look.endcolor"
	IDEndScale    = "look.endscale"
	IDScale       = "look.scale"
	IDFadeIn      = "look.fadein"
	IDFadeOut     = "look.fadeout"

	IDRate     = "emit.rate"
	IDBurst    = "emit.burst"
	IDDuration = "emit.duration"
	IDLoop     = "emit.loop"
	IDMax      = "emit.max"

	IDShape  = "shape.kind"
	IDRadius = "shape.radius"
	IDWidth  = "shape.width"
	IDHeight = "shape.height"

	IDLife   = "motion.life"
	IDAngle  = "motion.angle"
	IDSpread = "motion.spread"
	IDSpeed  = "motion.speed"
	IDGravX  = "motion.gx"
	IDGravY  = "motion.gy"
	IDDrag   = "motion.drag"
	IDSpin   = "motion.spin"
	IDRotate = "motion.rot"

	IDLocal = "adv.local"
)

The ids of the panel's fields. Set receives them; the edit functions below are keyed by them.

View Source
const (
	IDEmitterSel   = "emitter.sel"
	IDEmitterAdd   = "emitter.add"
	IDEmitterDup   = "emitter.dup"
	IDEmitterDel   = "emitter.del"
	IDEmitterUp    = "emitter.up"
	IDEmitterDown  = "emitter.down"
	IDEmitterName  = "emitter.name"
	IDEmitterLayer = "emitter.layer"
	IDEmitterMute  = "emitter.mute"
	IDEmitterSolo  = "emitter.solo"
	IDEmitterReset = "emitter.reset"
)

Ids of the emitter list section. Select, mute and solo change what the panel and the preview show, never the document.

View Source
const (
	SoftCircle = BuiltinPrefix + "soft-circle.png"
	Dot        = BuiltinPrefix + "dot.png"
	Spark      = BuiltinPrefix + "spark.png"
	Ring       = BuiltinPrefix + "ring.png"
	Star       = BuiltinPrefix + "star.png"
	Square     = BuiltinPrefix + "square.png"
	Streak     = BuiltinPrefix + "streak.png"
	Flake      = BuiltinPrefix + "flake.png"
	Heart      = BuiltinPrefix + "heart.png"
	Plus       = BuiltinPrefix + "plus.png"
)

Keys of the built-in sprites.

View Source
const (
	SavePathID = "save.path"
	SaveGoID   = "save.go"
)

SavePathID and SaveGoID are the ids of the Save as form.

View Source
const BuiltinPrefix = "fx-builtin/"

BuiltinPrefix starts the asset key of a built-in sprite. The sprites are code, not files: the tool serves them from the shell's overlay filesystem while editing, and Save as copies the one in use into the project. A saved effect never names this prefix.

View Source
const (
	// Burn burns particles away along a glowing edge; see its source.
	Burn = BuiltinPrefix + "burn.kage"
)

Keys of the built-in shaders.

View Source
const DefaultPreset = 0

DefaultPreset is the preset a new effect starts from.

View Source
const Suffix = fxfile.Suffix

Suffix is the file suffix of an effect.

Variables

View Source
var BlendNames = []string{"Normal", "Additive", "Multiply", "Screen", "Subtract", "Lighten", "Erase"}

BlendNames are the entries of the Blend dropdown, indexed by gfx.Blend.

View Source
var ShapeNames = []string{"Point", "Circle", "Rect"}

ShapeNames are the entries of the Shape dropdown, indexed by gfx.EmitShape.

Functions

func Apply

func Apply(e *Emitter, ctx Context, id string, v json.RawMessage) (err error)

Apply applies the change of one panel field to e. It returns an error for a value that is nonsense for the field (a negative rate, a crossed range, a blend mode that does not exist); e is then unchanged. Buttons and the preset widgets are not fields of the emitter and are handled by the panel.

func BuiltinKeys

func BuiltinKeys() []string

BuiltinKeys returns the asset keys of the built-in sprites.

func BuiltinPNG

func BuiltinPNG(key string) ([]byte, bool)

BuiltinPNG returns the PNG bytes of the built-in sprite key.

func BuiltinShader

func BuiltinShader(key string) ([]byte, bool)

BuiltinShader returns the Kage source of the built-in shader key.

func BuiltinShaderKeys

func BuiltinShaderKeys() []string

BuiltinShaderKeys returns the asset keys of the built-in shaders.

func ChangesOverLife

func ChangesOverLife(e Emitter) bool

ChangesOverLife reports whether the particle's color or size differs between birth and death.

func ClassifyAssets

func ClassifyAssets(keys []string) (images, shaders []string)

ClassifyAssets picks the images and shaders out of a list of asset keys (a host's file index), skipping anything under a folder that starts with a dot.

func ColorHex

func ColorHex(c gfx.Color) string

ColorHex formats c as "#rrggbbaa"; the zero color is white.

func Degrees

func Degrees(rad float32) float64

Degrees converts radians to degrees for the panel, rounded to hundredths so a stored -1.5708 shows as -90.

func EffectiveScale

func EffectiveScale(e Emitter) float32

EffectiveScale is the particle size at birth: Scale, 1 when zero.

func ExportAll

func ExportAll(ems []Emitter, effectKey string) ([]Emitter, []SaveFile)

ExportAll is ExportBuiltin for every emitter of an effect, for built-in sprites and shaders. The first built-in sprite becomes PNGKey; another one gets "-2", "-3" and so on before the extension. Built-in shaders are named the same way with ".kage". Emitters that share a built-in file share the copy.

func ExportBuiltin

func ExportBuiltin(e Emitter, effectKey string) (Emitter, []SaveFile)

ExportBuiltin prepares e for saving as the effect at effectKey. An emitter that uses a built-in sprite gets a copy of it next to the effect: the returned emitter names that file and the returned slice holds it. An emitter with a project sprite is returned as it is, with no files.

func IsBuiltin

func IsBuiltin(key string) bool

IsBuiltin reports whether key names a built-in sprite.

func ListAssets

func ListAssets(fsys fs.FS) (images, shaders []string)

ListAssets walks fsys for the images (.png, .jpg, .jpeg) and shaders (.kage) a picker offers, sorted by path. Folders that start with a dot are skipped. A nil fsys returns nothing.

func New

func New() toolshell.Tool

New returns the fx tool.

func NewUntitled

func NewUntitled() []byte

NewUntitled returns the text of the untitled effect the tool starts from: the smoke preset with a built-in sprite.

func PNGKey

func PNGKey(effectKey string) string

PNGKey returns the asset key of the sprite file Save as writes for the effect at effectKey: the same folder and name, ".png".

func PresetNames

func PresetNames() []string

PresetNames returns the names of Presets, for a dropdown.

Types

type Context

type Context struct {
	Params []shaderparam.Param
}

Context is what an edit needs besides the emitter: the parameters the emitter's shader declares (none: the four plain Params numbers).

type Emitter

type Emitter = fxfile.Emitter

Emitter is the effect's emitter the panel edits: package particles' type, in the units of the simulation (radians, world units).

func ApplyPreset

func ApplyPreset(cur Emitter, p Preset, keep bool) Emitter

ApplyPreset returns the emitter with the values of the preset's first emitter. With keep a shader (and its Params) and a sprite from the project stay: the user picked them. A built-in sprite or shader is the preset's own and is replaced.

type Hooks

type Hooks struct {
	// Edit receives the text of every new document version.
	Edit func(text []byte)
	// Exists reports whether an asset exists, for the overwrite question.
	Exists func(key string) bool
	// Create writes a new document and its files (Shell.Create).
	Create func(key string, text []byte, files []SaveFile) error
}

Hooks are what the state needs from its surroundings.

type Preset

type Preset struct {
	Name     string
	Emitters []Emitter
}

Preset is a named starting point for an effect: one emitter, or a complete effect of several. The values are tuned by eye for a game of a few hundred pixels across; a preset only ever changes with the editor, never the engine.

func Presets

func Presets() []Preset

Presets returns the presets: smoke first, then the single emitters, then the effects of several emitters.

func (Preset) Multi

func (p Preset) Multi() bool

Multi reports whether the preset is a whole effect of several emitters. Applying it replaces the effect, not the selected emitter.

type SaveFile

type SaveFile = toolshell.CreateFile

SaveFile is a file Save as writes next to the effect (a toolshell.CreateFile).

func NewEffect

func NewEffect(key string) (doc []byte, files []SaveFile)

NewEffect returns the starter of a new effect file at asset key key: the untitled effect with its built-in sprite exported next to it, as Save as would write it. The text names the copy; files holds it (asset keys). The caller writes the files with the text, so the saved effect never names a built-in file.

type State

type State struct {
	// DocStatus says whether a document was parsed (Loaded) and holds the
	// parse error of the last text (Stale, the shown model stays).
	toolshell.DocStatus
	// Key is the asset key of the file, "" while the effect is untitled.
	Key string
	// Ems are the emitters of the document and Sel the one the panel edits;
	// Em is a copy of Ems[Sel].
	Ems []Emitter
	Sel int
	Em  Emitter
	// Muted[i] silences emitter i in the preview only; it is not saved and
	// may be shorter than Ems.
	Muted []bool
	// Preset is the index of the preset dropdown; Keep keeps the picked
	// image and shader when a preset is applied.
	Preset int
	Keep   bool

	// Params are the markers of the shader's source, ParamsErr their parse
	// error. The tool refreshes them when the shader changes.
	Params    []shaderparam.Param
	ParamsErr error

	// Images, Shaders and the built-in sprites are the candidates of the
	// pickers; the tool refreshes them from the asset filesystem.
	Images, Shaders []string
	// Known is true once the lists were read (a missing file is only a
	// problem then).
	Known bool

	// Live and Max feed the readout, written by the tool each tick.
	Live, Max uint16

	// SavePath is the form field of Save as; SaveEdited says the user typed
	// it, so a preset change no longer renames it. Confirm is set after a
	// click on Save when the target exists.
	SavePath   string
	SaveEdited bool
	Confirm    bool

	// Restart is set by the restart button; Burst by a click in the
	// viewport. The tool clears them after acting.
	Restart, Burst bool
	// Rev counts changes of the emitter, so the tool knows to update the
	// preview.
	Rev int
	// contains filtered or unexported fields
}

State is everything the tool knows: the effect it shows, the choices in the panel and the save-as form. It has no Ebiten, so tests drive it directly; the tool feeds it the shell and the preview.

func NewState

func NewState(key string, h Hooks) *State

NewState returns a state for the file at key ("" for an untitled effect).

func (*State) Capacity

func (s *State) Capacity() uint16

Capacity is the pool size of the whole effect, the sum over its emitters.

func (*State) Findings

func (s *State) Findings() []string

Findings returns the problems of the document: a missing image or shader, unreadable shader markers, a built-in sprite or shader in a saved file.

func (*State) Load

func (s *State) Load(doc []byte) error

Load takes a new document version. An unparsable text keeps the last good model and marks it stale; nothing is written over it.

func (*State) Panel

func (s *State) Panel(title string, view toolshell.Section) toolshell.Panel

Panel is the panel of the tool as it is now: only the fields that matter, shown when they act. The tool puts in the shell's view section (view) at the end, before the problems it adds. It never contains a runtime field (Pool, Time, Done) as an input.

func (*State) Set

func (s *State) Set(id string, v []byte) error

Set applies a change of one panel field.

func (*State) SetCandidates

func (s *State) SetCandidates(images, shaders []string)

SetCandidates records the image and shader keys found in the asset filesystem.

type Tool

type Tool struct {
	// contains filtered or unexported fields
}

Tool is the fx tool. It implements toolshell.DocumentTool, toolshell.Syncer and toolshell.Checker.

func (*Tool) Check

func (*Tool) Check(key string) error

Check reports whether the tool can open the file at asset key. An empty key is the untitled effect.

func (*Tool) Draw

func (t *Tool) Draw(s *toolshell.Shell, screen ebiten.FinalScreen)

Draw implements toolshell.Tool: the emitter cross, the spawn shape and the direction cone in window pixels.

func (*Tool) Load

func (t *Tool) Load(text []byte) error

Load implements toolshell.DocumentTool: a new version of the document. One that does not parse leaves the shown effect as it is and marks it stale.

func (*Tool) Open

func (t *Tool) Open(s *toolshell.Shell, key string) error

Open implements toolshell.Tool.

func (*Tool) Panel

func (t *Tool) Panel() toolshell.Panel

Panel implements toolshell.Tool.

func (*Tool) Set

func (t *Tool) Set(id string, v json.RawMessage) error

Set implements toolshell.Tool.

func (*Tool) Sync

func (t *Tool) Sync(s *toolshell.Shell)

Sync implements toolshell.Syncer: it keeps the preview entities in step with the model and the clock.

func (*Tool) Update

func (t *Tool) Update(s *toolshell.Shell)

Update implements toolshell.Tool: the keys and the mouse in the viewport.

type Visibility

type Visibility struct {
	// Change shows End color and End scale (change over life is on).
	Change bool
	// Loop shows the Loop checkbox (a cycle has a Duration).
	Loop bool
	// Radius shows the circle's radius, Size the rect's width and height.
	Radius, Size bool
	// Shader shows the shader parameters (a shader is set).
	Shader bool
}

Visibility says which optional fields of the panel show for an emitter: fields appear only when they act (roadmap M4c). The rules live here, in Go; when the schema gets field hints they move there.

func Visible

func Visible(e Emitter) Visibility

Visible returns what shows for e.

Jump to

Keyboard shortcuts

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