-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.rs
executable file
·35 lines (33 loc) · 1.08 KB
/
main.rs
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
use crate::rules::*;
use weasel::{Battle, BattleController, EventTrigger, FlatVersionedEvent, Server};
mod rules;
fn main() {
// Create a server which will manage the battle.
let battle = Battle::builder(CustomRules::new()).build();
let mut server = Server::builder(battle).build();
// Fire two MakePizza events.
MakePizza::trigger(&mut server, "margherita".to_string())
.fire()
.unwrap();
MakePizza::trigger(&mut server, "diavola".to_string())
.fire()
.unwrap();
// Check that our custom metric is working correctly.
assert_eq!(
server
.battle()
.metrics()
.user_u64(PIZZAS_CREATED_METRIC.to_string()),
Some(2)
);
// Print the serialized history.
let events: Vec<FlatVersionedEvent<_>> = server
.battle()
.versioned_events(std::ops::Range {
start: 0,
end: server.battle().history().len() as usize,
})
.map(|e| e.into())
.collect();
println!("History:\n {}", serde_json::to_string(&events).unwrap());
}