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 axis;
62pub mod content;
63#[doc(hidden)]
64pub mod event;
65pub mod font;
66pub mod gizmos;
67#[doc(hidden)]
68pub mod global_vars;
69pub mod graphics;
70pub mod input;
71pub mod log;
72#[doc(hidden)]
73pub mod macros;
74pub mod math;
75pub mod message;
76pub mod module;
77pub mod public_vars;
78pub mod rand;
79#[doc(hidden)]
80pub mod settings;
81pub mod time;
82pub mod var;
83pub mod vehicle;
84/// PIS-Daten und Abfragefunktionen.
85///
86/// PIS data and query functions.
87pub mod pis {
88 pub use lotus_shared::pis::*;
89}
90
91/// Häufig genutzte Typen und Makros für Script-Implementierungen.
92///
93/// Commonly used types and macros for script implementations.
94pub mod prelude {
95 pub use crate::{
96 action,
97 graphics::{textures::Texture, Color},
98 log,
99 message::{message_type, send_message, Message, MessageTarget, MessageType},
100 rand, script, time,
101 var::{get_var, set_var, VariableType},
102 vehicle, Script,
103 };
104}
105pub use lotus_shared::animation::*;
106
107/// Haupt-Trait für LOTUS-Script-Implementierungen.
108///
109/// Main trait for LOTUS script implementations.
110pub trait Script {
111 /// Wird einmal beim Laden des Scripts aufgerufen.
112 ///
113 /// Called once when the script is loaded.
114 fn init(&mut self) {}
115
116 /// Registriert Eingabeaktionen; Standard: leere Liste.
117 ///
118 /// Registers input actions; defaults to an empty list.
119 fn actions() -> Vec<action::RegisterAction> {
120 Default::default()
121 }
122
123 /// Wird pro Simulations-Tick aufgerufen.
124 ///
125 /// Called once per simulation tick.
126 fn tick(&mut self) {}
127
128 /// Verarbeitet eine eingehende Nachricht.
129 ///
130 /// Handles an incoming message.
131 #[allow(unused_variables)]
132 fn on_message(&mut self, msg: Message) {}
133}
134
135/// Gibt `true` zurück, wenn das scriptbehaftete Objekt ferngesteuert ist.
136///
137/// Returns `true` if the object the script is attached to is remote controlled.
138pub fn is_rc() -> bool {
139 unsafe { lotus_script_sys::env::is_rc() }
140}