Fix bug in Rust relating to PlayedTile
The bug broke a contract that was relied on by WASM
This commit is contained in:
parent
e23c1d139b
commit
ef655f99cd
2 changed files with 16 additions and 3 deletions
12
src/game.rs
12
src/game.rs
|
@ -37,7 +37,7 @@ pub struct PlayerState {
|
|||
#[tsify(from_wasm_abi)]
|
||||
pub struct PlayedTile {
|
||||
pub index: usize,
|
||||
pub character: char,
|
||||
pub character: Option<char>, // we only set this if PlayedTile is a blank
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Tsify)]
|
||||
|
@ -164,7 +164,15 @@ impl Game {
|
|||
|
||||
let coord = Coordinates::new_from_index(played_tile.index);
|
||||
if letter.is_blank {
|
||||
letter.text = played_tile.character;
|
||||
match played_tile.character {
|
||||
None => {
|
||||
panic!("You can't play a blank character without providing a letter value")
|
||||
}
|
||||
Some(x) => {
|
||||
// TODO - check that x is a valid alphabet letter
|
||||
letter.text = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
played_letters.push((letter, coord));
|
||||
|
||||
|
|
|
@ -72,9 +72,14 @@ impl CompleteMove {
|
|||
match m {
|
||||
Some(x) => {
|
||||
if letter.partial_match(&x.letter) {
|
||||
let character = if x.letter.is_blank {
|
||||
Some(x.letter.text)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
played_tiles.push(Some(PlayedTile {
|
||||
index: x.coordinates.map_to_index(),
|
||||
character: x.letter.text,
|
||||
character,
|
||||
}));
|
||||
*m = None;
|
||||
found_match = true;
|
||||
|
|
Loading…
Reference in a new issue