//! The [`ScriptModule`] — the Stage-10 entry point that wires scripting into an //! [`App`]. //! //! Following the engine's module convention, everything the scripting layer //! contributes is registered here so it can be enabled, disabled, or removed as //! a unit (and so an exported game that uses no scripts never compiles them in). //! This first piece registers the [`Script`] component *type* for reflection //! (making it dual-editable and captured by the play-mode snapshot), installs //! the `.rhai` [`ScriptLoader`], and inserts the shared [`ScriptEngine`]. The //! lifecycle system that compiles and runs scripts each frame is added in a //! later piece. use oxide_engine::app::{App, Module, Schedule}; use crate::host::run_scripts; use crate::{Script, ScriptHost, ScriptLoader}; /// The scripting module. Add it after [`DefaultModules`] to give an app a /// `rhai`-backed scripting layer. /// /// [`DefaultModules`]: oxide_engine::app::DefaultModules /// /// ``` /// use oxide_engine::app::App; /// use oxide_script::ScriptModule; /// /// let mut app = App::new(); /// app.add_module(ScriptModule); /// assert!(app.has_module("script")); /// assert!(app.types.is_registered("Script")); /// ``` pub struct ScriptModule; impl Module for ScriptModule { fn name(&self) -> &'static str { "script" } fn build(&self, app: &mut App) { // Register the component type for reflection so it round-trips through // RON (scripts/AI/inspector) and is captured by the play-mode snapshot. app.register_type::