Add adding words to dictionary mid-game
This commit is contained in:
parent
4f8f14364c
commit
733feecfe3
3 changed files with 37 additions and 2 deletions
|
@ -229,4 +229,10 @@ impl Game {
|
|||
|
||||
}
|
||||
|
||||
pub fn add_word(&mut self, word: String) {
|
||||
let word = word.to_uppercase();
|
||||
|
||||
self.dictionary.insert(word, -1.0);
|
||||
}
|
||||
|
||||
}
|
|
@ -126,5 +126,9 @@ impl GameWasm {
|
|||
|
||||
}
|
||||
|
||||
pub fn add_word(&mut self, word: String) {
|
||||
self.0.add_word(word);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -124,6 +124,11 @@ export function Game(props: {wasm: GameWasm, settings: Settings}) {
|
|||
|
||||
}
|
||||
|
||||
function addWordFn(word: string) {
|
||||
props.wasm.add_word(word);
|
||||
logDispatch(<div><em>{word} was added to dictionary.</em></div>);
|
||||
}
|
||||
|
||||
|
||||
return <>
|
||||
<TileExchangeModal
|
||||
|
@ -168,7 +173,15 @@ export function Game(props: {wasm: GameWasm, settings: Settings}) {
|
|||
console.log({result});
|
||||
|
||||
if(result.response_type === "ERR") {
|
||||
logDispatch(<div><em>{(result.value as string)}</em></div>);
|
||||
const message = result.value as string;
|
||||
if (message.endsWith("is not a valid word")) {
|
||||
// extract out word
|
||||
const word = message.split(" ")[0];
|
||||
logDispatch(<div><em>{message}</em><AddWordButton word={word} addWordFn={addWordFn} /></div>);
|
||||
} else {
|
||||
logDispatch(<div><em>{message}</em></div>);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
let total_points = 0;
|
||||
|
@ -202,5 +215,17 @@ export function Game(props: {wasm: GameWasm, settings: Settings}) {
|
|||
}}>Return Tiles</button>
|
||||
</>;
|
||||
|
||||
|
||||
}
|
||||
|
||||
function AddWordButton(props: {word: string, addWordFn: (x: string) => void}) {
|
||||
const [isClicked, setIsClicked] = useState<boolean>(false);
|
||||
|
||||
return <button
|
||||
disabled={isClicked}
|
||||
onClick={() => {
|
||||
setIsClicked(true);
|
||||
props.addWordFn(props.word);
|
||||
}}>
|
||||
Add to dictionary
|
||||
</button>
|
||||
}
|
Loading…
Reference in a new issue