From 8f5ae08b4cceafeb815b91030a0e62b1d88f5e9c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 17 Feb 2021 21:06:56 +0000 Subject: [PATCH] hidden: introduce OccultationViews (nfc) Signed-off-by: Ian Jackson --- src/hidden.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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) -- 2.30.2