Fixes for FFI.
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is passing

This commit is contained in:
2022-10-01 15:40:15 +02:00
parent 78fde698ca
commit 84ddf0307d
15 changed files with 457 additions and 111 deletions

View File

@@ -58,11 +58,13 @@ pub fn load_types(path: &String, type_library: &mut TypeLibrary) {
for record in reader.records() {
let record = record.unwrap();
let offensive_type = record.get(0).unwrap();
let offensive_type_id = type_library.get_type_id(&StringKey::new(offensive_type.into()));
let offensive_type_id = type_library
.get_type_id(&StringKey::new(offensive_type.into()))
.unwrap();
for (i, v) in record.iter().skip(1).enumerate() {
let effectiveness = v.parse::<f32>().unwrap();
type_library.set_effectiveness(offensive_type_id, (i as u8).into(), effectiveness);
type_library.set_effectiveness(offensive_type_id, ((i + 1) as u8).into(), effectiveness);
}
}
}
@@ -171,7 +173,7 @@ pub fn load_moves(path: &String, lib: &mut StaticData) {
let move_data = move_data.as_object().unwrap();
let move_name = StringKey::new(move_data.get("name").unwrap().as_str().unwrap().into());
let move_type = StringKey::new(move_data.get("type").unwrap().as_str().unwrap().into());
let move_type_id = lib.types().get_type_id(&move_type);
let move_type_id = lib.types().get_type_id(&move_type).unwrap();
let move_category = serde_json::from_value(move_data.get("category").unwrap().clone()).unwrap();
let base_power = move_data.get("power").unwrap().as_i64().unwrap() as u8;
let accuracy = move_data.get("accuracy").unwrap().as_i64().unwrap() as u8;
@@ -300,7 +302,12 @@ fn parse_form(name: StringKey, value: &Value, library: &mut StaticData) -> Form
.as_array()
.unwrap()
.iter()
.map(|a| library.types().get_type_id(&StringKey::new(a.as_str().unwrap().into())))
.map(|a| {
library
.types()
.get_type_id(&StringKey::new(a.as_str().unwrap().into()))
.unwrap()
})
.collect();
let moves = parse_moves(&value.get("moves").unwrap(), library.moves());
@@ -410,8 +417,8 @@ fn test_type_library_loaded() {
assert_eq!(
lib.get_effectiveness(
lib.get_type_id(&StringKey::new("fire".into())),
&[lib.get_type_id(&StringKey::new("grass".into()))],
lib.get_type_id(&StringKey::new("fire".into())).unwrap(),
&[lib.get_type_id(&StringKey::new("grass".into())).unwrap()],
),
2.0
);