summaryrefslogtreecommitdiff
path: root/platforms/tortuise-script-wasm/src/scene.rs
diff options
context:
space:
mode:
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(())
+ }
+}