Configuration fields in game rules screen are editable
This commit is contained in:
@ -61,6 +61,10 @@ impl GameRules {
|
||||
|
||||
/// Get the list of boats for this configuration
|
||||
pub fn boats_list(&self) -> Vec<usize> {
|
||||
if self.boats_str.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
|
||||
self.boats_str
|
||||
.split(',')
|
||||
.map(|s| s.parse::<usize>().unwrap_or_default())
|
||||
@ -78,7 +82,7 @@ impl GameRules {
|
||||
pub fn add_boat(&mut self, len: usize) {
|
||||
let mut list = self.boats_list();
|
||||
list.push(len);
|
||||
self.set_boats_list(&list[0..list.len() - 1]);
|
||||
self.set_boats_list(&list);
|
||||
}
|
||||
|
||||
/// Check game rules errors
|
||||
@ -109,6 +113,11 @@ impl GameRules {
|
||||
|
||||
errors
|
||||
}
|
||||
|
||||
/// Check out whether these game rules are valid or not
|
||||
pub fn is_valid(&self) -> bool {
|
||||
return self.get_errors().is_empty();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Reference in New Issue
Block a user