README.md

Microslices #

A microslice is a small, independent wasm build in which one gameplay loop is the whole game. It calls the same rules the main game does, so tuning it tunes the game. See the Microslices section of AGENTS.md.

kit/ is the shared kit: the Bevy app, the terminal at physical resolution, key input, the palette and the noosphere theme. The main game draws through the same terminal.

Build and serve #

scripts/microslice.sh --all
scripts/microslice-serve.sh          # http://127.0.0.1:4040/

scripts/microslice.sh <name> builds one slice into output/microslices/<name>/. --all builds every slice and writes output/microslices/index.html. Serve the directory over ssh -L 4040:127.0.0.1:4040 to open it from another machine.

The bundles are release builds of wasm32-unknown-unknown with wasm-bindgen. Run scripts/fetch-fonts.sh first; the kit embeds the terminal faces.

Add a slice #

  1. Make crates/microslice/<name>/ with a package named protokill_microslice_<name> and add it to the workspace members.
  2. Depend on the rules crates the loop needs. Never depend on protokill_wasm_frontend.
  3. Depend on protokill_microslice_kit under [target.'cfg(target_arch = "wasm32")'.dependencies], and keep the rules state in the library so a native test can drive it.
  4. Implement the kit's slice and start it from the binary:
use protokill_microslice_kit::{Input, KeyCode, Microslice, ratatui::Frame};

pub struct MySlice { /* state */ }

impl Microslice for MySlice {
    const TITLE: &'static str = "My slice";
    const CONTROLS: &'static str = "Up/Down move | Enter choose";
    const HELP: &'static str = "What the loop is and how the controls work.";

    fn new(seed: u64) -> Self { /* seeded start */ }

    fn update(&mut self, input: &Input) {
        for press in input.presses() {
            if press.key == KeyCode::Enter {
                /* act */
            }
        }
    }

    fn draw(&self, frame: &mut Frame) { /* draw */ }
}

fn main() {
    protokill_microslice_kit::run::<MySlice>();
}

The kit prompts for the seed on screen, shows it beside the controls, draws CONTROLS in the last row and opens HELP on ?. Leave the last row free. Keep floats out of game state; render-only maths is fine.