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
|
pub mod conveyor;
use crate::{data::Gamedata, game::Tile, protocol::PacketC};
use anyhow::Result;
use conveyor::Conveyor;
use glam::IVec2;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, VecDeque};
pub type DynEntity = Box<dyn Entity + Send + Sync + 'static>;
pub trait Entity {
fn tick(
&mut self,
data: &Gamedata,
points: &mut i64,
packet_out: &mut VecDeque<PacketC>,
tiles: &mut HashMap<IVec2, Tile>,
dt: f32,
) -> Result<()>;
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum EntityDecl {
Conveyor {
from: IVec2,
to: IVec2,
speed: Option<f32>,
},
}
pub fn construct_entity(decl: &EntityDecl) -> DynEntity {
match decl.to_owned() {
EntityDecl::Conveyor { from, to, speed } => Box::new(Conveyor {
from,
to,
max_cooldown: 1. / speed.unwrap_or(2.),
..Default::default()
}),
}
}
|