Initial commit, implements most of the static_data side.
This commit is contained in:
2
src/static_data/moves/mod.rs
Normal file
2
src/static_data/moves/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod move_data;
|
||||
pub mod secondary_effect;
|
||||
75
src/static_data/moves/move_data.rs
Normal file
75
src/static_data/moves/move_data.rs
Normal file
@@ -0,0 +1,75 @@
|
||||
use self::super::secondary_effect::SecondaryEffect;
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum MoveCategory {
|
||||
Physical,
|
||||
Special,
|
||||
Status,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[allow(dead_code)]
|
||||
pub enum MoveTarget {
|
||||
Adjacent,
|
||||
AdjacentAlly,
|
||||
AdjacentAllySelf,
|
||||
AdjacentOpponent,
|
||||
|
||||
All,
|
||||
AllAdjacent,
|
||||
AllAdjacentOpponent,
|
||||
AllAlly,
|
||||
AllOpponent,
|
||||
|
||||
Any,
|
||||
|
||||
RandomOpponent,
|
||||
SelfUse,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct MoveData {
|
||||
name: String,
|
||||
move_type: u8,
|
||||
category: MoveCategory,
|
||||
base_power: u8,
|
||||
accuracy: u8,
|
||||
base_usages: u8,
|
||||
target: MoveTarget,
|
||||
priority: i8,
|
||||
secondary_effect: SecondaryEffect,
|
||||
flags: HashSet<String>,
|
||||
}
|
||||
|
||||
impl MoveData {
|
||||
pub fn new(
|
||||
name: String,
|
||||
move_type: u8,
|
||||
category: MoveCategory,
|
||||
base_power: u8,
|
||||
accuracy: u8,
|
||||
base_usages: u8,
|
||||
target: MoveTarget,
|
||||
priority: i8,
|
||||
secondary_effect: SecondaryEffect,
|
||||
flags: HashSet<String>,
|
||||
) -> MoveData {
|
||||
MoveData {
|
||||
name,
|
||||
move_type,
|
||||
category,
|
||||
base_power,
|
||||
accuracy,
|
||||
base_usages,
|
||||
target,
|
||||
priority,
|
||||
secondary_effect,
|
||||
flags,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_flag(&self, key: &str) -> bool {
|
||||
self.flags.contains(key)
|
||||
}
|
||||
}
|
||||
55
src/static_data/moves/secondary_effect.rs
Normal file
55
src/static_data/moves/secondary_effect.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use derive_getters::Getters;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum EffectParameter {
|
||||
Bool(bool),
|
||||
Int(i64),
|
||||
Float(f32),
|
||||
String(String),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug, Getters)]
|
||||
pub struct SecondaryEffect {
|
||||
chance: f32,
|
||||
effect_name: String,
|
||||
parameters: Vec<EffectParameter>,
|
||||
}
|
||||
|
||||
impl SecondaryEffect {
|
||||
pub fn empty() -> SecondaryEffect {
|
||||
SecondaryEffect {
|
||||
chance: 0.0,
|
||||
effect_name: "".to_string(),
|
||||
parameters: vec![],
|
||||
}
|
||||
}
|
||||
pub fn new(
|
||||
chance: f32,
|
||||
effect_name: String,
|
||||
parameters: Vec<EffectParameter>,
|
||||
) -> SecondaryEffect {
|
||||
SecondaryEffect {
|
||||
chance,
|
||||
effect_name,
|
||||
parameters,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::static_data::moves::secondary_effect::SecondaryEffect;
|
||||
use assert_approx_eq::assert_approx_eq;
|
||||
|
||||
#[test]
|
||||
fn create_secondary_effect() {
|
||||
let empty = SecondaryEffect::empty();
|
||||
assert_approx_eq!(empty.chance, 0.0);
|
||||
assert_eq!(empty.effect_name, "");
|
||||
assert_eq!(empty.parameters.len(), 0);
|
||||
let set = SecondaryEffect::new(50.0, "foo".to_string(), Vec::new());
|
||||
assert_approx_eq!(set.chance, 50.0);
|
||||
assert_eq!(set.effect_name, "foo");
|
||||
assert_eq!(set.parameters.len(), 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user