fix: UI prevents players from playing blank, blank tiles
This commit is contained in:
parent
0d43ed61c4
commit
eeb80d3c86
1 changed files with 62 additions and 53 deletions
115
ui/src/Game.tsx
115
ui/src/Game.tsx
|
@ -456,68 +456,77 @@ export function Game(props: {
|
|||
className="check"
|
||||
disabled={isGameOver || !isPlayersTurn}
|
||||
onClick={async () => {
|
||||
const playedTiles = playerLetters.map((i) => {
|
||||
if (i == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (i.location === LocationType.GRID) {
|
||||
let result: PlayedTile = {
|
||||
index: i.index,
|
||||
character: null
|
||||
};
|
||||
if (i.is_blank) {
|
||||
result.character = i.text;
|
||||
try {
|
||||
const playedTiles = playerLetters.map((i) => {
|
||||
if (i == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
const committing = confirmedScorePoints > -1;
|
||||
const result = props.api.play(playedTiles, committing);
|
||||
|
||||
result
|
||||
.then(
|
||||
(api_state) => {
|
||||
console.log("Testing45")
|
||||
console.log({api_state});
|
||||
|
||||
const play_tiles: TurnAction = api_state.update.type;
|
||||
if (play_tiles.type == "PlayTiles") {
|
||||
setConfirmedScorePoints(play_tiles.result.total);
|
||||
|
||||
if (committing) {
|
||||
setAPIState(api_state);
|
||||
if (i.location === LocationType.GRID) {
|
||||
let result: PlayedTile = {
|
||||
index: i.index,
|
||||
character: null
|
||||
};
|
||||
if (i.is_blank) {
|
||||
result.character = i.text;
|
||||
if(result.character == null || result.character == " " || result.character == "") {
|
||||
throw new Error("Blank tiles must contain a letter");
|
||||
}
|
||||
|
||||
} else {
|
||||
console.error("Inaccessible branch!!!")
|
||||
}
|
||||
}
|
||||
)
|
||||
.catch((error) => {
|
||||
console.error({error});
|
||||
|
||||
if (error.endsWith(" is not a valid word")) {
|
||||
const word = error.split(' ')[0];
|
||||
// For whatever reason I can't pass props.api.add_to_dictionary directly
|
||||
logDispatch(<AddWordButton word={word}
|
||||
addWordFn={(word) => {
|
||||
props.api.add_to_dictionary(word)
|
||||
.then((api_state) => {
|
||||
setAPIState(api_state);
|
||||
})
|
||||
}}/>);
|
||||
} else {
|
||||
logDispatch(<div>{error}</div>);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
const committing = confirmedScorePoints > -1;
|
||||
const result = props.api.play(playedTiles, committing);
|
||||
|
||||
result
|
||||
.then(
|
||||
(api_state) => {
|
||||
console.log("Testing45")
|
||||
console.log({api_state});
|
||||
|
||||
const play_tiles: TurnAction = api_state.update.type;
|
||||
if (play_tiles.type == "PlayTiles") {
|
||||
setConfirmedScorePoints(play_tiles.result.total);
|
||||
|
||||
if (committing) {
|
||||
setAPIState(api_state);
|
||||
}
|
||||
|
||||
} else {
|
||||
console.error("Inaccessible branch!!!")
|
||||
}
|
||||
}
|
||||
)
|
||||
.catch((error) => {
|
||||
console.error({error});
|
||||
|
||||
if (error.endsWith(" is not a valid word")) {
|
||||
const word = error.split(' ')[0];
|
||||
// For whatever reason I can't pass props.api.add_to_dictionary directly
|
||||
logDispatch(<AddWordButton word={word}
|
||||
addWordFn={(word) => {
|
||||
props.api.add_to_dictionary(word)
|
||||
.then((api_state) => {
|
||||
setAPIState(api_state);
|
||||
})
|
||||
}}/>);
|
||||
} else {
|
||||
logDispatch(<div>{error}</div>);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
catch(e) {
|
||||
logDispatch(<div>{e.message}</div>)
|
||||
}
|
||||
|
||||
}}>{confirmedScorePoints > -1 ? `Score ${confirmedScorePoints} points` : "Check"}</button>
|
||||
<button
|
||||
className="return"
|
||||
|
|
Loading…
Add table
Reference in a new issue