gizmo_scripting/
commands.rs1use gizmo_math::{Quat, Vec3};
7use std::sync::Mutex;
8#[derive(Debug, Clone)]
10pub enum ScriptCommand {
11 SetPosition(u32, Vec3),
13 SetRotation(u32, Quat),
14 SetScale(u32, Vec3),
15
16 SetVelocity(u32, Vec3),
18 SetAngularVelocity(u32, Vec3),
19
20 ApplyForce(u32, Vec3),
22 ApplyImpulse(u32, Vec3),
23 AddRigidBody {
24 id: u32,
25 mass: f32,
26 restitution: f32,
27 friction: f32,
28 use_gravity: bool,
29 },
30 AddBoxCollider {
31 id: u32,
32 hx: f32,
33 hy: f32,
34 hz: f32,
35 },
36 AddSphereCollider {
37 id: u32,
38 radius: f32,
39 },
40
41 SetVehicleEngineForce(u32, f32),
43 SetVehicleSteering(u32, f32),
44 SetVehicleBrake(u32, f32),
45
46 SpawnEntity {
48 name: String,
49 position: Vec3,
50 },
51 SpawnPrefab {
52 name: String,
53 prefab_type: String,
54 position: Vec3,
55 },
56 DestroyEntity(u32),
57
58 PlaySound(String),
60 PlaySound3D(String, Vec3),
61 StopSound(String),
62
63 LoadScene(String),
65 SaveScene(String),
66
67 ShowDialogue {
69 speaker: String,
70 text: String,
71 duration: f32,
72 },
73 HideDialogue,
74
75 TriggerCutscene(String), EndCutscene,
78
79 StartRace,
81 AddCheckpoint {
82 id: u32,
83 position: Vec3,
84 radius: f32,
85 },
86 ActivateCheckpoint(u32),
87 FinishRace {
88 winner_name: String,
89 },
90 ResetRace,
91
92 SetCameraTarget(u32), SetCameraFov(f32),
95
96 SetEntityName(u32, String),
98
99 AddNavAgent(u32),
101 SetAiTarget(u32, Vec3),
102 ClearAiTarget(u32),
103}
104
105pub struct CommandQueue {
107 pub commands: Mutex<Vec<ScriptCommand>>,
108}
109
110impl CommandQueue {
111 pub fn new() -> Self {
112 Self {
113 commands: Mutex::new(Vec::new()),
114 }
115 }
116
117 pub fn push(&self, cmd: ScriptCommand) {
118 self.commands.lock().unwrap().push(cmd);
119 }
120
121 pub fn drain(&self) -> Vec<ScriptCommand> {
122 self.commands.lock().unwrap().drain(..).collect()
123 }
124
125 pub fn is_empty(&self) -> bool {
126 self.commands.lock().unwrap().is_empty()
127 }
128
129 pub fn len(&self) -> usize {
130 self.commands.lock().unwrap().len()
131 }
132}
133
134impl Default for CommandQueue {
135 fn default() -> Self {
136 Self::new()
137 }
138}