Initial work on wasm scripting backend

This commit is contained in:
2022-07-18 10:16:47 +02:00
parent 8eb1159d64
commit 7682704945
21 changed files with 651 additions and 31 deletions

View File

@@ -26,6 +26,11 @@ pub trait DataLibrary<'a, T: 'a> {
self.map().get::<StringKey>(key)
}
/// Gets a value from the library.
fn get_by_hash(&'a self, key: u32) -> Option<&'a T> {
self.map().get::<u32>(&key)
}
/// Gets a mutable value from the library.
fn get_mut(&mut self, key: &StringKey) -> Option<&mut T> {
self.get_modify().get_mut(key)

View File

@@ -6,6 +6,7 @@ use crate::StringKey;
/// A library to store all data for moves.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct MoveLibrary {
/// The underlying map.
map: IndexMap<StringKey, MoveData>,

View File

@@ -9,6 +9,7 @@ use crate::static_data::TypeLibrary;
/// The storage for all different libraries.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct StaticData {
/// Several misc settings for the library.
settings: LibrarySettings,

View File

@@ -59,6 +59,7 @@ pub enum MoveTarget {
/// A move is the skill Pokémon primarily use in battle. This is the data related to that.
#[derive(PartialEq, Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct MoveData {
/// The name of the move.
name: StringKey,

View File

@@ -1,5 +1,3 @@
use std::lazy::SyncLazy;
use hashbrown::{HashMap, HashSet};
use crate::static_data::Form;
@@ -28,7 +26,11 @@ pub struct Species {
}
/// A cached String Key to get the default form.
static DEFAULT_KEY: SyncLazy<StringKey> = SyncLazy::new(|| StringKey::new("default"));
static DEFAULT_KEY: conquer_once::OnceCell<StringKey> = conquer_once::OnceCell::uninit();
fn get_default_key() -> StringKey {
DEFAULT_KEY.get_or_init(|| StringKey::new("default")).clone()
}
impl Species {
/// Creates a new species.
@@ -42,7 +44,7 @@ impl Species {
flags: HashSet<StringKey>,
) -> Species {
let mut forms = HashMap::with_capacity(1);
forms.insert_unique_unchecked(DEFAULT_KEY.clone(), default_form);
forms.insert_unique_unchecked(get_default_key(), default_form);
Species {
id,
name: name.clone(),
@@ -96,7 +98,7 @@ impl Species {
/// Gets the form the Pokemon will have by default, if no other form is specified.
pub fn get_default_form(&self) -> &Form {
self.forms.get(&DEFAULT_KEY).unwrap()
self.forms.get(&get_default_key()).unwrap()
}
/// Gets a random gender.