feat(pbs): add Beacon Workshop composition example
Test / Tests and coverage
Intrepid/Prometeu/Studio/pipeline/head This commit looks good

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.
This commit is contained in:
2026-11-26 18:37:09 +00:00
parent 533c4110f4
commit fccfeca39d
54 changed files with 3880 additions and 7 deletions
+1
View File
@@ -127,6 +127,7 @@ tasks.register<Test>("headlessProcessTest") {
include("**/HeadlessInstalledRuntimeTest.class")
include("**/GuestTestsInstalledRuntimeTest.class")
include("**/AnimationInstalledRuntimeTest.class")
include("**/BeaconWorkshopInstalledRuntimeTest.class")
systemProperty("pbs.registryConformanceDirectory",
project(":prometeu-compiler:prometeu-build-pipeline").layout.buildDirectory.dir("registry-conformance").get().asFile.absolutePath)
include("**/HeadlessTaskIntegrationTest.class")
@@ -0,0 +1,256 @@
package p.studio.app.animation;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.io.TempDir;
import p.packer.Packer;
import p.studio.api.automation.*;
import p.studio.api.project.*;
import p.studio.app.assets.PackerGlyphBankLayouts;
import p.studio.app.compiler.CompilerBuildGatewayAdapter;
import p.studio.app.operation.ExecutorOperationExecutor;
import p.studio.app.runtime.HeadlessProcessGateway;
import p.studio.core.project.*;
import p.studio.core.shipper.StudioShipperService;
import p.studio.core.runtime.HeadlessGateway;
import java.io.ByteArrayInputStream;
import java.nio.file.*;
import java.security.MessageDigest;
import java.util.*;
import java.util.concurrent.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import static org.junit.jupiter.api.Assertions.*;
/** Compiles the exact resource-distributed game, then drives the packaged native process. */
@Tag("integration")
class BeaconWorkshopInstalledRuntimeTest {
@TempDir Path root;
final ObjectMapper mapper = new ObjectMapper();
void extract() throws Exception {
var loader = p.studio.compiler.FrontendRegistryService.require("pbs").getClass().getClassLoader();
try (var input = loader.getResourceAsStream("pbs-knowledge/examples/game/1/beacon-workshop/distribution.json")) {
assertNotNull(input, "Missing canonical game projection");
var inventory = mapper.readTree(input);
for (var file : inventory.path("files")) {
Path target = root.resolve(file.path("path").asText());
assertTrue(target.normalize().startsWith(root));
try (var resource = loader.getResourceAsStream(file.path("resource").asText())) {
assertNotNull(resource, file.toString());
byte[] bytes = resource.readAllBytes();
assertEquals(file.path("sha256").asText(), HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(bytes)));
Files.createDirectories(target.getParent()); Files.write(target, bytes);
}
}
}
}
@FunctionalInterface interface Scenario { void run(HeadlessGateway.Session session) throws Exception; }
void runGame(boolean probe, boolean brokenInitialization, Scenario scenario) throws Exception {
extract();
if (probe) {
try (var input = getClass().getResourceAsStream("/beacon-workshop/verify.pbs")) {
assertNotNull(input); Files.write(root.resolve("src/verify.pbs"), input.readAllBytes());
}
Files.writeString(root.resolve("src/mod.barrel"), "\nmod fn verify_components(value: Workshop) -> result<AnimationError> bool;\nmod fn verify_variation(value: Workshop, trial: int) -> void;\n", StandardOpenOption.APPEND);
Path main = root.resolve("src/main.pbs");
Files.writeString(main, Files.readString(main).replace("fn run_frame() -> result<AnimationError> {", """
fn run_frame() -> result<AnimationError> {
if !probe_done {
if let value = slot.value {
handle verify_components(value) { _ -> { fail("Guest verification failed"); ok(false) } };
}
probe_done = true;
}
if variation_trial < 512 {
if let value = slot.value { verify_variation(value, variation_trial); }
variation_trial += 1;
}
""") + "\ndeclare global probe_done: bool = false;\ndeclare global variation_trial: int = 0;\n");
}
if (brokenInitialization) {
Path file = root.resolve("src/workshop.pbs");
Files.writeString(file, Files.readString(file).replace("let body = create_robot(0)!", "let body = create_robot(300)!"));
}
String install = System.getProperty("studio.test.runtimeInstall");
assertNotNull(install, "Supply -PstudioRuntimeInstall");
var setup = new ProjectLocalStudioSetupStore(mapper);
var project = new ProjectCatalogService(root.getParent(), mapper, setup).openProject(root);
setup.save(project, new ProjectLocalStudioSetup(install, null));
try (var workers = Executors.newSingleThreadExecutor(); var packer = Packer.bootstrap(mapper, ignored -> {})) {
var layouts = new PackerGlyphBankLayouts(packer.workspaceService(), mapper);
var build = new StudioShipperService(new CompilerBuildGatewayAdapter(layouts), packer.workspaceService(), mapper,
new ExecutorOperationExecutor(workers)).withAssetPreflight(new p.studio.app.assets.AssetBudgetInspection(
mapper, packer.workspaceService(), setup::load)).prepare(project, ignored -> {}).completion().toCompletableFuture().get(60, TimeUnit.SECONDS);
if (!build.success()) for (var issue : build.issues()) System.out.println(mapper.writeValueAsString(issue.toMap()));
assertTrue(build.success(), build.diagnostics().toString());
{
String variant = probe ? "component-checks" : brokenInitialization ? "initialization-error" : "cartridge";
Path artifact = Path.of(System.getProperty("pbs.registryConformanceDirectory")).resolve("beacon-workshop/" + variant);
try (var files = Files.walk(build.manifestPath().getParent())) {
for (Path file : files.filter(Files::isRegularFile).toList()) {
Path target = artifact.resolve(build.manifestPath().getParent().relativize(file).toString());
Files.createDirectories(target.getParent()); Files.copy(file, target, StandardCopyOption.REPLACE_EXISTING);
}
}
}
var session = new HeadlessProcessGateway(mapper, setup::load).boot(project, "beacon-workshop", build);
try {
scenario.run(session);
} finally { session.shutdown().toCompletableFuture().get(10, TimeUnit.SECONDS); }
}
}
BufferedImage advance(HeadlessGateway.Session session, int ticks, Map<String, Object> input) throws Exception {
session.call(TaskTools.HeadlessAction.CLEAR_INPUT, Map.of());
if (!input.isEmpty()) session.call(TaskTools.HeadlessAction.SET_INPUT, input);
var outcome = session.advance(ticks, ignored -> {});
assertEquals(AutomationOutcome.Kind.SUCCEEDED, outcome.kind(), outcome.toString());
assertNull(session.call(TaskTools.HeadlessAction.FAULT, Map.of()).values().get("fault"));
var image = ImageIO.read(new ByteArrayInputStream(outcome.capture().png()));
assertEquals(640, image.getWidth()); assertEquals(360, image.getHeight());
return image;
}
void save(String name, BufferedImage image) throws Exception {
Path directory = Path.of(System.getProperty("pbs.registryConformanceDirectory")).resolve("beacon-workshop");
Files.createDirectories(directory); ImageIO.write(image, "png", directory.resolve(name + ".png").toFile());
}
// Image-driven test pilot uses independent art signatures and live drone positions.
// It sends real logical input; it never changes production state or sources.
static int[] robot(BufferedImage image) {
for(int y=64;y<=288;y++) for(int x=32;x<=576;x++)
if(image.getRGB(x+15,y+1)==0xfff9ead3 && image.getRGB(x+10,y+5)==0xffc9edf0
&& image.getRGB(x+8,y+12)==0xffc9edf0 && image.getRGB(x+14,y+19)==0xffffbf69)
return new int[]{x,y};
throw new AssertionError("Robot art signature missing");
}
static List<int[]> drones(BufferedImage image) {
var points=new ArrayList<int[]>();
for(int y=64;y<=288;y++) for(int x=32;x<=576;x++)
if(image.getRGB(x+9,y+11)==0xffe27858 && image.getRGB(x+10,y+12)==0xffffbf69
&& image.getRGB(x+12,y+15)==0xff233549 && image.getRGB(x+14,y+15)==0xfff9ead3)
points.add(new int[]{x,y});
return points;
}
static boolean walkable(int x,int y) {
return x>=32&&x<=576&&y>=64&&y<=288&&!(x>264&&x<344&&y>104&&y<184);
}
static int nextDirection(int x,int y,int gx,int gy,List<int[]> hazards) {
int columns=81; var queue=new ArrayDeque<Integer>(); var parent=new HashMap<Integer,Integer>();
int start=(y/8)*columns+x/8,goal=(gy/8)*columns+gx/8;queue.add(start);parent.put(start,-1);
int[] dx={0,1,0,-1},dy={-1,0,1,0};
while(!queue.isEmpty()&&!parent.containsKey(goal)) {
int cell=queue.remove();int cx=cell%columns*8,cy=cell/columns*8;
for(int n=0;n<4;n++) {
int nx=cx+dx[n]*8,ny=cy+dy[n]*8,key=(ny/8)*columns+nx/8;
if(!walkable(nx,ny)||parent.containsKey(key)) continue;
boolean blocked=false;
for(int[] drone:hazards) if(Math.abs(nx-drone[0])<40&&Math.abs(ny-drone[1])<40) blocked=true;
if(blocked) continue;parent.put(key,cell);queue.add(key);
}
}
if(!parent.containsKey(goal)) return -1;
int next=goal;while(parent.get(next)!=start) next=parent.get(next);
int nx=next%columns*8,ny=next/columns*8;
return nx>x?1:nx<x?3:ny>y?2:0;
}
static boolean victory(BufferedImage image) {
if(image.getRGB(150,140)!=0xff101c2a) return false;
for(int y=156;y<168;y++)for(int x=176;x<464;x++)if(image.getRGB(x,y)==0xff4de3b5)return true;
return false;
}
BufferedImage navigate(HeadlessGateway.Session session,BufferedImage image,int gx,int gy,boolean finish) throws Exception {
String[] directions={"up","right","down","left"};
for(int n=0;n<600;n++) {
if(finish&&victory(image)) return image;
int[] position=robot(image); if(position[0]==gx&&position[1]==gy)return image;
int direction=nextDirection(position[0],position[1],gx,gy,drones(image));
image=advance(session,4,direction<0?Map.of():Map.of(directions[direction],true));
}
throw new AssertionError("Pilot could not reach "+gx+","+gy);
}
BufferedImage pulse(HeadlessGateway.Session session,BufferedImage image,String direction,String reverse) throws Exception {
advance(session,1,Map.of(direction,true,"a",true));
advance(session,1,Map.of(reverse,true,"a",true));
return advance(session,24,Map.of("a",true)); // held button never repeats the action
}
static int beaconMask(BufferedImage image) {
int[][] anchors={{64,80},{144,80},{64,144},{176,112},{400,80},{496,80},{400,144},{528,144},
{192,256},{288,256},{384,256},{480,288}};
int mask=0;
for(int n=0;n<anchors.length;n++) {
int x=anchors[n][0],y=anchors[n][1];
if(image.getRGB(x+8,y+4)==0xffffbf69&&image.getRGB(x+8,y+23)==0xff39556a)mask|=1<<n;
}
return mask;
}
static int countBeacons(BufferedImage image,int color) {
int[][] anchors={{64,80},{144,80},{64,144},{176,112},{400,80},{496,80},{400,144},{528,144},
{192,256},{288,256},{384,256},{480,288}};
int count=0;for(int[] point:anchors)if(image.getRGB(point[0]+8,point[1]+4)==0xffffbf69
&& image.getRGB(point[0]+8,point[1]+23)==0xff39556a && image.getRGB(point[0]+16,point[1]+8)==color)count++;
return count;
}
@Test void distributedGameAcceptsInputActivatesAllBeaconsWinsAndRestarts() throws Exception {
runGame(false, false, session -> {
var initial = advance(session, 1, Map.of()); save("initial", initial);
// Seed 2026 -> regional choices (2,3,0), independently checked against
// @sdk:random in verify.pbs. Color oracles come from original authored art.
int[][] beacons = {{64,144},{528,144},{192,256}};
for (int[] point : beacons) assertEquals(0xff233549, initial.getRGB(point[0]+16,point[1]+8));
var opposed = advance(session, 5, Map.of("left", true, "right", true, "up", true, "down", true));
assertArrayEquals(initial.getRGB(64,256,32,32,null,0,32),opposed.getRGB(64,256,32,32,null,0,32));
BufferedImage image = opposed;
image = navigate(session,image,64,176,false);
image = pulse(session,image,"up","down");
assertEquals(0xff4de3b5,image.getRGB(80,152)); save("first-beacon",image);
image = navigate(session,image,480,144,false);
image = pulse(session,image,"right","left");
assertEquals(0xff4de3b5,image.getRGB(544,152));
image = navigate(session,image,192,288,false);
image = pulse(session,image,"up","down");
for (int[] point:beacons) assertEquals(0xff4de3b5,image.getRGB(point[0]+16,point[1]+8));
assertEquals(0xff4de3b5,image.getRGB(588,268)); save("all-beacons",image);
var won=navigate(session,image,576,256,true); assertTrue(victory(won));save("victory",won);
var frozen=advance(session,20,Map.of("left",true,"a",true));
assertArrayEquals(won.getRGB(0,0,640,360,null,0,640),frozen.getRGB(0,0,640,360,null,0,640));
var restarted=advance(session,1,Map.of("start",true));save("restarted",restarted);
assertFalse(victory(restarted));
assertEquals(3,countBeacons(restarted,0xff233549));
assertNotEquals(beaconMask(initial),beaconMask(restarted),"New match must change the layout itself");
// A new native boot repeats the exact seed/ordered-input initial state.
session.call(TaskTools.HeadlessAction.RESET,Map.of());
session.call(TaskTools.HeadlessAction.BOOT,Map.of());
var replay=advance(session,1,Map.of());
assertArrayEquals(initial.getRGB(0,0,640,360,null,0,640),replay.getRGB(0,0,640,360,null,0,640));
});
}
@Test void componentsBoundariesCancellationErrorsAndRepeatedEmissionRunNatively() throws Exception {
runGame(true, false, session -> {
var image = advance(session, 1, Map.of());
// A failed guest check traps, while handled result errors remain playable.
assertEquals(0xff4de3b5, image.getRGB(76, 265));
save("component-checks", image);
advance(session, 512, Map.of());
});
}
@Test void voidInitializationHandlesFactoryFailureWithoutEnteringGameplay() throws Exception {
runGame(false, true, session -> {
var image = advance(session, 3, Map.of("a", true));
assertEquals(0xff101c2a, image.getRGB(112, 108));
// First letter of the error message has the declared coral diagnostic color.
boolean found = false;
for (int y=160;y<176;y++) for(int x=32;x<340;x++) found |= image.getRGB(x,y)==0xffe27858;
assertTrue(found, "Handled factory failure must show the diagnostic screen");
});
}
}
@@ -21,6 +21,7 @@ public final class InstalledKnowledgeProbe {
check(!Files.exists(Path.of("settings.gradle.kts")) && !Files.exists(Path.of("docs")), "No repository in working directory");
verifyRuntimeCatalogs(provider.getClass().getClassLoader());
if (arguments.length == 1 && arguments[0].equals("--catalog-only")) return;
verifyBeaconWorkshop(provider.getClass().getClassLoader());
var guideType = Class.forName("p.studio.app.mcp.McpConnectionGuide");
check(guideType.getProtectionDomain().getCodeSource().getLocation().getPath().endsWith(".jar"), "Lifecycle guide must come from installed JAR");
var guide = (String)guideType.getField("INSTRUCTIONS").get(null);
@@ -283,6 +284,48 @@ public final class InstalledKnowledgeProbe {
System.out.println("Packaged external sources verified: JAR bytes, SDK/host/core navigation, hover, tokens, read-only, reconnect, no extraction");
}
private static void verifyBeaconWorkshop(ClassLoader loader) throws Exception {
String resource = "pbs-knowledge/examples/game/1/beacon-workshop/distribution.json";
var location = loader.getResource(resource);
check(location != null && location.getProtocol().equals("jar"), "Beacon Workshop must come from installed JAR");
var mapper = new ObjectMapper();
Path root = Files.createDirectory(Path.of("beacon-workshop")).toRealPath();
try (var input = location.openStream()) {
for (var file : mapper.readTree(input).path("files")) {
Path target = root.resolve(file.path("path").asText()).normalize();
check(target.startsWith(root), "Packaged game path must stay inside project");
var url = loader.getResource(file.path("resource").asText());
check(url != null && url.getProtocol().equals("jar"), "Every game resource must come from installed JAR");
try (var bytes = url.openStream()) {
byte[] data = bytes.readAllBytes();
check(java.util.HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(data))
.equals(file.path("sha256").asText()), "Installed game resource hash mismatch");
Files.createDirectories(target.getParent()); Files.write(target, data);
}
}
}
var setup = new ProjectLocalStudioSetupStore(mapper);
var project = new ProjectCatalogService(root.getParent(), mapper, setup).openProject(root);
try (var workers = java.util.concurrent.Executors.newSingleThreadExecutor(); var packer = p.packer.Packer.bootstrap(mapper, ignored -> {})) {
var layouts = new p.studio.app.assets.PackerGlyphBankLayouts(packer.workspaceService(), mapper);
var build = new p.studio.core.shipper.StudioShipperService(new p.studio.app.compiler.CompilerBuildGatewayAdapter(layouts),
packer.workspaceService(), mapper, new p.studio.app.operation.ExecutorOperationExecutor(workers))
.prepare(project, ignored -> {}).completion().toCompletableFuture().get(60, java.util.concurrent.TimeUnit.SECONDS);
check(build.success(), "Installed Beacon Workshop must compile and pack: " + build.diagnostics());
Path output = Path.of(System.getProperty("pbs.registryConformanceDirectory")).resolve("beacon-workshop/installed-cartridge");
try (var files = Files.walk(build.manifestPath().getParent())) {
for (Path source : files.filter(Files::isRegularFile).toList()) {
Path target = output.resolve(build.manifestPath().getParent().relativize(source).toString());
Files.createDirectories(target.getParent()); Files.copy(source, target, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
}
}
mapper.writeValue(output.resolve("installed-source.json").toFile(), java.util.Map.of("resource", location.toString(),
"programSha256", java.util.HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256")
.digest(Files.readAllBytes(output.resolve("program.pbx"))))));
}
System.out.println("Installed Beacon Workshop verified: original resources, hashes, generated factories, compile and pack");
}
private static int[] position(String text, String needle, int offset) {
int index = text.indexOf(needle);
check(index >= 0, "Missing source fragment: " + needle);
@@ -29,6 +29,7 @@ class InstalledKnowledgeTest {
assertTrue(log.contains("Installed generated animation verified"), log);
assertTrue(log.contains("Installed production contracts verified: 21 compile classifications"), log);
assertTrue(log.contains("Installed generated animation project: zelda-1"), log);
assertTrue(log.contains("Installed Beacon Workshop verified: original resources, hashes, generated factories, compile and pack"), log);
}
@Test void installedCompilerAndSdkCarryTheSameVerifiedCatalog() throws Exception {
@@ -0,0 +1,185 @@
// Test-only guest checks. Installed production sources are copied unchanged;
// this extra module is injected into a disposable project by the process test.
import { AnimationError, PlaybackState } from @core:animation;
import { make_sprite, SpriteView } from @core:sprite;
import { Composer } from @sdk:composer;
import { Random, random } from @sdk:random;
import { Log } from @sdk:log;
fn check(condition: bool) -> void { if !condition { let failure = 1 / 0; } }
fn verify_components(value: Workshop) -> result<AnimationError> bool {
// Independent SDK oracle, without calling the game's layout selection code.
let root_rng = random.new(2026 as long);
let reference = random.new(random.next(root_rng));
let expected_west = random.range(reference, 0 as long, 4 as long) as int;
let expected_east = random.range(reference, 0 as long, 4 as long) as int;
let expected_south = random.range(reference, 0 as long, 4 as long) as int;
check(value.layout.west == expected_west && value.layout.east == expected_east && value.layout.south == expected_south);
Log.info(expected_west, "SDK reference: west");
Log.info(expected_east, "SDK reference: east");
Log.info(expected_south, "SDK reference: south");
let robot = value.robot;
robot.reset()!;
robot.motor.move(1, 1);
check(robot.spatial.x == 64 * 256 + 362 && robot.spatial.y == 256 * 256 + 362);
robot.motor.move(0, 0);
check(!robot.motor.moving && robot.spatial.facing_x == 1 && robot.spatial.facing_y == 1);
robot.spatial.reset(32, 64);
robot.motor.move(-1, -1);
check(robot.spatial.x == 32 * 256 && robot.spatial.y == 64 * 256);
check(robot.spatial.facing_x == -1 && robot.spatial.facing_y == -1);
robot.spatial.reset(256, 144);
robot.motor.move(1, 0);
check(robot.spatial.x == 258 * 256);
for n: int from 0 until 20 { robot.motor.move(1, 0); }
check(robot.spatial.x == 264 * 256);
// The very same robot consumes an AI controller and then the human controller.
robot.reset()!;
robot.move(value.first.controller);
check(robot.spatial.x == 64 * 256 + 362 && robot.spatial.y == 256 * 256 - 362);
robot.move(value.player);
check(robot.spatial.x == 64 * 256 + 362 && !robot.motor.moving);
robot.spatial.facing_x = 1; robot.spatial.facing_y = 0;
check(robot.tool.request(true, robot.spatial)!);
check(robot.tool.starts == 1 && robot.tool.active);
robot.tool.advance()!;
check(!robot.tool.request(true, robot.spatial)! && !robot.tool.pending);
for n: int from 0 until 7 { robot.tool.advance()!; }
check(robot.tool.remaining == 4);
let body_before = robot.visual.animator.sprite().glyph_id;
check(!robot.tool.request(true, robot.spatial)! && robot.tool.pending);
for n: int from 0 until 4 { robot.tool.advance()!; }
check(robot.tool.animator.state() == PlaybackState.Finished);
robot.spatial.facing_x = 0; robot.spatial.facing_y = -1;
check(robot.tool.request(false, robot.spatial)!);
check(robot.tool.starts == 2 && !robot.tool.pending && robot.tool.direction_y == -1);
check(robot.visual.animator.sprite().glyph_id == body_before);
check(!robot.tool.request(false, robot.spatial)!);
robot.tool.cancel();
check(!robot.tool.active && !robot.tool.pending && !robot.tool.request(false, robot.spatial)!);
// A normal body transition advances continuously and does not touch the tool.
robot.reset()!;
robot.spatial.facing_x = 1; robot.spatial.facing_y = 0;
for n: int from 0 until 5 { robot.visual.advance(robot.spatial, true)!; }
check(robot.visual.animator.sprite().glyph_id == 4);
robot.visual.advance(robot.spatial, true)!;
check(robot.visual.animator.sprite().glyph_id == 5);
check(!robot.tool.active && robot.tool.starts == 0);
let drone_before = value.second.animator.sprite().glyph_id;
value.first.animator.advance(6)!;
check(value.second.animator.sprite().glyph_id == drone_before);
// Real error recovery preserves playback, rather than catching a VM trap.
let body = robot.visual.animator;
let glyph = body.sprite().glyph_id;
handle body.advance(-1) { AnimationError.invalid_ticks -> { ok(()) }, _ -> AnimationError.overflow };
check(body.sprite().glyph_id == glyph);
// Start a buffered action, then make contact take priority over its completion.
value.reset()!;
robot.spatial.reset(value.first.spatial.pixel_x(), value.first.spatial.pixel_y());
robot.tool.request(true, robot.spatial)!;
for n: int from 0 until 8 { robot.tool.advance()!; }
robot.tool.request(true, robot.spatial)!;
check(robot.tool.pending);
value.update()!;
check(value.contacts == 1 && robot.spatial.pixel_x() == 64 && robot.spatial.pixel_y() == 256);
check(!robot.tool.active && !robot.tool.pending && !value.first_beacon.lit);
// Multiple emission calls preserve positions, glyphs, playback, requests and events.
value.reset()!;
robot.tool.request(true, robot.spatial)!;
robot.tool.advance()!;
robot.visual.advance(robot.spatial, true)!;
let x = robot.spatial.x; let y = robot.spatial.y;
let remaining = robot.tool.remaining; let starts = robot.tool.starts;
let tool_glyph = robot.tool.animator.sprite().glyph_id;
let body_glyph = robot.visual.animator.sprite().glyph_id;
let first_glyph = value.first.animator.sprite().glyph_id;
let second_glyph = value.second.animator.sprite().glyph_id;
check(render(value)); check(render(value));
check(robot.spatial.x == x && robot.spatial.y == y && robot.tool.remaining == remaining);
check(robot.tool.starts == starts && robot.tool.animator.sprite().glyph_id == tool_glyph);
check(value.first.animator.sprite().glyph_id == first_glyph && !value.first_beacon.lit);
check(value.second.animator.sprite().glyph_id == second_glyph);
check(robot.visual.animator.sprite().glyph_id == body_glyph);
check(robot.tool.animator.state() == PlaybackState.Playing && !robot.tool.pending);
// Check the exact next boundaries: equal glyphs alone could hide phase drift.
robot.tool.animator.advance(2)!;
check(robot.tool.animator.sprite().glyph_id == tool_glyph);
robot.tool.animator.advance(1)!;
check(robot.tool.animator.sprite().glyph_id != tool_glyph);
robot.visual.animator.advance(4)!;
check(robot.visual.animator.sprite().glyph_id == body_glyph);
robot.visual.animator.advance(1)!;
check(robot.visual.animator.sprite().glyph_id != body_glyph);
value.first.animator.advance(5)!;
check(value.first.animator.sprite().glyph_id == first_glyph);
value.first.animator.advance(1)!;
check(value.first.animator.sprite().glyph_id != first_glyph);
// Invalid numeric bank/glyph identifiers can be valid Sprite values but fail emission.
let invalid = handle make_sprite(255, 65535) { _ -> AnimationError.invalid_glyph };
let image = invalid.sprite();
check(Composer.emit_sprite(image.glyph_id, 0, 32, 64, 1, image.bank_id, false, false, 0) != 0);
// A deliberately blocked connection returns along the last known leg.
robot.spatial.reset(264, 112);
let stuck = new PatrolController(random.new(7 as long), 8, 3, 1, 0, false, 264, 112);
for n: int from 0 until 32 {
let command = stuck.intent(robot.spatial.pixel_x(), robot.spatial.pixel_y());
robot.motor.move(command.move_x, command.move_y);
}
check(stuck.recovering && stuck.target == 8 && robot.spatial.x < 264 * 256);
value.reset()!;
check(robot.tool.starts == 0 && value.contacts == 0 && !value.won);
check(!value.first_beacon.lit && !value.second_beacon.lit && !value.third_beacon.lit);
return ok(true);
}
// One bounded batch per guest frame: eight seeds, eight successive matches each.
declare global first_seed_code: int = -1;
declare global seed_diversity: bool = false;
declare global first_vertical: bool = false;
declare global first_diagonal: bool = false;
declare global second_vertical: bool = false;
declare global second_diagonal: bool = false;
fn verify_variation(value: Workshop, trial: int) -> void {
if trial < 64 {
let seed = (trial / 8) as long;
let a = new BeaconLayout(random.new(seed), -1, -1, -1);
let b = new BeaconLayout(random.new(seed), -1, -1, -1);
for n: int from 0 until trial % 8 + 1 {
let west = a.west; let east = a.east; let south = a.south;
a.next(); b.next();
check(a.west != west || a.east != east || a.south != south);
check(a.west == b.west && a.east == b.east && a.south == b.south);
}
check(a.valid());
if trial % 8 == 0 {
let code = a.west * 16 + a.east * 4 + a.south;
if trial == 0 { first_seed_code = code; }
else if code != first_seed_code { seed_diversity = true; }
}
if trial == 63 { check(seed_diversity); }
// Advancing one stream does not mutate the independent copy.
let west = b.west; let east = b.east; let south = b.south;
a.next();
check(b.west == west && b.east == east && b.south == south);
}
check(clear_position(value.first.spatial.x, value.first.spatial.y));
check(clear_position(value.second.spatial.x, value.second.spatial.y));
check(!touches(value.robot.spatial, value.first.spatial) && !touches(value.robot.spatial, value.second.spatial));
if value.first.spatial.pixel_y() != route_y(0) { first_vertical = true; }
if value.second.spatial.pixel_y() != route_y(4) { second_vertical = true; }
if value.first.motor.moving && value.first.spatial.facing_x != 0 && value.first.spatial.facing_y != 0 { first_diagonal = true; }
if value.second.motor.moving && value.second.spatial.facing_x != 0 && value.second.spatial.facing_y != 0 { second_diagonal = true; }
if trial == 511 {
check(first_vertical && first_diagonal && second_vertical && second_diagonal);
}
}
@@ -14,10 +14,17 @@ dependencies {
// Build-time projection of owner-maintained sources; no second normative copy is edited by Studio.
val pbsSpecs = rootProject.layout.projectDirectory.dir("docs/specs/compiler-languages/pbs")
val pbsResources = layout.projectDirectory.dir("src/main/resources")
val beaconWorkshop = rootProject.layout.projectDirectory.dir("test-projects/beacon-workshop")
val beaconFiles = fileTree(beaconWorkshop) {
include("src/**", "assets/**", "tools/*.py", "*.md", "prometeu.json", ".gitignore")
exclude("**/__pycache__/**")
}
val generatePbsKnowledge by tasks.registering(Sync::class) {
from(pbsSpecs) { include("*.md"); into("pbs-knowledge/specs") }
from(beaconFiles) { into("pbs-knowledge/examples/game/1/beacon-workshop") }
into(layout.buildDirectory.dir("generated/pbsKnowledge"))
inputs.files(fileTree(pbsResources) { include("game/stdlib/**/*.pbs", "game/stdlib/**/*.barrel", "pbs-knowledge/examples/**") })
inputs.files(beaconFiles)
doLast {
val entries = mutableListOf<Map<String, Any?>>()
fun entry(id: String, title: String, kind: String, resource: String, source: File, sdk: Int? = null, target: String? = null) {
@@ -72,6 +79,23 @@ val generatePbsKnowledge by tasks.registering(Sync::class) {
entry("pbs:example:game:1:$relative", "PBS Game / SDK 1 example: $relative", "EXAMPLE",
"pbs-knowledge/examples/game/1/$relative", source, 1, "Game")
}
// Binary glyphs travel as resources, never as UTF-8 reference payloads.
val distributed = beaconFiles.files.sorted().map { source ->
val relative = source.relativeTo(beaconWorkshop.asFile).invariantSeparatorsPath
val resource = "pbs-knowledge/examples/game/1/beacon-workshop/$relative"
if (source.extension != "png") {
entry("pbs:example:game:1:beacon-workshop/$relative", "Beacon Workshop / $relative",
"EXAMPLE", resource, source, 1, "Game")
}
mapOf("path" to relative, "resource" to resource,
"sha256" to MessageDigest.getInstance("SHA-256").digest(source.readBytes())
.joinToString("") { "%02x".format(it) })
}
val inventory = destinationDir.resolve("pbs-knowledge/examples/game/1/beacon-workshop/distribution.json")
inventory.writeText(groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(
mapOf("schemaVersion" to 1, "files" to distributed))))
entry("pbs:example:game:1:beacon-workshop/distribution.json", "Beacon Workshop / packaged files",
"EXAMPLE", "pbs-knowledge/examples/game/1/beacon-workshop/distribution.json", inventory, 1, "Game")
check(entries.map { it["id"] }.distinct().size == entries.size) { "Duplicate PBS reference IDs" }
destinationDir.resolve("pbs-knowledge/index.json").writeText(groovy.json.JsonOutput.prettyPrint(
groovy.json.JsonOutput.toJson(mapOf("schemaVersion" to 1, "owner" to "pbs", "references" to entries))))
@@ -40,7 +40,7 @@ final class PbsExecutableMetadataIndexFactory {
}
final var importedGlobalsBySlot = PbsImportedGlobalSlots.index(ownedNames, importedGlobals);
importedGlobalsBySlot.forEach((slot,global) -> globalSlotByNameId.put(nameTable.register(global.localName()),slot));
final var constDeclByNameId = indexConstDecls(ast, nameTable);
final var constDeclByNameId = indexConstDecls(ast, supplementalTopDecls, nameTable);
final var addressableByAddress = indexAddressables(feSurfaceContext);
final var builtinSignatureByOwnerAndMethod = indexBuiltinSignatures(
ast,
@@ -132,9 +132,14 @@ final class PbsExecutableMetadataIndexFactory {
private Map<NameId, PbsAst.ConstDecl> indexConstDecls(
final PbsAst.File ast,
final ReadOnlyList<PbsAst.TopDecl> supplementalTopDecls,
final NameTable nameTable) {
final var constDeclByNameId = new HashMap<NameId, PbsAst.ConstDecl>();
for (final var topDecl : ast.topDecls()) {
// Semantic admission already filters sibling/imported declarations. They
// need the same executable values as locally declared constants.
final var declarations = new ArrayList<>(ast.topDecls().asList());
declarations.addAll(supplementalTopDecls.asList());
for (final var topDecl : declarations) {
if (!(topDecl instanceof PbsAst.ConstDecl constDecl)) {
continue;
}
@@ -22,17 +22,72 @@ For bank UUID `12345678-1234-1234-1234-123456789abc` and animator ID `hero`:
```pbs
import { create_hero } from @app:generated/animations/b_12345678123412341234123456789abc;
import { AnimationError } from @core:animation;
fn render() -> result<AnimationError> {
import { Animator, AnimationError } from @core:animation;
import { Composer } from @sdk:composer;
import { Log } from @sdk:log;
declare struct HeroSlot(pub mut value: optional Animator) {
ctor make() { this.value = none; }
}
declare global hero: HeroSlot = new HeroSlot.make();
declare global animation_failed: bool = false;
fn initialize_hero() -> result<AnimationError> {
let value = create_hero(3)!;
value.play("idle")!;
value.advance(2)!;
let image = value.sprite();
// Supply image.bank_id/image.glyph_id to the existing nine-argument Composer API.
hero.value = some(value);
return ok(());
}
fn recover_initialization() -> result<AnimationError> {
handle initialize_hero() { _ -> {
animation_failed = true;
Log.failure("Unable to initialize hero animation");
ok(())
} };
return ok(());
}
fn recover_frame() -> result<AnimationError> {
if animation_failed { return ok(()); }
if let value = hero.value {
handle value.advance(1) { _ -> {
animation_failed = true;
Log.failure("Unable to advance hero animation");
ok(())
} };
if animation_failed { return ok(()); }
// Scene binding and bank-slot preload belong to project setup.
let image = value.sprite();
if Composer.emit_sprite(image.glyph_id, 0, 32, 32, 1,
image.bank_id, false, false, 0) != 0 {
animation_failed = true;
Log.failure("Unable to emit hero sprite");
}
}
return ok(());
}
[Init] fn init() -> void { recover_initialization(); }
[Frame] fn frame() -> void { recover_frame(); }
```
PBS requires `handle` inside a result-returning callable. The two recovery helpers
consume every domain error and always return `ok`; the required `void` hooks discard
only that already-recovered result. Do not discard a raw factory/update result or
try to propagate it from a `void` hook. The directly constructed holder avoids a
procedural factory or `none` expression in a global initializer.
The example above illustrates lifetime and error handling for the named authored
bank; it does not supply that bank or a complete scene. Construct once, retain the
same instance, advance explicitly during update and query its current sprite during
drawing. Change action clips only on transitions. Repeating a draw must not advance
time, and repeating `play` each frame restarts the animation.
For a complete project with original assets, input, composed body/tool animation,
two independent autonomous actors and a play/win/restart loop, use **Beacon Workshop**.
Its installed reference prefix is `pbs:example:game:1:beacon-workshop/`; start with
`README.md` and `distribution.json`. Its canonical editable source is Studio's
`test-projects/beacon-workshop`. The build projects that source into the installed
corpus, including the registered banks and authored animation definitions.
The virtual module is reproducible and read-only. Its CodeLens opens the original
JSON field in Studio. A changed definition invalidates older source revisions;
navigate again to obtain the current definition. Existing projects without a
@@ -60,6 +60,22 @@ class PbsProductionLoweringRegressionTest {
"""));
assertFalse(result.diagnostics().hasErrors(), result.diagnostics().asCollection().toString());
}
@Test void admittedSiblingConstantsAreMaterializedInCallsAndArithmetic() throws Exception {
var result=compile(Map.of(
"src/mod.barrel", "pub fn frame() -> void; mod const HOME_X; mod const HOME_Y; mod const SCALE;",
"src/settings.pbs", "declare const HOME_X:int=64; declare const HOME_Y:int=256; declare const SCALE:int=256;",
"src/main.pbs", """
declare struct Position(pub mut x:int,pub mut y:int) {
fn reset(x:int,y:int)->void { this.x=x*SCALE; this.y=y*SCALE; }
}
declare global position:Position=new Position(0,0);
[Frame] fn frame()->void {
position.reset(HOME_X,HOME_Y);
if position.x!=16384 || position.y!=65536 { let failure=1/0; }
}
"""));
assertFalse(result.diagnostics().hasErrors(),result.diagnostics().asCollection().toString());
}
record Compiled(IRBackend backend, DiagnosticSink diagnostics) {}
Compiled compile(Map<String,String> sources) throws Exception {
root=root.toRealPath(); var projects=new ProjectTable();var files=new FileTable(1);
+3
View File
@@ -0,0 +1,3 @@
/build/
/.studio/
__pycache__/
+157
View File
@@ -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"
}
}
File diff suppressed because it is too large Load Diff
@@ -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"
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

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"))