generated from 2ndbeam/bevy-template
feat: Implemented ActionGraph
This commit is contained in:
parent
18931ac157
commit
62199a1817
4 changed files with 262 additions and 3 deletions
68
src/tests/graph.rs
Normal file
68
src/tests/graph.rs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
use crate::graph::action::{ActionGraph, ActionNode, PhysicalAction};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum AttackType {
|
||||
Light,
|
||||
Heavy,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
enum AttackAction {
|
||||
Stab,
|
||||
VerticalSlash,
|
||||
HorizontalSlash,
|
||||
}
|
||||
|
||||
impl PhysicalAction<AttackType> for AttackAction {
|
||||
fn paths() -> Vec<Vec<(AttackType, Self)>> {
|
||||
use AttackType as L;
|
||||
use AttackAction as P;
|
||||
vec![
|
||||
vec![(L::Heavy, P::VerticalSlash), (L::Light, P::HorizontalSlash), (L::Heavy, P::Stab)],
|
||||
vec![(L::Heavy, P::VerticalSlash), (L::Heavy, P::Stab), (L::Light, P::Stab)],
|
||||
vec![(L::Light, P::HorizontalSlash), (L::Heavy, P::Stab), (L::Light, P::Stab)],
|
||||
vec![(L::Light, P::HorizontalSlash), (L::Light, P::VerticalSlash), (L::Heavy, P::HorizontalSlash)],
|
||||
vec![(L::Light, P::HorizontalSlash), (L::Light, P::VerticalSlash), (L::Light, P::VerticalSlash)],
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
fn get_wrong_combos() -> Vec<Vec<AttackType>> {
|
||||
use AttackType as L;
|
||||
vec![
|
||||
vec![L::Heavy, L::Light, L::Light],
|
||||
vec![L::Heavy, L::Heavy, L::Heavy],
|
||||
vec![L::Light, L::Heavy, L::Heavy],
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn action_graph_combos() {
|
||||
let mut graph = ActionGraph::<AttackAction, AttackType>::default();
|
||||
|
||||
for combo in AttackAction::paths() {
|
||||
for (i, (log, phys)) in combo.into_iter().enumerate() {
|
||||
let expected_node = ActionNode::new(Some(phys), 1 + i as u8);
|
||||
let checked_node = graph.next(log).unwrap();
|
||||
assert_eq!(checked_node, expected_node);
|
||||
}
|
||||
graph.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wrong_combos() {
|
||||
let wrong_combos = get_wrong_combos();
|
||||
|
||||
let mut graph = ActionGraph::<AttackAction, AttackType>::default();
|
||||
|
||||
for combo in wrong_combos {
|
||||
for (i, log) in combo.iter().enumerate() {
|
||||
if i < combo.len() - 1 {
|
||||
assert!(graph.next(*log).is_some());
|
||||
} else {
|
||||
assert!(graph.next(*log).is_none());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
src/tests/mod.rs
Normal file
1
src/tests/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
mod graph;
|
||||
Loading…
Add table
Add a link
Reference in a new issue