From pebble to empire. Every world remembers.
A 4X colony simulation where you begin Dwarf-Fortress-style on a single planet and end commanding a galactic civilizationβbut every world is still simulating underneath.
Pre-Alpha β AI agents are building this game.
cargo run --bin scale --features native
cargo test --features native
cargo criterion# Install prerequisites
rustup target add wasm32-unknown-unknown
cargo install --locked trunk
# Serve locally at http://localhost:8080
trunk serve.\install-hooks.ps1 # Windows
./install-hooks.sh # Linux/MacTo use SCALE's procedural generation in your own Rust code:
// In Cargo.toml:
// [dependencies]
// scale = "0.1.0"
// anyhow = "1.0"
use scale::prelude::*;
fn main() -> anyhow::Result<()> {
// 1. Initialize Generator (loads embedded lore by default)
let generator = NarrativeGenerator::from_embedded();
// Or load from a directory (must contain TEMPLATES.md and FRAGMENTS.md)
// let mut generator = NarrativeGenerator::default();
// generator.load_from_files("./lore")?;
// 2. Prepare Context
let mut context = NarrativeContext::default();
context.insert("CIV_NAME", "Terran Dominion");
// Note: If required context variables are missing, `generate` will return an error.
context.insert("ORIGIN_STAR", "Sol Prime");
context.insert("YEAR", "2150");
context.insert("CIV_EPITHET", "The First Ones");
// 3. Generate Story
let story = generator.generate("CIVILIZATION_RISE", &context)?;
println!("{}", story);
Ok(())
}See examples/narrative_demo.rs for a complete example.
Note: This is the base narrative system (mad-libs style text generation). It is available in the default build. For the advanced simulation of legends (Oral Tradition), see the Oral Tradition section below.
The "Nova" feature (Oral Tradition) builds upon the base narrative system to create living legends that evolve in taverns. It is located in scale::layer1::oral_tradition.
STOP! If you copy-paste the code below without enabling the
novafeature, it will NOT compile!To use this feature, you MUST enable the
novafeature flag in yourCargo.tomlor via the command line.If you see an error like
cannot find struct, variant or union type Story in this scope, it means you forgot thenovafeature!
Usage:
Run with:
cargo run --features nova
// In Cargo.toml:
// [dependencies]
// scale = { version = "0.1.0", features = ["nova"] }
use scale::prelude::*;
fn main() {
let mut tradition = OralTradition::default();
// Add a story directly to the tradition
let story = Story {
text: "The colony survived the Great Frost.".to_string(),
historical_date: 100,
mutations: 0,
genre: StoryGenre::Heroic,
};
tradition.add_story(story);
// Inspect
println!("{:?}", tradition.stories);
}Running the Demos:
# Minimal API usage
cargo run --features nova --example minimal_nova_demo
# Full Interactive TUI Demo
cargo run --features nova --example oral_tradition_demoTo run the full simulation loop without a window or GPU (e.g. for servers or AI training):
use scale::prelude::*;
fn main() {
// 1. Setup the world with headless configuration
let config = SetupConfig {
headless: true,
..Default::default()
};
let mut world = setup_world_with_config(config);
// 2. Run a few ticks
for _ in 0..10 {
run_simulation_tick(&mut world);
}
// 3. Inspect state
let time = world.resource::<SimulationTime>();
println!("Current Tick: {}", time.tick);
}See examples/headless_demo.rs for a complete example.
| Key | Action |
|---|---|
| WASD / Arrows | Scroll map (or move cursor in build mode) |
| Space | Pause/unpause |
| 1/2/3 | Speed (1x/3x/5x) |
| B | Toggle build mode |
| M | Toggle mine designation mode |
| X | Toggle demolish designation mode |
| Tab | Cycle building type (in build mode) |
| Enter | Place building / confirm |
| L | Toggle chronicle overlay |
| Escape | Exit current mode / close overlay |
| Q | Quit |
| Mouse click | Select entity or tile |
Terrain: , grass . dirt # rock ~ water ^ tree
Pops: @ idle/moving
Buildings: H housing F farm S stockpile T tavern
Three simulation layers, each abstracting the one below:
- Colony (Dwarf Fortress) β Individual pops, buildings, needs, jobs
- System (Planetary) β Planets as nodes, ships, orbital stations
- Galaxy (Stellaris) β Star systems, civilizations, diplomacy
Tech stack: Rust, bevy_ecs for simulation, ratatui for UI, ratzilla for browser support.
Runs natively in a terminal via crossterm, or in any browser via WASM + Ratzilla's DOM backend. Both targets share identical game logic β only the input translation and render backend differ.
See DESIGN.md for full architecture details and docs/adr/ for architecture decision records.
Every playthrough generates unique lore:
- Pre-history: 500+ years of galactic events generated at game start
- Chronicle: Ongoing events recorded as you play
- Discovery: Find artifacts, ruins, and legends with generated backstories
See lore/ for the building blocks.
scale/
βββ src/
β βββ main.rs # Native entry point (crossterm)
β βββ lib.rs # Library exports
β βββ bin/
β β βββ wasm_app.rs # WASM entry point (ratzilla)
β β βββ headless.rs # Headless simulation runner
β βββ platform/ # Input abstraction (native β wasm)
β βββ setup.rs # Shared world initialization
β βββ simulation.rs # Shared simulation tick
β βββ layer1/ # Colony simulation (pops, buildings, needs, AI)
β βββ shared/ # Input routing, selection, time, narrative
β βββ ui/ # Terminal UI rendering (backend-agnostic)
βββ web/ # Trunk HTML entry point for WASM
βββ e2e/ # Playwright E2E browser tests
βββ specs/ # Feature specifications
βββ lore/ # Procedural lore system
βββ design/ # Design docs and task tracking
βββ docs/ # Architecture documentation + ADRs
βββ benches/ # Performance benchmarks
βββ prompts/ # AI agent prompts
Language: Rust Edition 2024
Dependencies:
bevy_ecsβ Entity Component System for simulationratatuiβ Terminal UI framework (backend-agnostic)crosstermβ Native terminal backend (optional,nativefeature)ratzillaβ Browser WASM backend (optional,wasmfeature)anyhowβ Error handlingrandβ Random generationcriterionβ Benchmarking (dev)
Feature flags:
native(default) β Terminal mode via crosstermwasmβ Browser mode via ratzilla
Profiles:
devβ Optimized for fast iteration (opt-level = 1)releaseβ Fully optimized (LTO, single codegen unit)benchβ Inherits from release
- Format + Clippy (pedantic + nursery) + Tests + Coverage (native)
- WASM Build via Trunk
- E2E Tests via Playwright against the WASM build
- 85%+ test coverage enforced
See CI-SETUP.md for full CI/CD documentation.
This project is built by AI agents coordinating through git. See AGENTS.md for the protocol.
See docs/guides/EXTENDING.md for a guide on adding new buildings.
Follow the existing spec-driven workflow and ensure all changes pass CI quality gates.
MIT