Adds a large amount of the WASM interface
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-01-14 13:25:21 +01:00
parent 7511f56b1a
commit ca54820483
21 changed files with 777 additions and 9 deletions

View File

@@ -51,6 +51,9 @@ pub trait Form: ValueIdentifiable + Debug {
/// Check if the form has a specific flag set.
fn has_flag(&self, key: &StringKey) -> bool;
/// Arbitrary flags that can be applied to the move.
fn has_flag_by_hash(&self, key_hash: u32) -> bool;
}
/// A form is a variant of a specific species. A species always has at least one form, but can have
@@ -207,6 +210,10 @@ impl Form for FormImpl {
fn has_flag(&self, key: &StringKey) -> bool {
self.flags.contains(key)
}
fn has_flag_by_hash(&self, key_hash: u32) -> bool {
self.flags.contains::<u32>(&key_hash)
}
}
impl ValueIdentifiable for FormImpl {
@@ -240,6 +247,7 @@ pub(crate) mod tests {
fn get_random_ability(&self, rand: &mut Random) -> &StringKey;
fn get_random_hidden_ability(&self, rand: &mut Random) -> &StringKey;
fn has_flag(&self, key: &StringKey) -> bool;
fn has_flag_by_hash(&self, key_hash: u32) -> bool;
}
impl ValueIdentifiable for Form {
fn value_identifier(&self) -> ValueIdentifier {

View File

@@ -31,12 +31,16 @@ pub trait Species: ValueIdentifiable + Debug {
fn add_form(&self, id: StringKey, form: Arc<dyn Form>);
/// Gets a form by name.
fn get_form(&self, id: &StringKey) -> Option<Arc<dyn Form>>;
/// Gets a form by the hash of its name.
fn get_form_by_hash(&self, name_hash: u32) -> Option<Arc<dyn Form>>;
/// Gets the form the Pokemon will have by default, if no other form is specified.
fn get_default_form(&self) -> Arc<dyn Form>;
/// Gets a random gender.
fn get_random_gender(&self, rand: &mut Random) -> Gender;
/// Check whether the Pokemon has a specific flag set.
fn has_flag(&self, key: &StringKey) -> bool;
/// Check whether the Pokemon has a specific flag set.
fn has_flag_by_hash(&self, key_hash: u32) -> bool;
}
/// The data belonging to a Pokemon with certain characteristics.
@@ -136,6 +140,10 @@ impl Species for SpeciesImpl {
self.forms.read().get(id).cloned()
}
fn get_form_by_hash(&self, name_hash: u32) -> Option<Arc<dyn Form>> {
self.forms.read().get::<u32>(&name_hash).cloned()
}
/// Gets the form the Pokemon will have by default, if no other form is specified.
fn get_default_form(&self) -> Arc<dyn Form> {
self.forms.read().get(&get_default_key()).unwrap().clone()
@@ -156,6 +164,10 @@ impl Species for SpeciesImpl {
fn has_flag(&self, key: &StringKey) -> bool {
self.flags.contains(key)
}
fn has_flag_by_hash(&self, key_hash: u32) -> bool {
self.flags.contains::<u32>(&key_hash)
}
}
impl ValueIdentifiable for SpeciesImpl {
@@ -181,9 +193,11 @@ pub(crate) mod tests {
fn flags(&self) -> &HashSet<StringKey>;
fn add_form(&self, id: StringKey, form: Arc<dyn Form>);
fn get_form(&self, id: &StringKey) -> Option<Arc<dyn Form>>;
fn get_form_by_hash(&self, name_hash: u32) -> Option<Arc<dyn Form>>;
fn get_default_form(&self) -> Arc<dyn Form>;
fn get_random_gender(&self, rand: &mut Random) -> Gender;
fn has_flag(&self, key: &StringKey) -> bool;
fn has_flag_by_hash(&self, key_hash: u32) -> bool;
}
impl ValueIdentifiable for Species {
fn value_identifier(&self) -> ValueIdentifier {