A framework for the Godot engine to create TTRPG games for Advanced 5th Edition, Pathfinder 2nd Edition, and more
1use crate::{hooks::Hooks, actor::Actor, item::Item, traits::Serialize};
2use std::collections::HashMap;
3use uuid::Uuid;
4use wasm_bindgen::prelude::*;
5
6pub mod hooks;
7pub mod traits;
8pub mod actor;
9pub mod item;
10
11#[cfg(feature = "pf2e")]
12pub mod pf2e;
13
14#[cfg(feature = "a5e")]
15pub mod a5e;
16
17#[cfg(feature = "dnd5e")]
18pub mod dnd5e;
19
20#[cfg(feature = "sf2e")]
21pub mod sf2e;
22
23#[wasm_bindgen]
24pub struct Game {
25 hooks: Hooks,
26 actors: HashMap<Uuid, Actor>,
27 items: HashMap<Uuid, Item>,
28 packs: HashMap<String, Vec<u8>>
29}
30
31#[wasm_bindgen]
32impl Game {
33 fn new() -> Self {
34 let packs = HashMap::new();
35
36 // need to write code to load each system's packs
37 // might want to embed the binary potentially
38
39 Self {
40 hooks: Hooks::new(),
41 actors: HashMap::new(),
42 items: HashMap::new(),
43 packs
44 }
45 }
46
47 fn get_actor(&mut self, uuid: String) -> Option<Vec<u8>> {
48 match Uuid::parse_str(&uuid) {
49 Ok(uuid) => {
50 match self.actors.get_mut(&uuid) {
51 Some(actor) => {
52 Some(actor.serialize())
53 },
54 None => {
55 println!("Could not find actor {}", uuid);
56 None
57 }
58 }
59 },
60 Err(err) => {
61 println!("There was an error parsing UUID {}: {}", uuid, err.to_string());
62 None
63 }
64 }
65 }
66
67 fn get_hooks(&mut self) -> &mut Hooks {
68 &mut self.hooks
69 }
70
71 fn get_item(&mut self, uuid: String) -> Option<Vec<u8>> {
72 match Uuid::parse_str(&uuid) {
73 Ok(uuid) => {
74 match self.items.get_mut(&uuid) {
75 Some(item) => {
76 Some(item.serialize())
77 },
78 None => {
79 println!("Could not find item {}", uuid);
80 None
81 }
82 }
83 },
84 Err(err) => {
85 println!("There was an error parsing UUID {}: {}", uuid, err.to_string());
86 None
87 }
88 }
89 }
90}