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
- Variables
- func Apply(e *Emitter, ctx Context, id string, v json.RawMessage) (err error)
- func BuiltinKeys() []string
- func BuiltinPNG(key string) ([]byte, bool)
- func BuiltinShader(key string) ([]byte, bool)
- func BuiltinShaderKeys() []string
- func ChangesOverLife(e Emitter) bool
- func ClassifyAssets(keys []string) (images, shaders []string)
- func ColorHex(c gfx.Color) string
- func Degrees(rad float32) float64
- func EffectiveScale(e Emitter) float32
- func ExportAll(ems []Emitter, effectKey string) ([]Emitter, []SaveFile)
- func ExportBuiltin(e Emitter, effectKey string) (Emitter, []SaveFile)
- func IsBuiltin(key string) bool
- func ListAssets(fsys fs.FS) (images, shaders []string)
- func New() toolshell.Tool
- func NewUntitled() []byte
- func PNGKey(effectKey string) string
- func PresetNames() []string
- type Context
- type Emitter
- type Hooks
- type Preset
- type SaveFile
- type State
- type Tool
- func (*Tool) Check(key string) error
- func (t *Tool) Draw(s *toolshell.Shell, screen ebiten.FinalScreen)
- func (t *Tool) Load(text []byte) error
- func (t *Tool) Open(s *toolshell.Shell, key string) error
- func (t *Tool) Panel() toolshell.Panel
- func (t *Tool) Set(id string, v json.RawMessage) error
- func (t *Tool) Sync(s *toolshell.Shell)
- func (t *Tool) Update(s *toolshell.Shell)
- type Visibility
Constants ¶
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.
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.
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.
const ( SavePathID = "save.path" SaveGoID = "save.go" )
SavePathID and SaveGoID are the ids of the Save as form.
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.
const ( // Burn burns particles away along a glowing edge; see its source. Burn = BuiltinPrefix + "burn.kage" )
Keys of the built-in shaders.
const DefaultPreset = 0
DefaultPreset is the preset a new effect starts from.
const Suffix = fxfile.Suffix
Suffix is the file suffix of an effect.
Variables ¶
var BlendNames = []string{"Normal", "Additive", "Multiply", "Screen", "Subtract", "Lighten", "Erase"}
BlendNames are the entries of the Blend dropdown, indexed by gfx.Blend.
var ShapeNames = []string{"Point", "Circle", "Rect"}
ShapeNames are the entries of the Shape dropdown, indexed by gfx.EmitShape.
Functions ¶
func Apply ¶
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 ¶
BuiltinPNG returns the PNG bytes of the built-in sprite key.
func BuiltinShader ¶
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 ¶
ChangesOverLife reports whether the particle's color or size differs between birth and death.
func ClassifyAssets ¶
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 Degrees ¶
Degrees converts radians to degrees for the panel, rounded to hundredths so a stored -1.5708 shows as -90.
func EffectiveScale ¶
EffectiveScale is the particle size at birth: Scale, 1 when zero.
func ExportAll ¶
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 ¶
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 ListAssets ¶
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 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 ¶
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 ¶
Emitter is the effect's emitter the panel edits: package particles' type, in the units of the simulation (radians, world units).
func ApplyPreset ¶
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 ¶
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.
type SaveFile ¶
type SaveFile = toolshell.CreateFile
SaveFile is a file Save as writes next to the effect (a toolshell.CreateFile).
func NewEffect ¶
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 (*State) Findings ¶
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 ¶
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 ¶
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) SetCandidates ¶
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 ¶
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 ¶
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 ¶
Open implements toolshell.Tool.
func (*Tool) Set ¶
func (t *Tool) Set(id string, v json.RawMessage) error
Set implements toolshell.Tool.
func (*Tool) Sync ¶
Sync implements toolshell.Syncer: it keeps the preview entities in step with the model and the clock.
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.