|
|
|
import init, {
|
|
|
|
World,
|
|
|
|
Pane,
|
|
|
|
FullTile,
|
|
|
|
Signal,
|
|
|
|
available_tiles,
|
|
|
|
} from "/stackline-wasm/pkg/stackline_wasm.js";
|
|
|
|
|
|
|
|
import * as canvas from "./canvas.js";
|
|
|
|
import * as inspect from "./inspect.js";
|
|
|
|
|
|
|
|
let promises = [];
|
|
|
|
promises.push(init());
|
|
|
|
|
|
|
|
let font = new FontFace("Stackline Classic", "url(\"/font/StacklineClassic-Medium.otf\")");
|
|
|
|
promises.push(font.load());
|
|
|
|
await Promise.all(promises);
|
|
|
|
|
|
|
|
font = await font.loaded;
|
|
|
|
document.fonts.add(font);
|
|
|
|
|
|
|
|
export let world = World.deserialize(await (await fetch("/stackline/tests/other/prime.json")).json());
|
|
|
|
world.init();
|
|
|
|
|
|
|
|
let tile = world.get(4, 0);
|
|
|
|
tile.signal = new Signal();
|
|
|
|
tile.state = "Active";
|
|
|
|
world.set(4, 0, tile);
|
|
|
|
|
|
|
|
console.log(world.toString());
|
|
|
|
console.log(world.serialize());
|
|
|
|
|
|
|
|
export let selected = null;
|
|
|
|
export function select(x, y) {
|
|
|
|
selected = [x, y];
|
|
|
|
inspect.update_selected(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
export let running = null;
|
|
|
|
|
|
|
|
export function step() {
|
|
|
|
world.init();
|
|
|
|
world.step();
|
|
|
|
|
|
|
|
if (selected) {
|
|
|
|
inspect.update_selected(selected[0], selected[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function play() {
|
|
|
|
world.init();
|
|
|
|
running = setInterval(() => {
|
|
|
|
world.step();
|
|
|
|
if (selected) {
|
|
|
|
inspect.update_selected(selected[0], selected[1]);
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function pause() {
|
|
|
|
clearInterval(running);
|
|
|
|
running = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas.init();
|
|
|
|
inspect.init();
|