use crate::{hooks::Hooks, actor::Actor, item::Item, traits::Serialize}; use std::collections::HashMap; use uuid::Uuid; use wasm_bindgen::prelude::*; pub mod hooks; pub mod traits; pub mod actor; pub mod item; #[cfg(feature = "pf2e")] pub mod pf2e; #[cfg(feature = "a5e")] pub mod a5e; #[cfg(feature = "dnd5e")] pub mod dnd5e; #[cfg(feature = "sf2e")] pub mod sf2e; #[wasm_bindgen] pub struct Game { hooks: Hooks, actors: HashMap, items: HashMap, packs: HashMap> } #[wasm_bindgen] impl Game { fn new() -> Self { let packs = HashMap::new(); // need to write code to load each system's packs // might want to embed the binary potentially Self { hooks: Hooks::new(), actors: HashMap::new(), items: HashMap::new(), packs } } fn get_actor(&mut self, uuid: String) -> Option> { match Uuid::parse_str(&uuid) { Ok(uuid) => { match self.actors.get_mut(&uuid) { Some(actor) => { Some(actor.serialize()) }, None => { println!("Could not find actor {}", uuid); None } } }, Err(err) => { println!("There was an error parsing UUID {}: {}", uuid, err.to_string()); None } } } fn get_hooks(&mut self) -> &mut Hooks { &mut self.hooks } fn get_item(&mut self, uuid: String) -> Option> { match Uuid::parse_str(&uuid) { Ok(uuid) => { match self.items.get_mut(&uuid) { Some(item) => { Some(item.serialize()) }, None => { println!("Could not find item {}", uuid); None } } }, Err(err) => { println!("There was an error parsing UUID {}: {}", uuid, err.to_string()); None } } } }