Skip to main content

mms_module_example/
mms-module-example.rs

1/// mms-module-example: visual demo for MMS Phase 6 (module import / export).
2///
3/// Loads mms-module-example.mms which in turn imports cat.mms via
4/// `import { 0 as cat } from "cat.mms"`. Demonstrates cross-file CE import
5/// and Positional(ComponentExpr) → Child promotion inside a parent CE body.
6///
7/// Run from the repo root so relative paths resolve correctly:
8///   cargo run --example mms-module-example
9///
10/// Use WASD/RF/QE + right-mouse drag to navigate.
11use mittens_engine::{engine, engine::ecs::SignalEmitter, scripting, utils};
12
13#[path = "example_util/mod.rs"]
14mod example_util;
15
16fn main() {
17    mittens_engine::example_support::ensure_model_assets();
18    utils::logger::init();
19
20    // eval_file passes the path so `import "cat.mms"` resolves relative to
21    // examples/ — do NOT use include_str! here (that loses the path).
22    let output = scripting::MeowMeowRunner::eval_file("examples/mms-module-example.mms");
23
24    for error in &output.errors {
25        eprintln!("[mms] error: {error}");
26    }
27    assert!(
28        output.errors.is_empty(),
29        "MMS evaluation produced errors: {:?}",
30        output.errors,
31    );
32
33    println!("[mms] {} intent(s):", output.intents.len());
34    for intent in &output.intents {
35        if let engine::ecs::IntentValue::SpawnComponentTree { root, .. } = intent {
36            println!("  spawn {}", root.component_type);
37        }
38    }
39
40    let world = engine::ecs::World::default();
41    let mut universe = engine::Universe::new(world);
42
43    let scope = engine::ecs::ComponentId::default();
44    for intent in output.intents {
45        universe.command_queue.push_intent_now(scope, intent);
46    }
47
48    // Camera placed to see the cat from slightly above and in front.
49    example_util::spawn_mms_demo_rig(&mut universe, [0.0, 1.2, 4.5]);
50
51    universe.systems.process_commands(
52        &mut universe.world,
53        &mut universe.visuals,
54        &mut universe.render_assets,
55        &mut universe.command_queue,
56    );
57
58    engine::Windowing::run_app(universe).expect("Windowing failed");
59}