feat(pbs): add Beacon Workshop composition example
Add an original-asset minigame with modern controls, independent movement and tool animations, randomized safe beacon layouts and 2D drone patrols. Distribute the canonical project through installed knowledge and exercise compiled cartridges and animation boundaries. Fix lowering of admitted sibling constants and add a regression test. Focused compiler, installed knowledge and direct native checks passed; user tested and approved. Full make verify remains blocked by sandbox sysctl restrictions in ACP tests. WRK-0022 remains open.
@@ -0,0 +1,3 @@
|
||||
/build/
|
||||
/.studio/
|
||||
__pycache__/
|
||||
@@ -0,0 +1,157 @@
|
||||
# Beacon Workshop
|
||||
|
||||
A small original PBS game and an example of typed composition. Guide a repair
|
||||
robot through one workshop, pulse all three beacons, then reach the exit at the
|
||||
bottom right. Beacons change positions on each new match. Maintenance drones
|
||||
follow independent routes around the central obstacle. Contact returns the robot to
|
||||
the safe starting position and cancels its tool; lit beacons stay lit until restart.
|
||||
|
||||
Open this directory in Studio, select your runtime installation, build with
|
||||
Shipper and use Debug Play. All required art, asset registrations, palettes,
|
||||
scene data and animation definitions are included. No external game or ROM is used.
|
||||
|
||||
| Logical control | Action |
|
||||
| --- | --- |
|
||||
| D-pad | Move in eight directions; opposite directions cancel per axis |
|
||||
| A | Pulse towards the direction faced when the action starts |
|
||||
| Start | New match with a fresh beacon layout, including after victory |
|
||||
|
||||
Desktop keyboard/controller bindings belong to the selected host. The robot can
|
||||
move and turn while its tool completes a pulse. Holding A does not repeat pulses.
|
||||
A new press in the last four ticks of an action queues one next pulse. Earlier
|
||||
presses are discarded; additional presses do not create an unbounded queue.
|
||||
|
||||
## Composition
|
||||
|
||||
These are game-local structs, not a new public entity API or an inheritance tree.
|
||||
|
||||
| Type | Parts |
|
||||
| --- | --- |
|
||||
| `Robot` | `Spatial2D`, `Motor2D`, `LocomotionVisual`, `PulseTool` |
|
||||
| `Drone` | `Spatial2D`, `Motor2D`, independent `Animator`, 2D `PatrolController` |
|
||||
| `Beacon` | `Spatial2D`, independent activation flag, off/on `Sprite` |
|
||||
|
||||
`PlayerController` and `PatrolController` implement the same `Controller` contract
|
||||
and return a named tuple of movement/action intentions. The concrete actor applies
|
||||
its own rules. Only the player controller reads `Pad`. Each controller and actor
|
||||
is constructed once; mutable parts are shared only within their owning composition.
|
||||
For example a robot's motor observes the exact same spatial object as its renderer.
|
||||
Different robots/drones never share their mutable spatial or animator instances.
|
||||
|
||||
Locomotion and tool action have independent state:
|
||||
|
||||
```text
|
||||
body: Idle <-> Moving
|
||||
tool: Ready -> Pulsing -> Ready
|
||||
```
|
||||
|
||||
The body can keep stepping while the tool plays a separate `Once` clip. The tool
|
||||
captures its direction at action start; its visual offset follows the moving robot.
|
||||
The activation event happens once, at pulse start, using that tick's position.
|
||||
Remaining in `Pulsing` never emits another gameplay event.
|
||||
|
||||
`Spatial2D` uses fixed point with 256 units per pixel. Cardinal motion is 512 units
|
||||
per tick; diagonal components are 362 units. The diagonal magnitude is about
|
||||
0.0107% below cardinal motion, never faster. Fractional position is retained for
|
||||
simulation and truncated only for pixel emission. The footprint slides along the
|
||||
room's obstacles; orientation follows nonzero intention even when movement is blocked.
|
||||
|
||||
## Match variation and patrols
|
||||
|
||||
`BeaconLayout` draws one of four authored anchors in each of three regions. All
|
||||
12 positions have walkable approaches within pulse range and avoid the central
|
||||
obstacle, the robot's safe return area and the exit. Three draws produce a layout;
|
||||
if the complete triple repeats the last match, the southern choice advances to
|
||||
the next valid candidate. This bounded rule guarantees a different arrangement
|
||||
without retry loops. The map geometry stays fixed. Lit beacons keep their position
|
||||
and activation across contact; Start clears them and selects the next layout.
|
||||
|
||||
`DEFAULT_SEED` in `src/layout.pbs` is the explicit `long` value `2026`.
|
||||
`make_workshop_seed(seed)` supports controlled replay. Initialization creates
|
||||
independent Random streams for layout and each drone from three successive words
|
||||
of a root generator. Copies of a Random handle would share state; these streams
|
||||
are separately constructed. Start reuses them instead of reseeding. Reopening
|
||||
with the same seed repeats the first layout; matching seeds and ordered inputs
|
||||
reproduce the same sequence. No wall-clock entropy is assumed.
|
||||
|
||||
The drone controller follows a nine-point ring of safe connections around the
|
||||
obstacle, including vertical and diagonal legs. At a waypoint it has a one-in-four
|
||||
chance to reverse its traversal direction. Two-pixel arrival tolerance avoids
|
||||
oscillation. After 24 ticks without progress it returns to its last reached point
|
||||
and tries the opposite connection, without another random reversal on recovery.
|
||||
The ring leaves the return area clear. Each drone keeps its own current waypoint,
|
||||
destination, recovery state, Random stream and animation phase. Movement uses the
|
||||
same bounded motor as the robot; it does not gain diagonal speed or teleport at
|
||||
waypoints. Drawing never consumes random state.
|
||||
|
||||
Actors, visual parts and generators are built once. Layout selection and patrol
|
||||
updates reuse their state without constructing candidate lists, actors or Random
|
||||
objects per frame or per restart. Invalid anchor content is diagnosed at setup;
|
||||
a reset also checks its resulting placement before entering the match.
|
||||
|
||||
## Tick order and errors
|
||||
|
||||
1. Read intentions and resolve movement.
|
||||
2. Resolve contact with drones. Contact takes precedence over pulses and victory,
|
||||
returns the robot to `(64, 256)`, cancels the tool and clears the queued command.
|
||||
3. Resolve tool completion, the input window and a possible new pulse. A pulse
|
||||
activates unlit beacons within 56 pixels and a narrow forward sector.
|
||||
4. Select body clips on transitions and explicitly advance each animator once.
|
||||
5. Emit the resulting scene and sprites, followed by the small control/victory overlay.
|
||||
|
||||
The pulse lasts 12 authored ticks (three frames of four ticks). Its animator's
|
||||
`Finished` state is authoritative. The remaining-tick counter only determines the
|
||||
input window and is decremented alongside that animator's explicit advance.
|
||||
The queued press is valid only through completion of the current action and is
|
||||
consumed once. Restart and contact clear it. A new match also repositions the beacons and resets
|
||||
the drone routes while retaining the independent Random streams.
|
||||
|
||||
Factories run during `[Init]`, not from drawing. PBS requires `handle` within a
|
||||
result-returning callable, so private boundary helpers recover every domain error
|
||||
and always return `ok`. The `void` hooks discard only those recovered results.
|
||||
A directly constructed holder contains the optional game until initialization;
|
||||
global initialization never calls procedural factories. Animation failures and nonzero Composer
|
||||
statuses stop gameplay and produce a Studio log plus an error screen. These paths
|
||||
do not catch VM traps. Rendering never calls `play`/`advance`, changes gameplay or
|
||||
creates actors. Emitting twice within the same tick preserves animation and state.
|
||||
|
||||
## Original assets and installed example
|
||||
|
||||
All visual source is authored in `tools/author_assets.py`: compact pixel drawings
|
||||
of a teal/brass repair robot, coral maintenance drones, glass beacons and a metal
|
||||
workshop. The script uses only Python's standard library to generate PNGs, glyph
|
||||
bindings, the scene, palettes and `animations.studio.json`. It reads no external art.
|
||||
|
||||
```sh
|
||||
python3 tools/author_assets.py
|
||||
python3 tools/author_assets.py --check
|
||||
```
|
||||
|
||||
Edit these authoring sources when changing the art. Animation definitions can also
|
||||
be studied/edited through Studio's existing Assets animation authoring; reconcile
|
||||
intentional definition edits into the generator before regenerating. Generated
|
||||
animation factory modules are read-only and resolve through the registered bank.
|
||||
Runtime glyph slot 0 and scene slot 0 are preloaded by the existing Packer pipeline.
|
||||
Position, palette and ordering are emission inputs, not clip-definition fields.
|
||||
|
||||
This directory is the canonical source. The PBS frontend build projects its source
|
||||
and assets into `pbs-knowledge/examples/game/1/beacon-workshop`. The reference
|
||||
`pbs:example:game:1:beacon-workshop/distribution.json` lists packaged paths and hashes;
|
||||
binary PNGs are packaged resources rather than UTF-8 reference text. The installed
|
||||
runtime tests reconstruct the project from these resources and verify their hashes.
|
||||
|
||||
## What belongs in core?
|
||||
|
||||
`SpriteView` and `Animator` already provide reusable visual contracts. This example
|
||||
exercises spatial state and movement across two actor types, but collision geometry,
|
||||
patrol graph, regional anchor pools, beacon activation and pulse rules belong to
|
||||
this game. A public core
|
||||
entity/controller/motor API is deliberately deferred until other games demonstrate
|
||||
compatible requirements. In particular this room's collision function is not a
|
||||
general physics API, and one `SpriteView` cannot represent the robot's multiple
|
||||
independently emitted parts. Composition uses the current Composer API directly.
|
||||
|
||||
Validation covers the resource-distributed project, deterministic native input,
|
||||
animation boundaries, state independence and the play/win/restart loop. Static
|
||||
inspection of the hot path and executable invariance checks are distinct evidence;
|
||||
neither is presented as a native heap-allocation measurement.
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"next_asset_id": 3,
|
||||
"assets": [
|
||||
{
|
||||
"asset_id": 1,
|
||||
"asset_uuid": "baec0001-2026-4000-8000-000000000001",
|
||||
"root": "workshop",
|
||||
"included_in_build": true
|
||||
},
|
||||
{
|
||||
"asset_id": 2,
|
||||
"asset_uuid": "baec0001-2026-4000-8000-000000000002",
|
||||
"root": "room",
|
||||
"included_in_build": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"asset_uuid": "baec0001-2026-4000-8000-000000000002",
|
||||
"name": "Workshop room",
|
||||
"type": "scene_bank",
|
||||
"preload": {
|
||||
"enabled": true
|
||||
},
|
||||
"output": {
|
||||
"format": "SCENE/tilemap_v1",
|
||||
"codec": "NONE"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"bank_asset_uuid": "baec0001-2026-4000-8000-000000000001",
|
||||
"bindings": [
|
||||
{
|
||||
"artifact_id": "robot_s_idle",
|
||||
"glyph_id": 0,
|
||||
"fingerprint": "a79530833295a16466fdda9e7d74e2faeaac4e3fd9119cb904273394414a24a7"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_s_step",
|
||||
"glyph_id": 1,
|
||||
"fingerprint": "4acb96336d804db47b83665a5eb118e606ba018c96a64955ede62e49ee545424"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_se_idle",
|
||||
"glyph_id": 2,
|
||||
"fingerprint": "17e7fb3c4c625730178d945da570bf1bd37e64f89682f7ee2dae61747ab862ac"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_se_step",
|
||||
"glyph_id": 3,
|
||||
"fingerprint": "a6aaefab936f6808e0e3db6fe2a4b8cbd1138220af78fb701cfc07fcd9883196"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_e_idle",
|
||||
"glyph_id": 4,
|
||||
"fingerprint": "3e5359ea5720daf836934e2bac96b622be538b81b856c7024512c59ea4751b61"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_e_step",
|
||||
"glyph_id": 5,
|
||||
"fingerprint": "c0dc7a0b196b8c596bb1d804fb4920317b47de0612e7d2875ae097a0e8076fa2"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_ne_idle",
|
||||
"glyph_id": 6,
|
||||
"fingerprint": "fb2ded15d069de71d43db94b7c6e57a3a9e3742695f07bae35ef3f0af3cbfc77"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_ne_step",
|
||||
"glyph_id": 7,
|
||||
"fingerprint": "143e5471f6786f10f9d5447b0ada2f823e466e946d097e158d7d44a633fedf65"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_n_idle",
|
||||
"glyph_id": 8,
|
||||
"fingerprint": "6cffeefe031f26a212bec0fe0c2d66ca37b2b1b9565c6a6e95a8012eb4b4209c"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_n_step",
|
||||
"glyph_id": 9,
|
||||
"fingerprint": "b4a571e9f4db6f620ddbccfd18f0808637f6715842dd53923dcaf612b6f5ae04"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_nw_idle",
|
||||
"glyph_id": 10,
|
||||
"fingerprint": "49cfdb3b59752adf077bfa5a0d88f3c02d2901264dc44421877934c8de073bd5"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_nw_step",
|
||||
"glyph_id": 11,
|
||||
"fingerprint": "1bb590382cc96626c826d83aab627211b5998822881848883eac8986dad1478e"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_w_idle",
|
||||
"glyph_id": 12,
|
||||
"fingerprint": "3c85ed48ea2ca69ca5f67aabcc9a59dc1badeb47d09561b55fe5f36a7af3008a"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_w_step",
|
||||
"glyph_id": 13,
|
||||
"fingerprint": "5f2cce5597c8df27a79bb24aec1305832e88726a2d7616105af908215795b682"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_sw_idle",
|
||||
"glyph_id": 14,
|
||||
"fingerprint": "fd8fcda1f50c13c2d63c376f0407a62378446c0b1347f79f7829972a48b8adf3"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_sw_step",
|
||||
"glyph_id": 15,
|
||||
"fingerprint": "63604f854feffeeb038208c3af2d72dcb1f719f3c8b8869d1ba78c12e3cfefeb"
|
||||
},
|
||||
{
|
||||
"artifact_id": "drone_0",
|
||||
"glyph_id": 16,
|
||||
"fingerprint": "1030c3fddb834072ce349fb8fa8d2d8699365afc88be50b05ff326da7048b5de"
|
||||
},
|
||||
{
|
||||
"artifact_id": "drone_1",
|
||||
"glyph_id": 17,
|
||||
"fingerprint": "fd4de1e9206c16462b2ddf207fead152e448d58e66e0a075c455b5c2b68f124c"
|
||||
},
|
||||
{
|
||||
"artifact_id": "pulse_0",
|
||||
"glyph_id": 18,
|
||||
"fingerprint": "1af17d978522a920cbda8dc7382d0f1df7f35c41a12717d6376a6eb3922afbb2"
|
||||
},
|
||||
{
|
||||
"artifact_id": "pulse_1",
|
||||
"glyph_id": 19,
|
||||
"fingerprint": "2c0ab61b034f51c6e2c5e1e6c9abe7e0613b2e7ad41780761ea99c7e5c50573d"
|
||||
},
|
||||
{
|
||||
"artifact_id": "pulse_2",
|
||||
"glyph_id": 20,
|
||||
"fingerprint": "df80dcb9f25c6a2e1efbcb4bf72386b6b3441c445171032424b7cd253e7ed1b3"
|
||||
},
|
||||
{
|
||||
"artifact_id": "beacon_off",
|
||||
"glyph_id": 21,
|
||||
"fingerprint": "4a4ac16daed8dce31ff51d83aa3fd0951e664736565035656cfebd94d57cfe92"
|
||||
},
|
||||
{
|
||||
"artifact_id": "beacon_on",
|
||||
"glyph_id": 22,
|
||||
"fingerprint": "affb9acf288e37f576f2f4e51f6a3d9ca26181f4f0a0e3e4be1168ef8f86fa62"
|
||||
},
|
||||
{
|
||||
"artifact_id": "floor",
|
||||
"glyph_id": 23,
|
||||
"fingerprint": "df8ae257d47bf17efbe92f03760f90249956db4e8cbb7b6459e32179c01aaf18"
|
||||
},
|
||||
{
|
||||
"artifact_id": "wall",
|
||||
"glyph_id": 24,
|
||||
"fingerprint": "55b0d913422dbaa870e06d4228293d7bb3ac231fb99baa69eaed85d1d96b7534"
|
||||
},
|
||||
{
|
||||
"artifact_id": "exit_closed",
|
||||
"glyph_id": 25,
|
||||
"fingerprint": "0287cd1e2b9022e45ec086051483063ab4fab95b3b42949380a122543eb12780"
|
||||
},
|
||||
{
|
||||
"artifact_id": "exit_open",
|
||||
"glyph_id": 26,
|
||||
"fingerprint": "5481136bfc6a929bae8eba027dfb490ec3add4263331b700aed443b5a690c207"
|
||||
}
|
||||
],
|
||||
"animators": [
|
||||
{
|
||||
"id": "robot",
|
||||
"initial_clip": "idle_s",
|
||||
"clips": [
|
||||
{
|
||||
"name": "idle_s",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_s_idle",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "move_s",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_s_idle",
|
||||
"duration_ticks": 6
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_s_step",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "idle_se",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_se_idle",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "move_se",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_se_idle",
|
||||
"duration_ticks": 6
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_se_step",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "idle_e",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_e_idle",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "move_e",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_e_idle",
|
||||
"duration_ticks": 6
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_e_step",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "idle_ne",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_ne_idle",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "move_ne",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_ne_idle",
|
||||
"duration_ticks": 6
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_ne_step",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "idle_n",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_n_idle",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "move_n",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_n_idle",
|
||||
"duration_ticks": 6
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_n_step",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "idle_nw",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_nw_idle",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "move_nw",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_nw_idle",
|
||||
"duration_ticks": 6
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_nw_step",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "idle_w",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_w_idle",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "move_w",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_w_idle",
|
||||
"duration_ticks": 6
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_w_step",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "idle_sw",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_sw_idle",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "move_sw",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "robot_sw_idle",
|
||||
"duration_ticks": 6
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_sw_step",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "drone",
|
||||
"initial_clip": "fly",
|
||||
"clips": [
|
||||
{
|
||||
"name": "fly",
|
||||
"mode": "loop",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "drone_0",
|
||||
"duration_ticks": 6
|
||||
},
|
||||
{
|
||||
"artifact_id": "drone_1",
|
||||
"duration_ticks": 6
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pulse",
|
||||
"initial_clip": "pulse",
|
||||
"clips": [
|
||||
{
|
||||
"name": "pulse",
|
||||
"mode": "once",
|
||||
"frames": [
|
||||
{
|
||||
"artifact_id": "pulse_0",
|
||||
"duration_ticks": 4
|
||||
},
|
||||
{
|
||||
"artifact_id": "pulse_1",
|
||||
"duration_ticks": 4
|
||||
},
|
||||
{
|
||||
"artifact_id": "pulse_2",
|
||||
"duration_ticks": 4
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"asset_uuid": "baec0001-2026-4000-8000-000000000001",
|
||||
"name": "Beacon Workshop",
|
||||
"type": "glyph_bank",
|
||||
"preload": {
|
||||
"enabled": true
|
||||
},
|
||||
"output": {
|
||||
"format": "GLYPH/indexed_v1",
|
||||
"codec": "NONE",
|
||||
"metadata": {
|
||||
"tile_size": "32x32"
|
||||
},
|
||||
"pipeline": {
|
||||
"palettes": [
|
||||
{
|
||||
"index": 0,
|
||||
"palette": {
|
||||
"rgba8888": [
|
||||
0,
|
||||
270281471,
|
||||
590694911,
|
||||
961899263,
|
||||
1890500863,
|
||||
-907153153,
|
||||
1306768895,
|
||||
647135743,
|
||||
-4232705,
|
||||
-495429377,
|
||||
-1185451265,
|
||||
1734053887,
|
||||
-102050817,
|
||||
405222911,
|
||||
-2032604929,
|
||||
-1
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"artifacts": [
|
||||
{
|
||||
"artifact_id": "robot_s_idle",
|
||||
"file": "robot_s_idle.png",
|
||||
"index": 0,
|
||||
"fingerprint": "a79530833295a16466fdda9e7d74e2faeaac4e3fd9119cb904273394414a24a7"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_s_step",
|
||||
"file": "robot_s_step.png",
|
||||
"index": 1,
|
||||
"fingerprint": "4acb96336d804db47b83665a5eb118e606ba018c96a64955ede62e49ee545424"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_se_idle",
|
||||
"file": "robot_se_idle.png",
|
||||
"index": 2,
|
||||
"fingerprint": "17e7fb3c4c625730178d945da570bf1bd37e64f89682f7ee2dae61747ab862ac"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_se_step",
|
||||
"file": "robot_se_step.png",
|
||||
"index": 3,
|
||||
"fingerprint": "a6aaefab936f6808e0e3db6fe2a4b8cbd1138220af78fb701cfc07fcd9883196"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_e_idle",
|
||||
"file": "robot_e_idle.png",
|
||||
"index": 4,
|
||||
"fingerprint": "3e5359ea5720daf836934e2bac96b622be538b81b856c7024512c59ea4751b61"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_e_step",
|
||||
"file": "robot_e_step.png",
|
||||
"index": 5,
|
||||
"fingerprint": "c0dc7a0b196b8c596bb1d804fb4920317b47de0612e7d2875ae097a0e8076fa2"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_ne_idle",
|
||||
"file": "robot_ne_idle.png",
|
||||
"index": 6,
|
||||
"fingerprint": "fb2ded15d069de71d43db94b7c6e57a3a9e3742695f07bae35ef3f0af3cbfc77"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_ne_step",
|
||||
"file": "robot_ne_step.png",
|
||||
"index": 7,
|
||||
"fingerprint": "143e5471f6786f10f9d5447b0ada2f823e466e946d097e158d7d44a633fedf65"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_n_idle",
|
||||
"file": "robot_n_idle.png",
|
||||
"index": 8,
|
||||
"fingerprint": "6cffeefe031f26a212bec0fe0c2d66ca37b2b1b9565c6a6e95a8012eb4b4209c"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_n_step",
|
||||
"file": "robot_n_step.png",
|
||||
"index": 9,
|
||||
"fingerprint": "b4a571e9f4db6f620ddbccfd18f0808637f6715842dd53923dcaf612b6f5ae04"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_nw_idle",
|
||||
"file": "robot_nw_idle.png",
|
||||
"index": 10,
|
||||
"fingerprint": "49cfdb3b59752adf077bfa5a0d88f3c02d2901264dc44421877934c8de073bd5"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_nw_step",
|
||||
"file": "robot_nw_step.png",
|
||||
"index": 11,
|
||||
"fingerprint": "1bb590382cc96626c826d83aab627211b5998822881848883eac8986dad1478e"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_w_idle",
|
||||
"file": "robot_w_idle.png",
|
||||
"index": 12,
|
||||
"fingerprint": "3c85ed48ea2ca69ca5f67aabcc9a59dc1badeb47d09561b55fe5f36a7af3008a"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_w_step",
|
||||
"file": "robot_w_step.png",
|
||||
"index": 13,
|
||||
"fingerprint": "5f2cce5597c8df27a79bb24aec1305832e88726a2d7616105af908215795b682"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_sw_idle",
|
||||
"file": "robot_sw_idle.png",
|
||||
"index": 14,
|
||||
"fingerprint": "fd8fcda1f50c13c2d63c376f0407a62378446c0b1347f79f7829972a48b8adf3"
|
||||
},
|
||||
{
|
||||
"artifact_id": "robot_sw_step",
|
||||
"file": "robot_sw_step.png",
|
||||
"index": 15,
|
||||
"fingerprint": "63604f854feffeeb038208c3af2d72dcb1f719f3c8b8869d1ba78c12e3cfefeb"
|
||||
},
|
||||
{
|
||||
"artifact_id": "drone_0",
|
||||
"file": "drone_0.png",
|
||||
"index": 16,
|
||||
"fingerprint": "1030c3fddb834072ce349fb8fa8d2d8699365afc88be50b05ff326da7048b5de"
|
||||
},
|
||||
{
|
||||
"artifact_id": "drone_1",
|
||||
"file": "drone_1.png",
|
||||
"index": 17,
|
||||
"fingerprint": "fd4de1e9206c16462b2ddf207fead152e448d58e66e0a075c455b5c2b68f124c"
|
||||
},
|
||||
{
|
||||
"artifact_id": "pulse_0",
|
||||
"file": "pulse_0.png",
|
||||
"index": 18,
|
||||
"fingerprint": "1af17d978522a920cbda8dc7382d0f1df7f35c41a12717d6376a6eb3922afbb2"
|
||||
},
|
||||
{
|
||||
"artifact_id": "pulse_1",
|
||||
"file": "pulse_1.png",
|
||||
"index": 19,
|
||||
"fingerprint": "2c0ab61b034f51c6e2c5e1e6c9abe7e0613b2e7ad41780761ea99c7e5c50573d"
|
||||
},
|
||||
{
|
||||
"artifact_id": "pulse_2",
|
||||
"file": "pulse_2.png",
|
||||
"index": 20,
|
||||
"fingerprint": "df80dcb9f25c6a2e1efbcb4bf72386b6b3441c445171032424b7cd253e7ed1b3"
|
||||
},
|
||||
{
|
||||
"artifact_id": "beacon_off",
|
||||
"file": "beacon_off.png",
|
||||
"index": 21,
|
||||
"fingerprint": "4a4ac16daed8dce31ff51d83aa3fd0951e664736565035656cfebd94d57cfe92"
|
||||
},
|
||||
{
|
||||
"artifact_id": "beacon_on",
|
||||
"file": "beacon_on.png",
|
||||
"index": 22,
|
||||
"fingerprint": "affb9acf288e37f576f2f4e51f6a3d9ca26181f4f0a0e3e4be1168ef8f86fa62"
|
||||
},
|
||||
{
|
||||
"artifact_id": "floor",
|
||||
"file": "floor.png",
|
||||
"index": 23,
|
||||
"fingerprint": "df8ae257d47bf17efbe92f03760f90249956db4e8cbb7b6459e32179c01aaf18"
|
||||
},
|
||||
{
|
||||
"artifact_id": "wall",
|
||||
"file": "wall.png",
|
||||
"index": 24,
|
||||
"fingerprint": "55b0d913422dbaa870e06d4228293d7bb3ac231fb99baa69eaed85d1d96b7534"
|
||||
},
|
||||
{
|
||||
"artifact_id": "exit_closed",
|
||||
"file": "exit_closed.png",
|
||||
"index": 25,
|
||||
"fingerprint": "0287cd1e2b9022e45ec086051483063ab4fab95b3b42949380a122543eb12780"
|
||||
},
|
||||
{
|
||||
"artifact_id": "exit_open",
|
||||
"file": "exit_open.png",
|
||||
"index": 26,
|
||||
"fingerprint": "5481136bfc6a929bae8eba027dfb490ec3add4263331b700aed443b5a690c207"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 191 B |
|
After Width: | Height: | Size: 216 B |
|
After Width: | Height: | Size: 188 B |
|
After Width: | Height: | Size: 191 B |
|
After Width: | Height: | Size: 141 B |
|
After Width: | Height: | Size: 142 B |
|
After Width: | Height: | Size: 136 B |
|
After Width: | Height: | Size: 140 B |
|
After Width: | Height: | Size: 175 B |
|
After Width: | Height: | Size: 203 B |
|
After Width: | Height: | Size: 245 B |
|
After Width: | Height: | Size: 241 B |
|
After Width: | Height: | Size: 248 B |
|
After Width: | Height: | Size: 243 B |
|
After Width: | Height: | Size: 248 B |
|
After Width: | Height: | Size: 243 B |
|
After Width: | Height: | Size: 249 B |
|
After Width: | Height: | Size: 244 B |
|
After Width: | Height: | Size: 244 B |
|
After Width: | Height: | Size: 240 B |
|
After Width: | Height: | Size: 244 B |
|
After Width: | Height: | Size: 239 B |
|
After Width: | Height: | Size: 247 B |
|
After Width: | Height: | Size: 243 B |
|
After Width: | Height: | Size: 246 B |
|
After Width: | Height: | Size: 242 B |
|
After Width: | Height: | Size: 154 B |
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "workshop",
|
||||
"version": "1.0.0",
|
||||
"language": "pbs",
|
||||
"stdlib": "1",
|
||||
"target": "Game",
|
||||
"app_id": 1380077381,
|
||||
"dependencies": []
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import { Animator, AnimationError, PlaybackState } from @core:animation;
|
||||
import { Sprite } from @core:sprite;
|
||||
import { math } from @sdk:math;
|
||||
|
||||
declare const BUFFER_TICKS: int = 4;
|
||||
|
||||
declare struct LocomotionVisual(pub animator: Animator) {
|
||||
fn advance(spatial: Spatial2D, moving: bool) -> result<AnimationError> {
|
||||
let clip = body_clip(spatial.facing_x, spatial.facing_y, moving);
|
||||
if clip != this.animator.active_clip() { this.animator.play(clip)!; }
|
||||
this.animator.advance(1)!;
|
||||
return ok(());
|
||||
}
|
||||
}
|
||||
|
||||
declare struct PulseTool(pub animator: Animator, duration: int,
|
||||
pub mut active: bool, pub mut remaining: int, pub mut pending: bool,
|
||||
pub mut direction_x: int, pub mut direction_y: int, pub mut starts: int) {
|
||||
fn cancel() -> void {
|
||||
this.active = false; this.remaining = 0; this.pending = false;
|
||||
this.animator.stop();
|
||||
}
|
||||
fn request(pressed: bool, spatial: Spatial2D) -> result<AnimationError> bool {
|
||||
// Animator is authoritative for completion. remaining is only the input
|
||||
// window, derived from the authored clip duration and decremented with advance.
|
||||
if this.active && this.animator.state() == PlaybackState.Finished { this.active = false; }
|
||||
if this.active {
|
||||
if pressed && this.remaining <= BUFFER_TICKS { this.pending = true; }
|
||||
return ok(false);
|
||||
}
|
||||
if !pressed && !this.pending { return ok(false); }
|
||||
this.pending = false; this.direction_x = spatial.facing_x; this.direction_y = spatial.facing_y;
|
||||
this.animator.play("pulse")!;
|
||||
this.active = true; this.remaining = this.duration;
|
||||
// Bounded diagnostic count: it never controls gameplay or grows without limit.
|
||||
this.starts = (this.starts + 1) % 1000000;
|
||||
return ok(true);
|
||||
}
|
||||
fn advance() -> result<AnimationError> {
|
||||
if this.active {
|
||||
this.animator.advance(1)!;
|
||||
if this.remaining > 0 { this.remaining -= 1; }
|
||||
}
|
||||
return ok(());
|
||||
}
|
||||
}
|
||||
|
||||
declare struct Robot(pub spatial: Spatial2D, pub motor: Motor2D,
|
||||
pub visual: LocomotionVisual, pub tool: PulseTool) {
|
||||
fn move(source: Controller) -> bool {
|
||||
let command = source.intent(this.spatial.pixel_x(), this.spatial.pixel_y());
|
||||
this.motor.move(command.move_x, command.move_y);
|
||||
return command.pulse;
|
||||
}
|
||||
fn reset() -> result<AnimationError> {
|
||||
this.spatial.reset(HOME_X, HOME_Y); this.motor.moving = false;
|
||||
this.tool.cancel(); this.tool.starts = 0;
|
||||
this.visual.animator.play("idle_s")!;
|
||||
return ok(());
|
||||
}
|
||||
}
|
||||
|
||||
declare struct Drone(pub spatial: Spatial2D, pub motor: Motor2D,
|
||||
pub animator: Animator, pub controller: PatrolController) {
|
||||
fn move(source: Controller) -> void {
|
||||
let command = source.intent(this.spatial.pixel_x(), this.spatial.pixel_y());
|
||||
this.motor.move(command.move_x, command.move_y);
|
||||
}
|
||||
}
|
||||
|
||||
declare struct Beacon(pub spatial: Spatial2D, pub off: Sprite, pub on: Sprite, pub mut lit: bool) {
|
||||
fn receive(robot: Robot) -> void {
|
||||
if this.lit { return; }
|
||||
let dx = this.spatial.pixel_x() - robot.spatial.pixel_x();
|
||||
let dy = this.spatial.pixel_y() - robot.spatial.pixel_y();
|
||||
let forward = dx * robot.tool.direction_x + dy * robot.tool.direction_y;
|
||||
let across = math.abs(dx * robot.tool.direction_y - dy * robot.tool.direction_x);
|
||||
if forward > 0 && dx * dx + dy * dy <= 56 * 56 && across <= 24 { this.lit = true; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { Pad, Button } from @sdk:input;
|
||||
import { Random, random } from @sdk:random;
|
||||
import { math } from @sdk:math;
|
||||
|
||||
// A value payload, not a new command object per tick. Controllers decide;
|
||||
// concrete actors validate and execute. Coordinates are observations, not ownership.
|
||||
declare contract Controller {
|
||||
fn intent(x: int, y: int) -> (move_x: int, move_y: int, pulse: bool);
|
||||
}
|
||||
|
||||
declare struct PlayerController() {
|
||||
fn intent(x: int, y: int) -> (move_x: int, move_y: int, pulse: bool) {
|
||||
let dx = 0; let dy = 0;
|
||||
if Pad.down(Button.Right) { dx += 1; }
|
||||
if Pad.down(Button.Left) { dx -= 1; }
|
||||
if Pad.down(Button.Down) { dy += 1; }
|
||||
if Pad.down(Button.Up) { dy -= 1; }
|
||||
return (move_x: dx, move_y: dy, pulse: Pad.pressed(Button.A));
|
||||
}
|
||||
}
|
||||
implements Controller for PlayerController using value {
|
||||
fn intent(x: int, y: int) -> (move_x: int, move_y: int, pulse: bool) {
|
||||
return value.intent(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
// The ring's adjacent segments stay entirely outside the central obstacle and
|
||||
// the robot's return area. Direction changes happen at waypoints, not per frame.
|
||||
fn route_x(node: int) -> int {
|
||||
if node == 0 || node == 8 { return 144; }
|
||||
if node == 1 { return 256; }
|
||||
if node == 2 { return 384; }
|
||||
if node == 3 { return 512; }
|
||||
if node == 4 { return 528; }
|
||||
if node == 5 { return 448; }
|
||||
if node == 6 { return 320; }
|
||||
return 192;
|
||||
}
|
||||
fn route_y(node: int) -> int {
|
||||
if node < 3 { return 80; }
|
||||
if node == 3 { return 112; }
|
||||
if node == 4 || node == 7 { return 208; }
|
||||
if node == 5 { return 288; }
|
||||
if node == 6 { return 272; }
|
||||
return 144;
|
||||
}
|
||||
|
||||
declare struct PatrolController(rng: Random, pub mut node: int, pub mut target: int,
|
||||
pub mut heading: int, pub mut stalled: int, pub mut recovering: bool, last_x: int, last_y: int) {
|
||||
fn reset(node: int, heading: int) -> void {
|
||||
this.node = node; this.target = (node + heading + 9) % 9; this.heading = heading;
|
||||
this.last_x = route_x(node); this.last_y = route_y(node); this.stalled = 0; this.recovering = false;
|
||||
}
|
||||
fn intent(x: int, y: int) -> (move_x: int, move_y: int, pulse: bool) {
|
||||
if math.abs(x - route_x(this.target)) <= 2 && math.abs(y - route_y(this.target)) <= 2 {
|
||||
this.node = this.target;
|
||||
if !this.recovering && random.range(this.rng, 0 as long, 4 as long) == (0 as long) { this.heading = -this.heading; }
|
||||
this.recovering = false;
|
||||
this.target = (this.node + this.heading + 9) % 9;
|
||||
this.stalled = 0;
|
||||
} else {
|
||||
if x == this.last_x && y == this.last_y { this.stalled += 1; }
|
||||
else { this.stalled = 0; }
|
||||
if this.stalled >= 24 {
|
||||
// Return along the known leg before choosing the opposite connection.
|
||||
this.heading = -this.heading; this.target = this.node; this.stalled = 0; this.recovering = true;
|
||||
}
|
||||
}
|
||||
this.last_x = x; this.last_y = y;
|
||||
let dx = route_x(this.target) - x; let dy = route_y(this.target) - y;
|
||||
let ix = 0; let iy = 0;
|
||||
if dx > 2 { ix = 1; } else if dx < -2 { ix = -1; }
|
||||
if dy > 2 { iy = 1; } else if dy < -2 { iy = -1; }
|
||||
return (move_x: ix, move_y: iy, pulse: false);
|
||||
}
|
||||
}
|
||||
implements Controller for PatrolController using value {
|
||||
fn intent(x: int, y: int) -> (move_x: int, move_y: int, pulse: bool) {
|
||||
return value.intent(x, y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Generated by tools/author_assets.py from original code-authored art.
|
||||
declare const GLYPH_ROBOT_S_IDLE: int = 0;
|
||||
declare const GLYPH_ROBOT_S_STEP: int = 1;
|
||||
declare const GLYPH_ROBOT_SE_IDLE: int = 2;
|
||||
declare const GLYPH_ROBOT_SE_STEP: int = 3;
|
||||
declare const GLYPH_ROBOT_E_IDLE: int = 4;
|
||||
declare const GLYPH_ROBOT_E_STEP: int = 5;
|
||||
declare const GLYPH_ROBOT_NE_IDLE: int = 6;
|
||||
declare const GLYPH_ROBOT_NE_STEP: int = 7;
|
||||
declare const GLYPH_ROBOT_N_IDLE: int = 8;
|
||||
declare const GLYPH_ROBOT_N_STEP: int = 9;
|
||||
declare const GLYPH_ROBOT_NW_IDLE: int = 10;
|
||||
declare const GLYPH_ROBOT_NW_STEP: int = 11;
|
||||
declare const GLYPH_ROBOT_W_IDLE: int = 12;
|
||||
declare const GLYPH_ROBOT_W_STEP: int = 13;
|
||||
declare const GLYPH_ROBOT_SW_IDLE: int = 14;
|
||||
declare const GLYPH_ROBOT_SW_STEP: int = 15;
|
||||
declare const GLYPH_DRONE_0: int = 16;
|
||||
declare const GLYPH_DRONE_1: int = 17;
|
||||
declare const GLYPH_PULSE_0: int = 18;
|
||||
declare const GLYPH_PULSE_1: int = 19;
|
||||
declare const GLYPH_PULSE_2: int = 20;
|
||||
declare const GLYPH_BEACON_OFF: int = 21;
|
||||
declare const GLYPH_BEACON_ON: int = 22;
|
||||
declare const GLYPH_FLOOR: int = 23;
|
||||
declare const GLYPH_WALL: int = 24;
|
||||
declare const GLYPH_EXIT_CLOSED: int = 25;
|
||||
declare const GLYPH_EXIT_OPEN: int = 26;
|
||||
@@ -0,0 +1,69 @@
|
||||
import { Random, random } from @sdk:random;
|
||||
import { math } from @sdk:math;
|
||||
|
||||
declare const DEFAULT_SEED: long = 2026;
|
||||
|
||||
// Four authored anchors in each of three separated regions. This changes
|
||||
// instance placement; the room and collision geometry remain fixed.
|
||||
fn beacon_x(region: int, choice: int) -> int {
|
||||
if region == 0 {
|
||||
if choice == 1 { return 144; }
|
||||
if choice == 3 { return 176; }
|
||||
return 64;
|
||||
}
|
||||
if region == 1 {
|
||||
if choice == 1 { return 496; }
|
||||
if choice == 3 { return 528; }
|
||||
return 400;
|
||||
}
|
||||
return 192 + choice * 96;
|
||||
}
|
||||
fn beacon_y(region: int, choice: int) -> int {
|
||||
if region == 0 {
|
||||
if choice == 2 { return 144; }
|
||||
if choice == 3 { return 112; }
|
||||
return 80;
|
||||
}
|
||||
if region == 1 { return if choice >= 2 { 144 } else { 80 }; }
|
||||
return if choice == 3 { 288 } else { 256 };
|
||||
}
|
||||
|
||||
fn valid_anchor(x: int, y: int) -> bool {
|
||||
if !clear_position(x * SCALE, y * SCALE) { return false; }
|
||||
if math.abs(x - HOME_X) < 64 && math.abs(y - HOME_Y) < 64 { return false; }
|
||||
if math.abs(x - 576) < 48 && math.abs(y - 256) < 48 { return false; }
|
||||
// At least one axial approach from inside pulse range must be walkable.
|
||||
return clear_position(x * SCALE, (y + 32) * SCALE) || clear_position(x * SCALE, (y - 32) * SCALE) ||
|
||||
clear_position((x + 32) * SCALE, y * SCALE) || clear_position((x - 32) * SCALE, y * SCALE);
|
||||
}
|
||||
|
||||
declare struct BeaconLayout(rng: Random, pub mut west: int, pub mut east: int, pub mut south: int) {
|
||||
fn next() -> void {
|
||||
let west = random.range(this.rng, 0 as long, 4 as long) as int;
|
||||
let east = random.range(this.rng, 0 as long, 4 as long) as int;
|
||||
let south = random.range(this.rng, 0 as long, 4 as long) as int;
|
||||
// Exactly three draws. A repeated triple has a finite, valid alternative.
|
||||
if west == this.west && east == this.east && south == this.south { south = (south + 1) % 4; }
|
||||
this.west = west; this.east = east; this.south = south;
|
||||
}
|
||||
fn choice(region: int) -> int {
|
||||
if region == 0 { return this.west; }
|
||||
return if region == 1 { this.east } else { this.south };
|
||||
}
|
||||
fn x(region: int) -> int { return beacon_x(region, this.choice(region)); }
|
||||
fn y(region: int) -> int { return beacon_y(region, this.choice(region)); }
|
||||
fn valid() -> bool {
|
||||
if this.west < 0 || this.west > 3 || this.east < 0 || this.east > 3 || this.south < 0 || this.south > 3 { return false; }
|
||||
for region: int from 0 until 3 {
|
||||
for choice: int from 0 until 4 {
|
||||
if !valid_anchor(beacon_x(region, choice), beacon_y(region, choice)) { return false; }
|
||||
}
|
||||
}
|
||||
for a: int from 0 until 3 {
|
||||
for b: int from a + 1 until 3 {
|
||||
if math.abs(this.x(a) - this.x(b)) < 64 && math.abs(this.y(a) - this.y(b)) < 64 { return false; }
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Pad, Button } from @sdk:input;
|
||||
import { Log } from @sdk:log;
|
||||
import { Gfx } from @sdk:gfx;
|
||||
import { Color } from @core:color;
|
||||
import { AnimationError } from @core:animation;
|
||||
|
||||
// Procedural factories are not global initializers. A directly constructed
|
||||
// holder provides absence until the Init hook has recovered factory errors.
|
||||
declare struct GameSlot(pub mut value: optional Workshop) {
|
||||
ctor make() { this.value = none; }
|
||||
}
|
||||
declare global slot: GameSlot = new GameSlot.make();
|
||||
declare global failed: bool = false;
|
||||
|
||||
fn fail(message: str) -> void { failed = true; Log.failure(message); }
|
||||
|
||||
fn install_game() -> result<AnimationError> {
|
||||
let value = make_workshop()!;
|
||||
if !value.layout.valid() { fail("Beacon Workshop: invalid authored beacon anchors"); return ok(()); }
|
||||
slot.value = some(value);
|
||||
return ok(());
|
||||
}
|
||||
|
||||
fn initialize() -> result<AnimationError> {
|
||||
failed = false;
|
||||
handle install_game() { _ -> { fail("Beacon Workshop: unable to initialize authored animation"); ok(()) } };
|
||||
return ok(());
|
||||
}
|
||||
|
||||
fn run_frame() -> result<AnimationError> {
|
||||
if !failed {
|
||||
if let value = slot.value {
|
||||
let updated = handle tick(value) { _ -> { fail("Beacon Workshop: animation update failed"); ok(false) } };
|
||||
if updated && !render(value) { fail("Beacon Workshop: scene/sprite emission failed"); }
|
||||
}
|
||||
}
|
||||
if failed {
|
||||
Gfx.fill_rect(0, 0, 640, 360, Color.rgb(16, 28, 42));
|
||||
Gfx.draw_text(32, 160, "WORKSHOP ERROR - SEE STUDIO DIAGNOSTICS", Color.rgb(226, 120, 88));
|
||||
}
|
||||
return ok(());
|
||||
}
|
||||
|
||||
// handle belongs inside a result-returning callable in PBS. These private
|
||||
// boundary helpers recover every domain error and always return ok; only that
|
||||
// already-recovered result is discarded by the required void entrypoints.
|
||||
[Init] fn init() -> void { initialize(); }
|
||||
[Frame] fn frame() -> void { run_frame(); }
|
||||
|
||||
fn tick(value: Workshop) -> result<AnimationError> bool {
|
||||
if Pad.pressed(Button.Start) {
|
||||
value.reset()!;
|
||||
if !value.layout.valid() { fail("Beacon Workshop: invalid beacon placement"); return ok(false); }
|
||||
}
|
||||
else { value.update()!; }
|
||||
return ok(true);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
pub fn init() -> void;
|
||||
pub fn frame() -> void;
|
||||
mod contract Controller;
|
||||
mod struct PlayerController;
|
||||
mod struct PatrolController;
|
||||
mod struct Spatial2D;
|
||||
mod struct Motor2D;
|
||||
mod struct LocomotionVisual;
|
||||
mod struct PulseTool;
|
||||
mod struct Robot;
|
||||
mod struct Drone;
|
||||
mod struct Beacon;
|
||||
mod struct Workshop;
|
||||
mod struct BeaconLayout;
|
||||
mod const DEFAULT_SEED;
|
||||
mod const SCALE;
|
||||
mod const HOME_X;
|
||||
mod const HOME_Y;
|
||||
mod const GLYPH_BEACON_OFF;
|
||||
mod const GLYPH_BEACON_ON;
|
||||
mod const GLYPH_EXIT_CLOSED;
|
||||
mod const GLYPH_EXIT_OPEN;
|
||||
mod fn clear_position(x: int, y: int) -> bool;
|
||||
mod fn touches(a: Spatial2D, b: Spatial2D) -> bool;
|
||||
mod fn body_clip(dx: int, dy: int, moving: bool) -> str;
|
||||
mod fn make_workshop() -> result<AnimationError> Workshop;
|
||||
mod fn make_workshop_seed(seed: long) -> result<AnimationError> Workshop;
|
||||
mod fn beacon_x(region: int, choice: int) -> int;
|
||||
mod fn beacon_y(region: int, choice: int) -> int;
|
||||
mod fn route_x(node: int) -> int;
|
||||
mod fn route_y(node: int) -> int;
|
||||
mod fn render(value: Workshop) -> bool;
|
||||
@@ -0,0 +1,60 @@
|
||||
import { math } from @sdk:math;
|
||||
|
||||
declare const SCALE: int = 256;
|
||||
declare const SPEED: int = 512;
|
||||
declare const DIAGONAL_SPEED: int = 362;
|
||||
declare const HOME_X: int = 64;
|
||||
declare const HOME_Y: int = 256;
|
||||
|
||||
declare struct Spatial2D(pub mut x: int, pub mut y: int,
|
||||
pub mut facing_x: int, pub mut facing_y: int) {
|
||||
fn reset(x: int, y: int) -> void {
|
||||
this.x = x * SCALE; this.y = y * SCALE;
|
||||
this.facing_x = 0; this.facing_y = 1;
|
||||
}
|
||||
fn pixel_x() -> int { return this.x / SCALE; }
|
||||
fn pixel_y() -> int { return this.y / SCALE; }
|
||||
}
|
||||
|
||||
// Room-specific collision is deliberately local to this game. The visible body
|
||||
// is 32x32, its footprint is inset by eight pixels on each side.
|
||||
fn clear_position(x: int, y: int) -> bool {
|
||||
if x < 32 * SCALE || x > 576 * SCALE || y < 64 * SCALE || y > 288 * SCALE { return false; }
|
||||
return !(x + 24 * SCALE > 288 * SCALE && x + 8 * SCALE < 352 * SCALE &&
|
||||
y + 24 * SCALE > 128 * SCALE && y + 8 * SCALE < 192 * SCALE);
|
||||
}
|
||||
|
||||
declare struct Motor2D(spatial: Spatial2D, pub mut moving: bool) {
|
||||
fn move(dx: int, dy: int) -> void {
|
||||
let ix = math.clamp(dx, -1, 1); let iy = math.clamp(dy, -1, 1);
|
||||
if ix != 0 || iy != 0 {
|
||||
this.spatial.facing_x = ix; this.spatial.facing_y = iy;
|
||||
}
|
||||
let stride = if ix != 0 && iy != 0 { DIAGONAL_SPEED } else { SPEED };
|
||||
let old_x = this.spatial.x; let old_y = this.spatial.y;
|
||||
let x = old_x + ix * stride;
|
||||
if clear_position(x, old_y) { this.spatial.x = x; }
|
||||
let y = old_y + iy * stride;
|
||||
if clear_position(this.spatial.x, y) { this.spatial.y = y; }
|
||||
this.moving = old_x != this.spatial.x || old_y != this.spatial.y;
|
||||
}
|
||||
}
|
||||
|
||||
fn touches(a: Spatial2D, b: Spatial2D) -> bool {
|
||||
return math.abs(a.x - b.x) < 20 * SCALE && math.abs(a.y - b.y) < 20 * SCALE;
|
||||
}
|
||||
|
||||
fn body_clip(dx: int, dy: int, moving: bool) -> str {
|
||||
if dy > 0 {
|
||||
if dx > 0 { return if moving { "move_se" } else { "idle_se" }; }
|
||||
if dx < 0 { return if moving { "move_sw" } else { "idle_sw" }; }
|
||||
return if moving { "move_s" } else { "idle_s" };
|
||||
}
|
||||
if dy < 0 {
|
||||
if dx > 0 { return if moving { "move_ne" } else { "idle_ne" }; }
|
||||
if dx < 0 { return if moving { "move_nw" } else { "idle_nw" }; }
|
||||
return if moving { "move_n" } else { "idle_n" };
|
||||
}
|
||||
if dx > 0 { return if moving { "move_e" } else { "idle_e" }; }
|
||||
return if moving { "move_w" } else { "idle_w" };
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { SpriteView } from @core:sprite;
|
||||
import { Composer } from @sdk:composer;
|
||||
import { Gfx } from @sdk:gfx;
|
||||
import { Color } from @core:color;
|
||||
|
||||
fn emit_image(image: SpriteView, x: int, y: int, priority: int) -> bool {
|
||||
let view = image.sprite();
|
||||
return Composer.emit_sprite(view.glyph_id, 0, x, y, 1, view.bank_id, false, false, priority) == 0;
|
||||
}
|
||||
|
||||
fn draw_beacon(beacon: Beacon) -> bool {
|
||||
if beacon.lit { return emit_image(beacon.on, beacon.spatial.pixel_x(), beacon.spatial.pixel_y(), 1); }
|
||||
return emit_image(beacon.off, beacon.spatial.pixel_x(), beacon.spatial.pixel_y(), 1);
|
||||
}
|
||||
|
||||
fn render(value: Workshop) -> bool {
|
||||
if Composer.bind_scene(0) != 0 { return false; }
|
||||
Composer.set_camera(0, 0);
|
||||
if !draw_beacon(value.first_beacon) || !draw_beacon(value.second_beacon) || !draw_beacon(value.third_beacon) { return false; }
|
||||
let exit_ok = if value.all_lit() { emit_image(value.exit_open, 576, 256, 1) } else { emit_image(value.exit_closed, 576, 256, 1) };
|
||||
if !exit_ok { return false; }
|
||||
if !emit_image(value.first.animator, value.first.spatial.pixel_x(), value.first.spatial.pixel_y(), 2) { return false; }
|
||||
if !emit_image(value.second.animator, value.second.spatial.pixel_x(), value.second.spatial.pixel_y(), 2) { return false; }
|
||||
if !emit_image(value.robot.visual.animator, value.robot.spatial.pixel_x(), value.robot.spatial.pixel_y(), 3) { return false; }
|
||||
if value.robot.tool.active {
|
||||
let x = value.robot.spatial.pixel_x() + value.robot.tool.direction_x * 20;
|
||||
let y = value.robot.spatial.pixel_y() + value.robot.tool.direction_y * 20;
|
||||
if !emit_image(value.robot.tool.animator, x, y, 4) { return false; }
|
||||
}
|
||||
Gfx.fill_rect(0, 0, 640, 32, Color.rgb(16, 28, 42));
|
||||
Gfx.draw_text(16, 10, "BEACON WORKSHOP", Color.rgb(201, 237, 240));
|
||||
Gfx.draw_text(248, 10, "ACTIVATE ALL THREE BEACONS", Color.rgb(112, 174, 192));
|
||||
Gfx.fill_rect(0, 336, 640, 24, Color.rgb(16, 28, 42));
|
||||
Gfx.draw_text(16, 342, "D-PAD MOVE / A PULSE / START RESTART", Color.rgb(112, 174, 192));
|
||||
if value.won {
|
||||
Gfx.fill_rect(144, 136, 352, 80, Color.rgb(16, 28, 42));
|
||||
Gfx.draw_text(176, 156, "WORKSHOP RESTORED", Color.rgb(77, 227, 181));
|
||||
Gfx.draw_text(176, 184, "PRESS START TO PLAY AGAIN", Color.rgb(249, 234, 211));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import { create_robot, create_drone, create_pulse } from @workshop:generated/animations/b_baec0001202640008000000000000001;
|
||||
import { AnimationError } from @core:animation;
|
||||
import { Sprite, make_sprite } from @core:sprite;
|
||||
import { Random, random } from @sdk:random;
|
||||
|
||||
declare struct Workshop(pub robot: Robot, pub first: Drone, pub second: Drone,
|
||||
pub first_beacon: Beacon, pub second_beacon: Beacon, pub third_beacon: Beacon,
|
||||
pub player: PlayerController, pub exit_closed: Sprite,
|
||||
pub exit_open: Sprite, pub layout: BeaconLayout, pub mut won: bool, pub mut contacts: int) {
|
||||
fn update() -> result<AnimationError> {
|
||||
if this.won { return ok(()); }
|
||||
let pressed = this.robot.move(this.player);
|
||||
this.first.move(this.first.controller); this.second.move(this.second.controller);
|
||||
if touches(this.robot.spatial, this.first.spatial) || touches(this.robot.spatial, this.second.spatial) {
|
||||
this.robot.spatial.reset(HOME_X, HOME_Y); this.robot.motor.moving = false;
|
||||
this.robot.tool.cancel(); this.contacts = (this.contacts + 1) % 1000000;
|
||||
} else {
|
||||
let pulse = this.robot.tool.request(pressed, this.robot.spatial)!;
|
||||
if pulse {
|
||||
this.first_beacon.receive(this.robot); this.second_beacon.receive(this.robot); this.third_beacon.receive(this.robot);
|
||||
}
|
||||
if this.all_lit() && this.robot.spatial.pixel_x() >= 560 && this.robot.spatial.pixel_y() >= 240 {
|
||||
this.won = true; this.robot.tool.cancel();
|
||||
}
|
||||
}
|
||||
this.robot.visual.advance(this.robot.spatial, this.robot.motor.moving)!;
|
||||
this.robot.tool.advance()!;
|
||||
this.first.animator.advance(1)!; this.second.animator.advance(1)!;
|
||||
return ok(());
|
||||
}
|
||||
fn all_lit() -> bool { return this.first_beacon.lit && this.second_beacon.lit && this.third_beacon.lit; }
|
||||
fn reset() -> result<AnimationError> {
|
||||
this.robot.reset()!;
|
||||
this.first.spatial.reset(route_x(0), route_y(0)); this.second.spatial.reset(route_x(4), route_y(4));
|
||||
this.first.controller.reset(0, 1); this.second.controller.reset(4, -1);
|
||||
this.first.motor.moving = false; this.second.motor.moving = false;
|
||||
this.first.animator.play("fly")!; this.second.animator.play("fly")!;
|
||||
this.second.animator.advance(5)!;
|
||||
this.first_beacon.lit = false; this.second_beacon.lit = false; this.third_beacon.lit = false;
|
||||
this.layout.next(); this.place_beacons();
|
||||
this.won = false; this.contacts = 0;
|
||||
return ok(());
|
||||
}
|
||||
fn place_beacons() -> void {
|
||||
this.first_beacon.spatial.reset(this.layout.x(0), this.layout.y(0));
|
||||
this.second_beacon.spatial.reset(this.layout.x(1), this.layout.y(1));
|
||||
this.third_beacon.spatial.reset(this.layout.x(2), this.layout.y(2));
|
||||
}
|
||||
}
|
||||
|
||||
fn make_drone(seed: long, node: int, heading: int) -> result<AnimationError> Drone {
|
||||
let x = route_x(node); let y = route_y(node);
|
||||
let spatial = new Spatial2D(x * SCALE, y * SCALE, 1, 0);
|
||||
let animator = create_drone(0)!; animator.play("fly")!;
|
||||
let controller = new PatrolController(random.new(seed), node, (node + heading + 9) % 9, heading, 0, false, x, y);
|
||||
return ok(new Drone(spatial, new Motor2D(spatial, false), animator, controller));
|
||||
}
|
||||
|
||||
fn make_beacon(x: int, y: int) -> result<AnimationError> Beacon {
|
||||
let off = handle make_sprite(0, GLYPH_BEACON_OFF) { _ -> AnimationError.invalid_glyph };
|
||||
let on = handle make_sprite(0, GLYPH_BEACON_ON) { _ -> AnimationError.invalid_glyph };
|
||||
return ok(new Beacon(new Spatial2D(x * SCALE, y * SCALE, 0, 1), off, on, false));
|
||||
}
|
||||
|
||||
fn make_workshop() -> result<AnimationError> Workshop {
|
||||
return make_workshop_seed(DEFAULT_SEED);
|
||||
}
|
||||
|
||||
fn make_workshop_seed(seed: long) -> result<AnimationError> Workshop {
|
||||
let seeds = random.new(seed);
|
||||
let layout_seed = random.next(seeds); let first_seed = random.next(seeds); let second_seed = random.next(seeds);
|
||||
let layout = new BeaconLayout(random.new(layout_seed), -1, -1, -1);
|
||||
layout.next();
|
||||
let spatial = new Spatial2D(HOME_X * SCALE, HOME_Y * SCALE, 0, 1);
|
||||
let body = create_robot(0)!; body.play("idle_s")!;
|
||||
let effect = create_pulse(0)!;
|
||||
let duration: long = 0;
|
||||
let count = effect.frame_count("pulse")!;
|
||||
for index: long from (0 as long) until count {
|
||||
let definition = effect.frame_at("pulse", index)!;
|
||||
duration += definition.duration_ticks;
|
||||
}
|
||||
let tool = new PulseTool(effect, duration as int, false, 0, false, 0, 1, 0);
|
||||
let robot = new Robot(spatial, new Motor2D(spatial, false), new LocomotionVisual(body), tool);
|
||||
let closed = handle make_sprite(0, GLYPH_EXIT_CLOSED) { _ -> AnimationError.invalid_glyph };
|
||||
let opened = handle make_sprite(0, GLYPH_EXIT_OPEN) { _ -> AnimationError.invalid_glyph };
|
||||
let value = new Workshop(robot, make_drone(first_seed, 0, 1)!, make_drone(second_seed, 4, -1)!,
|
||||
make_beacon(layout.x(0), layout.y(0))!, make_beacon(layout.x(1), layout.y(1))!, make_beacon(layout.x(2), layout.y(2))!,
|
||||
new PlayerController(), closed, opened, layout, false, 0);
|
||||
value.second.animator.advance(5)!;
|
||||
return ok(value);
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Original, code-authored pixel art. Standard library only; no external art input."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import zlib
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
BANK_UUID = "baec0001-2026-4000-8000-000000000001"
|
||||
SCENE_UUID = "baec0001-2026-4000-8000-000000000002"
|
||||
PALETTE = [0x00000000, 0x101c2aff, 0x233549ff, 0x39556aff,
|
||||
0x70aec0ff, 0xc9edf0ff, 0x4de3b5ff, 0x269281ff,
|
||||
0xffbf69ff, 0xe27858ff, 0xb95772ff, 0x675b8fff,
|
||||
0xf9ead3ff, 0x182735ff, 0x86d8e8ff, 0xffffffff]
|
||||
DIRECTIONS = [("s", 0, 1), ("se", 1, 1), ("e", 1, 0), ("ne", 1, -1),
|
||||
("n", 0, -1), ("nw", -1, -1), ("w", -1, 0), ("sw", -1, 1)]
|
||||
|
||||
|
||||
def png(pixels):
|
||||
def chunk(kind, data):
|
||||
return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data))
|
||||
raw = b"".join(b"\0" + b"".join(PALETTE[c].to_bytes(4, "big") for c in row) for row in pixels)
|
||||
return (b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", 32, 32, 8, 6, 0, 0, 0))
|
||||
+ chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b""))
|
||||
|
||||
|
||||
def canvas(fill=0):
|
||||
return [[fill] * 32 for _ in range(32)]
|
||||
|
||||
|
||||
def rect(p, x, y, w, h, color):
|
||||
for yy in range(max(0, y), min(32, y + h)):
|
||||
for xx in range(max(0, x), min(32, x + w)):
|
||||
p[yy][xx] = color
|
||||
|
||||
|
||||
def robot(dx, dy, step):
|
||||
p = canvas()
|
||||
# Broad little repair automaton, brass antenna and a teal glass face.
|
||||
rect(p, 8, 25, 17, 3, 1)
|
||||
for x, phase in [(9, step), (20, 1 - step)]:
|
||||
rect(p, x, 22 + phase, 5, 5, 1)
|
||||
rect(p, x + 1, 22 + phase, 3, 3, 4)
|
||||
rect(p, 6, 11, 20, 13, 1)
|
||||
rect(p, 8, 12, 16, 10, 4)
|
||||
rect(p, 8, 12, 16, 2, 5)
|
||||
rect(p, 11, 18, 10, 4, 3)
|
||||
rect(p, 14, 19, 4, 2, 8)
|
||||
rect(p, 3, 14 + step, 4, 8, 1)
|
||||
rect(p, 4, 15 + step, 3, 5, 7)
|
||||
rect(p, 25, 15 - step, 4, 8, 1)
|
||||
rect(p, 25, 16 - step, 3, 4, 7)
|
||||
rect(p, 9, 4, 14, 10, 1)
|
||||
rect(p, 10, 5, 12, 8, 5)
|
||||
rect(p, 11 + dx * 2, 7 + dy, 9, 4, 2)
|
||||
rect(p, 12 + dx * 2, 8 + dy, 2, 2, 6)
|
||||
rect(p, 17 + dx * 2, 8 + dy, 2, 2, 6)
|
||||
rect(p, 15, 1, 2, 4, 8)
|
||||
rect(p, 14, 1, 4, 2, 12)
|
||||
return p
|
||||
|
||||
|
||||
def drone(step):
|
||||
p = canvas()
|
||||
rect(p, 7, 25, 18, 2, 1)
|
||||
rect(p, 3, 9 + step, 26, 3, 1)
|
||||
rect(p, 4, 9 + step, 8, 1, 8)
|
||||
rect(p, 20, 9 + step, 8, 1, 8)
|
||||
rect(p, 7, 10 + step, 18, 12, 1)
|
||||
rect(p, 9, 11 + step, 14, 9, 9)
|
||||
rect(p, 10, 12 + step, 12, 2, 8)
|
||||
rect(p, 12, 15 + step, 8, 3, 2)
|
||||
rect(p, 14, 15 + step, 4, 2, 12)
|
||||
rect(p, 10, 21 + step, 4, 2, 10)
|
||||
rect(p, 18, 21 + step, 4, 2, 10)
|
||||
return p
|
||||
|
||||
|
||||
def beacon(on):
|
||||
p = canvas()
|
||||
rect(p, 5, 26, 22, 3, 1)
|
||||
rect(p, 8, 23, 16, 4, 3)
|
||||
rect(p, 11, 17, 10, 7, 1)
|
||||
rect(p, 13, 18, 6, 6, 4)
|
||||
rect(p, 7, 5, 18, 14, 1)
|
||||
rect(p, 9, 7, 14, 10, 7 if on else 3)
|
||||
rect(p, 11, 8, 10, 8, 6 if on else 2)
|
||||
rect(p, 12, 8, 3, 5, 12 if on else 4)
|
||||
rect(p, 8, 4, 16, 2, 8)
|
||||
if on:
|
||||
rect(p, 2, 9, 3, 2, 6)
|
||||
rect(p, 27, 9, 3, 2, 6)
|
||||
rect(p, 15, 0, 2, 3, 6)
|
||||
return p
|
||||
|
||||
|
||||
def pulse(phase):
|
||||
p = canvas()
|
||||
radius = [5, 10, 14][phase]
|
||||
for y in range(32):
|
||||
for x in range(32):
|
||||
d = abs(x - 15) + abs(y - 15)
|
||||
if radius - 2 <= d <= radius:
|
||||
p[y][x] = 6 if phase < 2 else 14
|
||||
rect(p, 14, 14, 3, 3, 12)
|
||||
return p
|
||||
|
||||
|
||||
def terrain(wall=False):
|
||||
p = canvas(2 if wall else 13)
|
||||
rect(p, 0, 0, 32, 1, 4 if wall else 2)
|
||||
rect(p, 0, 0, 1, 32, 3 if wall else 2)
|
||||
rect(p, 0, 30, 32, 2, 1)
|
||||
rect(p, 30, 0, 2, 32, 1)
|
||||
if wall:
|
||||
rect(p, 3, 4, 26, 23, 3)
|
||||
rect(p, 5, 6, 22, 2, 4)
|
||||
for x in (7, 23):
|
||||
rect(p, x, 22, 2, 2, 8)
|
||||
else:
|
||||
for x, y in ((5, 5), (25, 5), (5, 25), (25, 25)):
|
||||
rect(p, x, y, 1, 1, 3)
|
||||
return p
|
||||
|
||||
|
||||
def door(opened):
|
||||
p = canvas()
|
||||
rect(p, 1, 0, 30, 32, 1)
|
||||
rect(p, 3, 2, 26, 30, 4)
|
||||
rect(p, 6, 4, 20, 28, 7 if opened else 2)
|
||||
rect(p, 9, 7, 14, 23, 6 if opened else 3)
|
||||
rect(p, 14, 13, 4, 11, 12 if opened else 9)
|
||||
return p
|
||||
|
||||
|
||||
def json_bytes(value):
|
||||
return (json.dumps(value, indent=2) + "\n").encode()
|
||||
|
||||
|
||||
def generated():
|
||||
files, artifacts, clips = {}, [], []
|
||||
|
||||
def glyph(name, pixels):
|
||||
data = png(pixels)
|
||||
index = len(artifacts)
|
||||
fingerprint = hashlib.sha256(data).hexdigest()
|
||||
artifacts.append(dict(artifact_id=name, file=name + ".png", index=index, fingerprint=fingerprint))
|
||||
files["assets/workshop/" + name + ".png"] = data
|
||||
return name
|
||||
|
||||
for name, dx, dy in DIRECTIONS:
|
||||
idle = glyph("robot_" + name + "_idle", robot(dx, dy, 0))
|
||||
moving = glyph("robot_" + name + "_step", robot(dx, dy, 1))
|
||||
clips.append(dict(name="idle_" + name, mode="loop", frames=[dict(artifact_id=idle, duration_ticks=6)]))
|
||||
clips.append(dict(name="move_" + name, mode="loop", frames=[dict(artifact_id=idle, duration_ticks=6), dict(artifact_id=moving, duration_ticks=6)]))
|
||||
fly = [glyph("drone_" + str(i), drone(i)) for i in range(2)]
|
||||
effect = [glyph("pulse_" + str(i), pulse(i)) for i in range(3)]
|
||||
for name, image in [("beacon_off", beacon(False)), ("beacon_on", beacon(True)),
|
||||
("floor", terrain()), ("wall", terrain(True)),
|
||||
("exit_closed", door(False)), ("exit_open", door(True))]:
|
||||
glyph(name, image)
|
||||
bank = dict(schema_version=1, asset_uuid=BANK_UUID, name="Beacon Workshop", type="glyph_bank",
|
||||
preload=dict(enabled=True), output=dict(format="GLYPH/indexed_v1", codec="NONE",
|
||||
metadata=dict(tile_size="32x32"), pipeline=dict(palettes=[dict(index=0, palette=dict(
|
||||
rgba8888=[color if color < 0x80000000 else color - 0x100000000 for color in PALETTE]))])), artifacts=artifacts)
|
||||
files["assets/workshop/asset.json"] = json_bytes(bank)
|
||||
binding = [dict(artifact_id=a["artifact_id"], glyph_id=a["index"], fingerprint=a["fingerprint"]) for a in artifacts]
|
||||
animators = [dict(id="robot", initial_clip="idle_s", clips=clips),
|
||||
dict(id="drone", initial_clip="fly", clips=[dict(name="fly", mode="loop", frames=[dict(artifact_id=g, duration_ticks=6) for g in fly])]),
|
||||
dict(id="pulse", initial_clip="pulse", clips=[dict(name="pulse", mode="once", frames=[dict(artifact_id=g, duration_ticks=4) for g in effect])])]
|
||||
files["assets/workshop/animations.studio.json"] = json_bytes(dict(schema_version=1, bank_asset_uuid=BANK_UUID, bindings=binding, animators=animators))
|
||||
ids = {a["artifact_id"]: a["index"] for a in artifacts}
|
||||
tiles = []
|
||||
for y in range(12):
|
||||
for x in range(20):
|
||||
solid = x in (0, 19) or y in (1, 10, 11) or (9 <= x <= 10 and 4 <= y <= 5)
|
||||
tiles.append(dict(active=True, glyph_id=ids["wall" if solid else "floor"], palette_id=0, flip_x=False, flip_y=False))
|
||||
layer = dict(active=True, glyph_asset_id=1, tile_size=32, parallax_factor_x=1.0, parallax_factor_y=1.0, width=20, height=12, tiles=tiles)
|
||||
files["assets/room/asset.json"] = json_bytes(dict(schema_version=1, asset_uuid=SCENE_UUID, name="Workshop room", type="scene_bank", preload=dict(enabled=True), output=dict(format="SCENE/tilemap_v1", codec="NONE")))
|
||||
inactive = dict(active=False, glyph_asset_id=1, tile_size=32, parallax_factor_x=1.0,
|
||||
parallax_factor_y=1.0, width=1, height=1,
|
||||
tiles=[dict(active=False, glyph_id=0, palette_id=0, flip_x=False, flip_y=False)])
|
||||
files["assets/room/scene-bank.pack-request.json"] = json_bytes(dict(schema_version=1, format="SCENE/tilemap_v1", version=1, layers=[layer, inactive, inactive, inactive]))
|
||||
files["assets/.prometeu/index.json"] = json_bytes(dict(schema_version=1, next_asset_id=3, assets=[dict(asset_id=1, asset_uuid=BANK_UUID, root="workshop", included_in_build=True), dict(asset_id=2, asset_uuid=SCENE_UUID, root="room", included_in_build=True)]))
|
||||
files["src/glyphs.pbs"] = ("// Generated by tools/author_assets.py from original code-authored art.\n" + "\n".join("declare const GLYPH_" + name.upper() + ": int = " + str(index) + ";" for name, index in ids.items()) + "\n").encode()
|
||||
return files
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--check", action="store_true", help="verify checked-in outputs without changing them")
|
||||
args = parser.parse_args()
|
||||
for relative, data in generated().items():
|
||||
destination = ROOT / relative
|
||||
if args.check:
|
||||
if not destination.is_file() or destination.read_bytes() != data:
|
||||
raise SystemExit("Out-of-date generated asset: " + relative)
|
||||
else:
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
destination.write_bytes(data)
|
||||
print("Beacon Workshop: original assets " + ("verified" if args.check else "generated"))
|
||||