diff options
Diffstat (limited to 'src/data.rs')
-rw-r--r-- | src/data.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/data.rs b/src/data.rs index 4cfe0c09e463..940bda10e7e8 100644 --- a/src/data.rs +++ b/src/data.rs @@ -78,13 +78,13 @@ pub type PlayerId = usize; #[derive(Serialize, Deserialize)] pub struct Player { /// A unique player ID (per match) - id: PlayerId, + pub id: PlayerId, /// The player name - name: String, + pub name: String, /// Player color - color: Color, + pub color: Color, /// The player's money - money: AtomicU16, + pub money: AtomicU16, } /// Optionally, players can create teams @@ -144,7 +144,7 @@ pub trait ColorPalette { /// Create a new color palette fn palette() -> Self; /// Get a palette without a certain colour - fn without(b: &Color) -> Self; + fn without(&mut self, b: &Color); /// Mix a color back into the available palette fn remix(&mut self, new: Color); } @@ -167,8 +167,11 @@ impl ColorPalette for Vec<Color> { pal } - fn without(b: &Color) -> Self { - Self::palette().into_iter().filter(|a| a == b).collect() + /// Drop a colour from the palette + fn without(&mut self, b: &Color) { + if let Some(pos) = self.into_iter().rposition(|a| a == b) { + self.remove(pos); + } } fn remix(&mut self, new: Color) { |