1use serde::{Deserialize, Serialize};
2use thedes_geometry::orientation::Direction;
3
4use crate::geometry::CoordPair;
5
6pub use thedes_entity::compact::InvalidId;
7
8pub type Registry = thedes_entity::compact::Registry<Monster>;
9
10pub type Id = thedes_entity::compact::ShortId;
11
12pub type IdShortageError = thedes_entity::compact::NonShortId;
13
14#[derive(
15 Debug,
16 Clone,
17 Copy,
18 PartialEq,
19 Eq,
20 PartialOrd,
21 Ord,
22 Hash,
23 Serialize,
24 Deserialize,
25)]
26pub struct MonsterPosition {
27 body: CoordPair,
28 facing: Direction,
29}
30
31impl MonsterPosition {
32 pub fn new(body: CoordPair, facing: Direction) -> Self {
33 Self { body, facing }
34 }
35
36 pub fn body(&self) -> CoordPair {
37 self.body
38 }
39
40 pub fn facing(&self) -> Direction {
41 self.facing
42 }
43
44 pub(crate) fn set_body(&mut self, body: CoordPair) {
45 self.body = body;
46 }
47
48 pub(crate) fn face(&mut self, facing: Direction) {
49 self.facing = facing;
50 }
51}
52
53#[derive(
54 Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
55)]
56pub struct Monster {
57 position: MonsterPosition,
58}
59
60impl Monster {
61 pub fn new(position: MonsterPosition) -> Self {
62 Self { position }
63 }
64
65 pub fn position(&self) -> MonsterPosition {
66 self.position
67 }
68
69 pub(crate) fn position_mut(&mut self) -> &mut MonsterPosition {
70 &mut self.position
71 }
72}