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 init(&mut self) {}
34//!
35//!     fn tick(&mut self) {}
36//!
37//!     fn on_message(&mut self, msg: Message) {}
38//! }
39//!
40//! script!(MyScript);
41//! # }
42//! ```
43//!
44//! # Hilfe / Help
45//!
46//! - Offline-Hilfe im LOTUS-Simulator / in-game offline help of the LOTUS simulator
47//! - [LOTUS-Forum](https://www.lotus-simulator.de/forum/)
48//! - Repository-README / repository README
49//!
50//! # Features
51//!
52//! - `time`: zusätzliche Zeitumrechnungen über die `time`-Crate / extra time conversions via the `time` crate
53//! - `internal`: Schnittstellen für die Simulator-Engine, nicht für Addon-Scripts / APIs for the simulator engine, not for addon scripts
54
55#[doc(hidden)]
56pub use lotus_bindgen_macros::lotus_bindgen;
57
58use message::Message;
59
60pub mod action;
61pub mod content;
62#[doc(hidden)]
63pub mod event;
64pub mod font;
65pub mod gizmos;
66#[doc(hidden)]
67pub mod global_vars;
68pub mod graphics;
69pub mod input;
70pub mod log;
71#[doc(hidden)]
72pub mod macros;
73pub mod math;
74pub mod message;
75pub mod module;
76pub mod public_vars;
77pub mod rand;
78#[doc(hidden)]
79pub mod settings;
80pub mod time;
81pub mod var;
82pub mod vehicle;
83/// PIS-Daten und Abfragefunktionen.
84///
85/// PIS data and query functions.
86pub mod pis {
87    pub use lotus_shared::pis::*;
88}
89
90/// Häufig genutzte Typen und Makros für Script-Implementierungen.
91///
92/// Commonly used types and macros for script implementations.
93pub mod prelude {
94    pub use crate::{
95        action,
96        graphics::{textures::Texture, Color},
97        log,
98        message::{message_type, send_message, Message, MessageTarget, MessageType},
99        rand, script, time,
100        var::{get_var, set_var, VariableType},
101        vehicle, Script,
102    };
103}
104pub use lotus_shared::animation::*;
105
106/// Haupt-Trait für LOTUS-Script-Implementierungen.
107///
108/// Main trait for LOTUS script implementations.
109pub trait Script {
110    /// Wird einmal beim Laden des Scripts aufgerufen.
111    ///
112    /// Called once when the script is loaded.
113    fn init(&mut self) {}
114
115    /// Registriert Eingabeaktionen; Standard: leere Liste.
116    ///
117    /// Registers input actions; defaults to an empty list.
118    fn actions() -> Vec<action::RegisterAction> {
119        Default::default()
120    }
121
122    /// Wird pro Simulations-Tick aufgerufen.
123    ///
124    /// Called once per simulation tick.
125    fn tick(&mut self) {}
126
127    /// Verarbeitet eine eingehende Nachricht.
128    ///
129    /// Handles an incoming message.
130    #[allow(unused_variables)]
131    fn on_message(&mut self, msg: Message) {}
132}
133
134/// Gibt `true` zurück, wenn das scriptbehaftete Objekt ferngesteuert ist.
135///
136/// Returns `true` if the object the script is attached to is remote controlled.
137pub fn is_rc() -> bool {
138    unsafe { lotus_script_sys::env::is_rc() }
139}