1use gizmo_math::{Quat, Vec3};
7use std::sync::Mutex;
8#[derive(Debug, Clone)]
10#[non_exhaustive]
11pub enum ScriptCommand {
12 SetPosition(u32, Vec3),
14 SetRotation(u32, Quat),
15 SetScale(u32, Vec3),
16
17 SetVelocity(u32, Vec3),
19 SetAngularVelocity(u32, Vec3),
20
21 ApplyForce(u32, Vec3),
23 ApplyImpulse(u32, Vec3),
24 AddRigidBody {
25 id: u32,
26 mass: f32,
27 use_gravity: bool,
28 },
29 AddBoxCollider {
30 id: u32,
31 hx: f32,
32 hy: f32,
33 hz: f32,
34 },
35 AddSphereCollider {
36 id: u32,
37 radius: f32,
38 },
39
40 SetVehicleEngineForce(u32, f32),
42 SetVehicleSteering(u32, f32),
43 SetVehicleBrake(u32, f32),
44
45 SpawnEntity {
47 name: String,
48 position: Vec3,
49 },
50 SpawnPrefab {
51 name: String,
52 prefab_type: String,
53 position: Vec3,
54 },
55 DestroyEntity(u32),
56
57 PlaySound(String),
59 PlaySound3D(String, Vec3),
60 StopSound(String),
61
62 LoadScene(String),
64 SaveScene(String),
65
66 ShowDialogue {
68 speaker: String,
69 text: String,
70 duration: f32,
71 },
72 HideDialogue,
73
74 TriggerCutscene(String), EndCutscene,
77
78 StartRace,
80 AddCheckpoint {
81 id: u32,
82 position: Vec3,
83 radius: f32,
84 },
85 ActivateCheckpoint(u32),
86 FinishRace {
87 winner_name: String,
88 },
89 ResetRace,
90
91 SetCameraTarget(u32), SetCameraFov(f32),
94 SetFightCamera {
96 p1_id: u32,
97 p2_id: u32,
98 height: f32, distance: f32, },
101
102SetEntityName(u32, String),
104PlayAnimation {
105 id: u32,
106 name: String,
107 blend: f32,
108 loop_anim: bool,
109 },
110 SetAnimationSpeed(u32, f32),
111
112
113 AddNavAgent(u32),
115 SetAiTarget(u32, Vec3),
116 ClearAiTarget(u32),
117
118 SetFighterMove {
120 id: u32,
121 name: String,
122 startup: u32,
123 active: u32,
124 recovery: u32,
125 damage: f32,
126 },
127 ApplyHitstop(u32, u32),
128 ApplyHitstun(u32, u32),
129}
130
131
132#[derive(Debug, Default)]
137pub struct CommandQueue {
138 pub commands: Mutex<Vec<ScriptCommand>>,
140}
141
142impl CommandQueue {
143 pub fn new() -> Self {
145 Self {
146 commands: Mutex::new(Vec::new()),
147 }
148 }
149
150 pub fn push(&self, cmd: ScriptCommand) {
152 self.commands
155 .lock()
156 .unwrap_or_else(|e| e.into_inner())
157 .push(cmd);
158 }
159
160 pub fn drain(&self) -> Vec<ScriptCommand> {
162 self.commands
164 .lock()
165 .unwrap_or_else(|e| e.into_inner())
166 .drain(..)
167 .collect()
168 }
169
170 pub fn is_empty(&self) -> bool {
172 self.commands
174 .lock()
175 .unwrap_or_else(|e| e.into_inner())
176 .is_empty()
177 }
178
179 pub fn len(&self) -> usize {
181 self.commands
183 .lock()
184 .unwrap_or_else(|e| e.into_inner())
185 .len()
186 }
187}