Provides comprehensive context about the Codako game engine's world operator, actor/character/rule types, stage helpers, and simulation logic...
Activate this skill when working on:
frontend/src/editor/utils/world-operator.ts)frontend/src/editor/utils/stage-helpers.ts)frontend/src/types.ts)| File | Purpose |
|---|---|
frontend/src/types.ts |
All domain model types |
frontend/src/editor/utils/world-operator.ts |
Simulation engine |
frontend/src/editor/utils/stage-helpers.ts |
Position, transform, and comparison helpers |
frontend/src/editor/utils/frame-accumulator.ts |
Animation frame tracking |
frontend/src/editor/utils/world-constants.ts |
FLOW_BEHAVIORS and CONTAINER_TYPES |
Character (template)
βββ rules: RuleTreeItem[] # Behavior tree
βββ spritesheet.appearances # Sprites
βββ variables # Variable definitions
Actor (instance of Character)
βββ characterId # Reference to template
βββ position: {x, y} # Grid coordinates
βββ appearance # Current sprite ID
βββ variableValues # Instance variable overrides
βββ transform # Rotation/flip
Stage (2D grid)
βββ actors: {[id]: Actor}
βββ width, height
βββ wrapX, wrapY # Edge wrapping
World (complete state)
βββ stages: {[id]: Stage}
βββ globals # Global variables
βββ input: {keys, clicks} # Current frame input
βββ evaluatedRuleDetails # Debug: detailed rule evaluation results
βββ evaluatedTickFrames # Debug: animation frames
βββ history: HistoryItem[] # Undo stack (max 20)
A Rule defines a beforeβafter pattern transformation:
Rule = {
mainActorId: string // "Owner" actor, always at (0,0) in rule space
actors: {[id]: Actor} // "Before" pattern - positions relative to mainActor
conditions: RuleCondition[] // Additional constraints
actions: RuleAction[] // Transformations to apply
extent: RuleExtent // Bounding box {xmin, xmax, ymin, ymax, ignored}
}
Rules are organized hierarchically:
RuleTreeEventItem (group-event): Filters by input
event: "key" with code - Specific key pressevent: "click" - Actor was clickedevent: "idle" - Always firesRuleTreeFlowItem (group-flow): Controls iteration
behavior: "first" - Stop after first matchbehavior: "all" - Execute all matches, then hand control back to the
parent container so the rules after this group still get a turn ("Do All
& Continue")behavior: "random" - Shuffle, then first matchbehavior: "loop" - Repeat N timesRuleCondition: Comparison between two RuleValues
{ left: RuleValue, comparator: VariableComparator, right: RuleValue, enabled: boolean }
RuleValue variants:
{ constant: string } - Literal value{ actorId, variableId } - Actor's variable/appearance/transform{ globalId } - Global variableRuleAction types:
move - Change position (delta or offset)appearance - Change spritetransform - Rotate/flipvariable - Modify actor variable (add/set/subtract)delete - Remove actorcreate - Spawn new actorglobal - Modify global variableWorldOperator(previousWorld, characters, characterZOrder) β {
tick(), // Advance simulation one step
untick(), // Revert to previous state
resetForRule() // Set up for rule preview
}
ActorOperator, top-most character
first (sortActorIdsByTickOrder: descending characterZOrder, then actor
id), so execution order follows the layering the user sees on the stage.
Each actor is visited exactly once: an actor blocked by a neighbour that
has not moved yet stays put until the next tick, and when two actors want
the same square the one layered on top gets itFor each grid cell in rule.extent:
Returns {ruleActorId β stageActor} mapping, or false.
{ [actorId]: { [ruleId]: EvaluatedRuleDetails } }
Tracks detailed evaluation results for each rule per actor. Includes:
Used by inspector to show rule state circles and condition status dots. See granular-rule-tracking.md for full details.
Frame[] where Frame = { actors: {[id]: FrameActor}, id: number }
FrameActor = Actor & { deleted?, actionIdx?, animationStyle? }
Animation frames within a tick. Stage container animates through these.
updeep (imported as u) for state updatesdeepClone from utils)wrappedPosition() for stage edge handlingarchitecture-reference.md - Detailed architecture diagrams, data flow, and code examplesgranular-rule-tracking.md - Documentation for the granular rule evaluation tracking system (square/condition-level feedback)