1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#[cfg(feature = "serialization")]
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::hash::Hash;
pub trait Id {
#[cfg(not(feature = "serialization"))]
type Id: Hash + Eq + Clone + Debug;
#[cfg(feature = "serialization")]
type Id: Hash + Eq + Clone + Debug + Serialize + for<'a> Deserialize<'a>;
fn id(&self) -> &Self::Id;
}
#[cfg(test)]
pub(crate) mod tests {
use crate::battle::{Battle, BattleRules};
use crate::creature::{CreateCreature, CreatureId};
use crate::event::{DefaultOutput, DummyEvent, EventProcessor, EventTrigger};
use crate::server::Server;
use crate::space::Position;
use crate::team::{CreateTeam, TeamId};
pub(crate) fn server<R: BattleRules + 'static>(rules: R) -> Server<R> {
let battle = Battle::builder(rules).build();
Server::builder(battle).build()
}
pub(crate) fn team<'a, R: BattleRules + 'static>(server: &'a mut Server<R>, id: TeamId<R>) {
assert_eq!(CreateTeam::trigger(server, id).fire().err(), None);
}
pub(crate) fn creature<'a, R: BattleRules + 'static>(
server: &'a mut Server<R>,
creature_id: CreatureId<R>,
team_id: TeamId<R>,
position: Position<R>,
) {
assert_eq!(
CreateCreature::trigger(server, creature_id, team_id, position)
.fire()
.err(),
None
);
}
pub(crate) fn dummy<'a, R, P>(processor: &'a mut P)
where
R: BattleRules + 'static,
P: EventProcessor<R>,
{
assert_eq!(DummyEvent::trigger(processor).fire().err(), None);
}
}