summaryrefslogtreecommitdiff
path: root/platforms/tortuise-script-wasm/src/scene.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-10-26 10:52:04 -0400
committerMica White <botahamec@outlook.com>2026-10-26 10:58:46 -0400
commitec40f6e3acc7874b82709ab81b254c741529fdff (patch)
treee3dfdc315bd0c6f1d2efcf442c2cfb3317d6810f /platforms/tortuise-script-wasm/src/scene.rs
parente3c5839159903658a667f789963f20a31567b25c (diff)
Finish engineHEADmain
Diffstat (limited to 'platforms/tortuise-script-wasm/src/scene.rs')
-rw-r--r--platforms/tortuise-script-wasm/src/scene.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/platforms/tortuise-script-wasm/src/scene.rs b/platforms/tortuise-script-wasm/src/scene.rs
new file mode 100644
index 0000000..93889a7
--- /dev/null
+++ b/platforms/tortuise-script-wasm/src/scene.rs
@@ -0,0 +1,22 @@
+use crate::ScriptContext;
+
+mod tortuise {
+ #[link(wasm_import_module = "tortuise")]
+ unsafe extern "C" {
+ pub unsafe fn scene_id_by_name(context: u64, name: *const u8, length: usize) -> usize;
+ pub safe fn switch_scene(context: u64, id: usize);
+ }
+}
+
+impl ScriptContext<'_> {
+ pub fn scene_id(&self, name: &str) -> Option<usize> {
+ let id = unsafe { tortuise::scene_id_by_name(self.0, name.as_ptr(), name.len()) };
+ (id < usize::MAX).then_some(id)
+ }
+
+ pub fn switch_scene(&mut self, name: &str) -> Option<()> {
+ let id = self.scene_id(name)?;
+ tortuise::switch_scene(self.0, id);
+ Some(())
+ }
+}