From: Ian Jackson Date: Wed, 17 Feb 2021 21:06:56 +0000 (+0000) Subject: hidden: introduce OccultationViews (nfc) X-Git-Tag: otter-0.4.0~427 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8f5ae08b4cceafeb815b91030a0e62b1d88f5e9c;p=otter.git hidden: introduce OccultationViews (nfc) Signed-off-by: Ian Jackson --- diff --git a/src/hidden.rs b/src/hidden.rs index 5ce934d8..220a8c98 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -32,15 +32,20 @@ pub struct PieceOccult { pub struct Occultation { region: Area, // automatically affect pieces here occulter: PieceId, // kept in synch with PieceOccult::active + pieces: BTreeSet, // kept in synch with PieceOccult::passive + #[serde(flatten)] views: OccultationViews, +} + +#[derive(Clone,Debug,Serialize,Deserialize)] +pub struct OccultationViews { views: Vec, #[serde(default)] defview: OccultationKind, - pieces: BTreeSet, // kept in synch with PieceOccult::passive } #[derive(Clone,Debug,Serialize,Deserialize)] pub struct OccultView { - players: Vec, #[serde(default)] occult: OccultationKind, + players: Vec, } #[derive(Clone,Copy,Debug,Serialize,Deserialize)] @@ -86,7 +91,7 @@ impl OccultationKind { } } -impl Occultation { +impl OccultationViews { pub fn get_kind(&self, player: PlayerId) -> &OccultationKind { let kind = self.views.iter().find_map(|view| { if view.players.contains(&player) { return Some(&view.occult); } @@ -96,6 +101,12 @@ impl Occultation { ); kind } +} + +impl Occultation { + pub fn get_kind(&self, player: PlayerId) -> &OccultationKind { + self.views.get_kind(player) + } pub fn in_region(&self, pos: Pos) -> bool { self.region.contains(pos)