Improved party data structure
This commit is contained in:
@@ -153,7 +153,6 @@ fn register_message(events: &mut meter::Meter, message: &game_protocol::Message)
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use fake_clock::FakeClock as Instant;
|
|
||||||
|
|
||||||
use cpython::{PyClone, PyDict, PyFloat, PyUnicode};
|
use cpython::{PyClone, PyDict, PyFloat, PyUnicode};
|
||||||
|
|
||||||
|
|||||||
+6
-4
@@ -1,4 +1,6 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::iter::FromIterator;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use fake_clock::FakeClock as Instant;
|
use fake_clock::FakeClock as Instant;
|
||||||
@@ -18,23 +20,23 @@ use super::traits::FameStats;
|
|||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct Party {
|
pub struct Party {
|
||||||
pub id: usize,
|
pub id: usize,
|
||||||
pub members: Vec<String>
|
pub members: HashSet<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Party {
|
impl Party {
|
||||||
pub fn new(id: usize, members: &std::vec::Vec<std::string::String>) -> Self {
|
pub fn new(id: usize, members: &std::vec::Vec<std::string::String>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
members: members.clone(),
|
members: HashSet::from_iter(members.iter().cloned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_member(&mut self, member_name: &str) {
|
pub fn add_member(&mut self, member_name: &str) {
|
||||||
self.members.push(member_name.to_string());
|
self.members.insert(member_name.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn includes(&self, other: &str) -> bool {
|
pub fn includes(&self, other: &str) -> bool {
|
||||||
return self.members.iter().find(|m| **m == other).is_some();
|
return self.members.contains(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user