Rework of FFI, adding a value identifier, so we can keep knowledge of data even when data moves.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,6 +2,7 @@ use std::convert::TryFrom;
|
||||
use std::fmt::Debug;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read};
|
||||
use std::sync::Arc;
|
||||
|
||||
use hashbrown::HashSet;
|
||||
use num_traits::PrimInt;
|
||||
@@ -116,7 +117,10 @@ pub fn load_items(path: &String, lib: &mut ItemLibrary) {
|
||||
}
|
||||
}
|
||||
|
||||
lib.add(&name, Item::new(&name, category, battle_category, price as i32, flags));
|
||||
lib.add(
|
||||
&name,
|
||||
Arc::new(Item::new(&name, category, battle_category, price as i32, flags)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +163,7 @@ pub fn load_abilities(path: &String, ability_library: &mut AbilityLibrary) {
|
||||
}
|
||||
}
|
||||
|
||||
ability_library.add(&name, Ability::new(&name, &effect, parameters));
|
||||
ability_library.add(&name, Arc::new(Ability::new(&name, &effect, parameters)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +216,7 @@ pub fn load_moves(path: &String, lib: &mut StaticData) {
|
||||
|
||||
lib.moves_mut().add(
|
||||
&move_name,
|
||||
MoveData::new(
|
||||
Arc::new(MoveData::new(
|
||||
&move_name.clone(),
|
||||
move_type_id,
|
||||
move_category,
|
||||
@@ -223,7 +227,7 @@ pub fn load_moves(path: &String, lib: &mut StaticData) {
|
||||
priority,
|
||||
secondary_effect,
|
||||
flags,
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -269,7 +273,7 @@ pub fn load_species(path: &String, library: &mut StaticData) {
|
||||
default_form,
|
||||
Default::default(),
|
||||
);
|
||||
library.species_mut().add(&name, species);
|
||||
library.species_mut().add(&name, Arc::new(species));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,7 +286,7 @@ fn load_wasm(path: &String, library: &mut WebAssemblyScriptResolver) {
|
||||
library.finalize();
|
||||
}
|
||||
|
||||
fn parse_form(name: StringKey, value: &Value, library: &mut StaticData) -> Form {
|
||||
fn parse_form(name: StringKey, value: &Value, library: &mut StaticData) -> Arc<Form> {
|
||||
let mut abilities = Vec::new();
|
||||
for a in value.get("abilities").unwrap().as_array().unwrap() {
|
||||
abilities.push(StringKey::new(a.as_str().unwrap().into()));
|
||||
@@ -312,7 +316,7 @@ fn parse_form(name: StringKey, value: &Value, library: &mut StaticData) -> Form
|
||||
|
||||
let moves = parse_moves(&value.get("moves").unwrap(), library.moves());
|
||||
|
||||
Form::new(
|
||||
Arc::new(Form::new(
|
||||
&name,
|
||||
height as f32,
|
||||
weight as f32,
|
||||
@@ -323,7 +327,7 @@ fn parse_form(name: StringKey, value: &Value, library: &mut StaticData) -> Form
|
||||
hidden_abilities,
|
||||
moves,
|
||||
Default::default(),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
fn parse_statistics<T>(value: &Value) -> StaticStatisticSet<T>
|
||||
@@ -389,15 +393,15 @@ fn parse_effect_parameter(value: &Value) -> EffectParameter {
|
||||
Value::Null => {
|
||||
panic!("Unexpected type")
|
||||
}
|
||||
Value::Bool(b) => EffectParameter::Bool(*b),
|
||||
Value::Bool(b) => (*b).into(),
|
||||
Value::Number(n) => {
|
||||
if n.is_f64() {
|
||||
EffectParameter::Float(n.as_f64().unwrap() as f32)
|
||||
(n.as_f64().unwrap() as f32).into()
|
||||
} else {
|
||||
EffectParameter::Int(n.as_i64().unwrap())
|
||||
n.as_i64().unwrap().into()
|
||||
}
|
||||
}
|
||||
Value::String(s) => EffectParameter::String(StringKey::new(s.as_str().into())),
|
||||
Value::String(s) => StringKey::new(s.as_str().into()).into(),
|
||||
Value::Array(_) => {
|
||||
panic!("Unexpected type")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user