From 733feecfe30bd1d35d3b73a42f440568fb5fc534 Mon Sep 17 00:00:00 2001 From: Joel Therrien Date: Thu, 24 Aug 2023 20:29:08 -0700 Subject: [PATCH] Add adding words to dictionary mid-game --- src/game.rs | 6 ++++++ src/wasm.rs | 4 ++++ ui/src/Game.tsx | 29 +++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/game.rs b/src/game.rs index a45dda5..827c5c5 100644 --- a/src/game.rs +++ b/src/game.rs @@ -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); + } + } \ No newline at end of file diff --git a/src/wasm.rs b/src/wasm.rs index 40c3b8e..cc42b0a 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -126,5 +126,9 @@ impl GameWasm { } + pub fn add_word(&mut self, word: String) { + self.0.add_word(word); + } + } \ No newline at end of file diff --git a/ui/src/Game.tsx b/ui/src/Game.tsx index fc17b7b..b3fce4c 100644 --- a/ui/src/Game.tsx +++ b/ui/src/Game.tsx @@ -124,6 +124,11 @@ export function Game(props: {wasm: GameWasm, settings: Settings}) { } + function addWordFn(word: string) { + props.wasm.add_word(word); + logDispatch(
{word} was added to dictionary.
); + } + return <> {(result.value as string)}); + const message = result.value as string; + if (message.endsWith("is not a valid word")) { + // extract out word + const word = message.split(" ")[0]; + logDispatch(
{message}
); + } else { + logDispatch(
{message}
); + } + } else { let total_points = 0; @@ -202,5 +215,17 @@ export function Game(props: {wasm: GameWasm, settings: Settings}) { }}>Return Tiles ; - } + +function AddWordButton(props: {word: string, addWordFn: (x: string) => void}) { + const [isClicked, setIsClicked] = useState(false); + + return +} \ No newline at end of file