dotzuki_engine_script/lib.rs
1//! dotzuki-engine-script — an async JavaScript scripting engine (Boa-based) for games.
2//!
3//! Provides an async/await-based scripting system using Boa (a pure-Rust JS engine)
4//! that replaces the hardcoded ScriptAction queue. Map scripts are written in
5//! JavaScript and can `await` game operations like showText(), moveNpc(), etc.
6//!
7//! # Architecture
8//!
9//! ```text
10//! JS Script (async fn)
11//! │
12//! ├─ await game.showText("...") ──► ScriptCommand::ShowText
13//! │ ↑ Rust resolves promise when text dismissed
14//! │
15//! ├─ game.getFlag("GOT_STARTER") ──► synchronous bool return
16//! │
17//! └─ await game.startBattle("RIVAL") ──► ScriptCommand::StartBattle
18//! ↑ Rust resolves promise with battle result
19//! ```
20//!
21//! The game loop calls `ScriptEngine::tick()` each frame:
22//! 1. If a pending command was resolved by Rust, `run_jobs()` drains the JS
23//! microtask queue so the async function continues to its next `await`.
24//! 2. If the script issues a new command, it's returned to the caller for dispatch.
25//! 3. If no script is active, returns `None`.
26
27pub mod api_registrar;
28pub mod command;
29pub mod config;
30pub mod cutscene;
31pub mod engine;
32pub mod game_api;
33pub mod loader;
34
35#[cfg(feature = "embedded-scripts")]
36mod embedded_scripts {
37 include!(concat!(env!("OUT_DIR"), "/embedded_scripts.rs"));
38}
39
40#[cfg(test)]
41mod tests;
42
43pub use api_registrar::ScriptApiRegistrar;
44pub use command::{CommandResult, ScriptCommand};
45pub use config::MapScriptConfig;
46pub use cutscene::CutsceneManager;
47pub use engine::{BridgeView, ScriptEngine, ScriptEngineError};
48pub use loader::{ScriptLoader, ScriptLoaderError};