Skip to main content

component_method_call/
component-method-call.rs

1/// Component method call demo.
2///
3/// Loads component-method-call.mms, which authors the scene and wires signal
4/// handlers that call `anim.pause()` and `anim.play()` on a live AnimationComponent.
5///
6/// Click the blue cube  → pause the spinning animation.
7/// Click the green cube → resume the spinning animation.
8///
9/// Run: cargo run --release --example component-method-call
10use mittens_engine::{engine, engine::ecs::SignalEmitter, scripting, utils};
11
12fn main() {
13    mittens_engine::example_support::ensure_model_assets();
14    utils::logger::init();
15
16    let world = engine::ecs::World::default();
17    let mut universe = engine::Universe::new(world);
18
19    let source = include_str!("component-method-call.mms");
20    let output = scripting::MeowMeowRunner::eval_with_world(
21        source,
22        &mut universe.world,
23        &mut universe.systems.rx,
24        &mut universe.command_queue,
25    );
26
27    for err in &output.errors {
28        eprintln!("[mms] {err}");
29    }
30    if !output.errors.is_empty() {
31        std::process::exit(1);
32    }
33
34    for intent in output.intents {
35        universe
36            .command_queue
37            .push_intent_now(engine::ecs::ComponentId::default(), intent);
38    }
39
40    universe.systems.process_commands(
41        &mut universe.world,
42        &mut universe.visuals,
43        &mut universe.render_assets,
44        &mut universe.command_queue,
45    );
46
47    universe.enable_repl();
48    engine::Windowing::run_app(universe).expect("Windowing failed");
49}