Configuration fields in game rules screen are editable

This commit is contained in:
2022-10-02 16:21:08 +02:00
parent 075b9e33e4
commit a62ced4d3c
4 changed files with 98 additions and 14 deletions

View File

@ -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)]