diff --git a/Cargo.toml b/Cargo.toml index 1c0feea..a3c779c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,5 @@ wasm-bindgen = { version = "0.2.87", features = ["serde-serialize"] } serde_json = "1.0" serde = { version = "1.0.181", features = ["derive"] } serde-wasm-bindgen = "0.4" +tsify = { version = "0.4.5", features = ["js"] } diff --git a/src/board.rs b/src/board.rs index f4d06cd..79a0257 100644 --- a/src/board.rs +++ b/src/board.rs @@ -2,6 +2,7 @@ use std::collections::HashSet; use std::fmt; use std::fmt::{Formatter, Write}; use serde::{Deserialize, Serialize}; +use tsify::Tsify; use crate::constants::{ALL_LETTERS_BONUS, GRID_LENGTH, TRAY_LENGTH}; use crate::dictionary::DictionaryImpl; @@ -49,7 +50,8 @@ impl Coordinates { } } -#[derive(Debug, Copy, Clone, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, Serialize, Deserialize, Tsify)] +#[tsify(from_wasm_abi)] pub struct Letter { pub text: char, pub points: u32, diff --git a/src/player_interaction.rs b/src/player_interaction.rs index 3685158..efa325c 100644 --- a/src/player_interaction.rs +++ b/src/player_interaction.rs @@ -1,10 +1,12 @@ use serde::{Deserialize, Serialize}; +use tsify::Tsify; use crate::board::Letter; pub mod ai; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Tsify)] +#[tsify(from_wasm_abi)] pub struct Tray { pub letters: Vec> } diff --git a/ui/src/elements.tsx b/ui/src/elements.tsx index 571c7a3..61dd780 100644 --- a/ui/src/elements.tsx +++ b/ui/src/elements.tsx @@ -1,13 +1,8 @@ import * as React from "react"; +import {Letter as LetterData} from "word_grid"; -export interface LetterData { - text: string, - points: number, - ephemeral: boolean, - is_blank: boolean, -} -export function Letter(props: {data: LetterData}): React.JSX.Element { +export function Letter(props: { data: LetterData }): React.JSX.Element { return
{props.data.text}
{props.data.points}
@@ -20,7 +15,7 @@ export function TileTray(props: { letters: Array }): React.JSX.Eleme if (ld === undefined) { return
; } else { - return + return } }) .concat(); diff --git a/ui/src/index.html b/ui/src/index.html index 06fa78b..af80563 100644 --- a/ui/src/index.html +++ b/ui/src/index.html @@ -6,7 +6,7 @@ Word Grid - +
diff --git a/ui/src/index.js b/ui/src/index.tsx similarity index 92% rename from ui/src/index.js rename to ui/src/index.tsx index c7a01ba..c3714fc 100644 --- a/ui/src/index.js +++ b/ui/src/index.tsx @@ -1,7 +1,7 @@ import init, {greet, GameWasm} from '../node_modules/word_grid/word_grid.js'; import {TileTray} from "./elements"; -import ReactDOM from "react-dom"; import {createRoot} from "react-dom/client"; +import {Tray} from "word_grid"; async function run() { // First up we need to actually load the wasm file, so we use the @@ -34,8 +34,8 @@ async function run() { greet("Heyo!"); - let game = new GameWasm(1234n); - let tray = game.get_tray(); + let game = new GameWasm(BigInt(1234)); + let tray: Tray = game.get_tray(); console.log({tray}); diff --git a/ui/tsconfig.json b/ui/tsconfig.json new file mode 100644 index 0000000..77e01d7 --- /dev/null +++ b/ui/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "ES2023", + "jsx": "react-jsx", + "lib": [ + "es2023", + "dom" + ] + } +} \ No newline at end of file