Skip to main content

lotus_script/
lib.rs

1//! High-Level-API für LOTUS-Simulator-Scripts (WebAssembly).
2//!
3//! High-level API for LOTUS simulator scripts (WebAssembly).
4//!
5//! # Einstieg / Getting started
6//!
7//! Als Script-Autor reicht die Abhängigkeit `lotussim-script`. Im Rust-Code heißt das Crate
8//! `lotus_script`.
9//!
10//! As a script author, depend only on `lotussim-script`. In Rust code the crate is named
11//! `lotus_script`.
12//!
13//! ```toml
14//! [dependencies]
15//! lotussim-script = "0.8"
16//! ```
17//!
18//! Scripts werden nach `wasm32-unknown-unknown` gebaut und laufen in der LOTUS-Scriptengine.
19//! Der mit [`script!`] registrierte Typ muss [`Default`] implementieren.
20//!
21//! Scripts are compiled for `wasm32-unknown-unknown` and run inside the LOTUS script engine.
22//! The type registered with [`script!`] must implement [`Default`].
23//!
24//! ```no_run
25//! # #[cfg(target_arch = "wasm32")]
26//! # {
27//! use lotus_script::prelude::*;
28//!
29//! #[derive(Default)]
30//! struct MyScript;
31//!
32//! impl Script for MyScript {
33//!     fn tick(&mut self) {}
34//! }
35//!
36//! script!(MyScript);
37//! # }
38//! ```
39//!
40//! # Hilfe / Help
41//!
42//! - Offline-Hilfe im LOTUS-Simulator / in-game offline help of the LOTUS simulator
43//! - [LOTUS-Forum](https://www.lotus-simulator.de/forum/)
44//! - Repository-README / repository README
45//!
46//! # Features
47//!
48//! - `time`: zusätzliche Zeitumrechnungen über die `time`-Crate / extra time conversions via the `time` crate
49//! - `internal`: Schnittstellen für die Simulator-Engine, nicht für Addon-Scripts / APIs for the simulator engine, not for addon scripts
50
51#[doc(hidden)]
52pub use lotus_bindgen_macros::lotus_bindgen;
53
54use message::Message;
55
56pub mod action;
57pub mod content;
58#[doc(hidden)]
59pub mod event;
60pub mod font;
61pub mod gizmos;
62#[doc(hidden)]
63pub mod global_vars;
64pub mod graphics;
65pub mod input;
66pub mod log;
67#[doc(hidden)]
68pub mod macros;
69pub mod math;
70pub mod message;
71pub mod module;
72pub mod public_vars;
73pub mod rand;
74#[doc(hidden)]
75pub mod settings;
76pub mod time;
77pub mod var;
78pub mod vehicle;
79/// PIS-Daten und Abfragefunktionen.
80///
81/// PIS data and query functions.
82pub mod pis {
83    pub use lotus_shared::pis::*;
84}
85
86/// Häufig genutzte Typen und Makros für Script-Implementierungen.
87///
88/// Commonly used types and macros for script implementations.
89pub mod prelude {
90    pub use crate::{
91        action,
92        graphics::{textures::Texture, Color},
93        log,
94        message::{message_type, send_message, Message, MessageTarget, MessageType},
95        rand, script, time,
96        var::{get_var, set_var, VariableType},
97        vehicle, Script,
98    };
99}
100pub use lotus_shared::animation::*;
101
102/// Haupt-Trait für LOTUS-Script-Implementierungen.
103///
104/// Main trait for LOTUS script implementations.
105pub trait Script {
106    /// Wird einmal beim Laden des Scripts aufgerufen.
107    ///
108    /// Called once when the script is loaded.
109    fn init(&mut self) {}
110
111    /// Registriert Eingabeaktionen; Standard: leere Liste.
112    ///
113    /// Registers input actions; defaults to an empty list.
114    fn actions() -> Vec<action::RegisterAction> {
115        Default::default()
116    }
117
118    /// Wird pro Simulations-Tick aufgerufen.
119    ///
120    /// Called once per simulation tick.
121    fn tick(&mut self) {}
122
123    /// Verarbeitet eine eingehende Nachricht.
124    ///
125    /// Handles an incoming message.
126    #[allow(unused_variables)]
127    fn on_message(&mut self, msg: Message) {}
128}
129
130/// Gibt `true` zurück, wenn das scriptbehaftete Objekt ferngesteuert ist.
131///
132/// Returns `true` if the object the script is attached to is remote controlled.
133pub fn is_rc() -> bool {
134    unsafe { lotus_script_sys::env::is_rc() }
135}