summaryrefslogtreecommitdiff
path: root/src/script.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-07-10 19:42:23 -0400
committerMica White <botahamec@outlook.com>2026-07-10 19:42:23 -0400
commit7aa6566796e1632ae36277648c162fc77af7052b (patch)
tree1f8362c44329acd519eb1c19cc65a3729e50313a /src/script.rs
parenta9977e7fabeb06a6f21824cc4a41b36ea39f6799 (diff)
State utilities
Diffstat (limited to 'src/script.rs')
-rw-r--r--src/script.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/script.rs b/src/script.rs
index 93f6f99..8539c92 100644
--- a/src/script.rs
+++ b/src/script.rs
@@ -7,6 +7,7 @@ use crate::{
file::{FileManager, GameManifest},
input::InputManager,
scene::{preload_scene, switch_scenes},
+ storage::StorageManager,
time::TimeContext,
};
@@ -15,6 +16,7 @@ mod wasm;
pub struct ScriptManager<'a> {
scripts: &'a [ScriptDeclaration],
pub active_scripts: Vec<usize>,
+ entities: FxHashMap<Box<str>, Box<[u8]>>,
script_states: FxHashMap<usize, Box<[u8]>>,
}
@@ -28,6 +30,7 @@ pub struct ScriptContext<'a> {
pub buffer: &'a mut Buffer,
pub input: &'a InputManager,
pub time: &'a TimeContext,
+ pub storage: &'a mut StorageManager,
pub operation_queue: Vec<Operation>,
}
@@ -39,6 +42,7 @@ pub struct FullScriptContext<'a> {
pub time: &'a TimeContext,
pub scripts: &'a ScriptManager<'a>,
pub files: &'a FileManager,
+ pub storage: &'a StorageManager,
pub wasm_runner: &'a WasmRunner,
pub operation_queue: &'a mut Vec<Operation>,
}
@@ -55,6 +59,13 @@ pub enum Operation {
script_id: usize,
new_state: Box<[u8]>,
},
+ UpdateEntity {
+ name: Box<str>,
+ new_state: Box<[u8]>,
+ },
+ UpdateStorage {
+ new_save: Box<[u8]>,
+ },
Exit,
}
@@ -130,6 +141,7 @@ impl WasmRunner {
buffer: context.buffer,
input: context.input,
time: context.time,
+ storage: context.storage,
scripts,
files,
wasm_runner,
@@ -160,6 +172,7 @@ impl<'a> ScriptManager<'a> {
Self {
scripts,
active_scripts: Vec::new(),
+ entities: FxHashMap::default(),
script_states: FxHashMap::default(),
}
}
@@ -233,6 +246,7 @@ impl<'a> ScriptManager<'a> {
buffer: context.buffer,
input: context.input,
time: context.time,
+ storage: context.storage,
operation_queue: Vec::new(),
},
files,
@@ -248,6 +262,7 @@ impl<'a> ScriptManager<'a> {
buffer: context.buffer,
input: context.input,
time: context.time,
+ storage: context.storage,
operation_queue: Vec::new(),
},
wasm_runner,
@@ -260,6 +275,7 @@ impl<'a> ScriptManager<'a> {
buffer: context.buffer,
input: context.input,
time: context.time,
+ storage: context.storage,
operation_queue: Vec::new(),
},
wasm_runner,
@@ -269,6 +285,12 @@ impl<'a> ScriptManager<'a> {
script_id,
new_state,
} => *get_script_state(&mut self.script_states, *script_id) = new_state.clone(),
+ Operation::UpdateEntity { name, new_state } => {
+ self.entities.insert(name.clone(), new_state.clone());
+ }
+ Operation::UpdateStorage { new_save } => {
+ context.storage.background_save(new_save.clone());
+ }
Operation::Exit => context.exit(),
}
}
@@ -328,6 +350,7 @@ impl<'a> ScriptManager<'a> {
let Some(script) = self.scripts.get(script_id) else {
unreachable!("The active script does not exist");
};
+ self.script_states.remove(&script_id);
match script {
ScriptDeclaration::Static { end, .. } => {
end.map(|s| {