chiark / gitweb /
hidden: introduce OccultationViews (nfc)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 17 Feb 2021 21:06:56 +0000 (21:06 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 17 Feb 2021 21:06:56 +0000 (21:06 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/hidden.rs

index 5ce934d8898bca4152ece4e4e5c0dc10e8d476f9..220a8c986587d8c6ca4cdc010414de0ba2bdab0a 100644 (file)
@@ -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<PieceId>, // kept in synch with PieceOccult::passive
+  #[serde(flatten)] views: OccultationViews,
+}
+
+#[derive(Clone,Debug,Serialize,Deserialize)]
+pub struct OccultationViews {
   views: Vec<OccultView>,
   #[serde(default)] defview: OccultationKind,
-  pieces: BTreeSet<PieceId>, // kept in synch with PieceOccult::passive
 }
 
 #[derive(Clone,Debug,Serialize,Deserialize)]
 pub struct OccultView {
-  players: Vec<PlayerId>,
   #[serde(default)] occult: OccultationKind,
+  players: Vec<PlayerId>,
 }
 
 #[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)