Add autogenerated Typescript definitions
This commit is contained in:
parent
c9c3c7b59e
commit
f8e99ea02f
7 changed files with 25 additions and 14 deletions
|
@ -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"] }
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<Option<Letter>>
|
||||
}
|
||||
|
|
|
@ -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 <div className="letter">
|
||||
<div className="text">{props.data.text}</div>
|
||||
<div className="letter-points">{props.data.points}</div>
|
||||
|
@ -20,7 +15,7 @@ export function TileTray(props: { letters: Array<LetterData> }): React.JSX.Eleme
|
|||
if (ld === undefined) {
|
||||
return <div key={i}></div>;
|
||||
} else {
|
||||
return <Letter data={ld} key={i} />
|
||||
return <Letter data={ld} key={i}/>
|
||||
}
|
||||
})
|
||||
.concat();
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<title>Word Grid</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="./index.js" type="module"></script>
|
||||
<script src="index.tsx" type="module"></script>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -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});
|
||||
|
11
ui/tsconfig.json
Normal file
11
ui/tsconfig.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "ES2023",
|
||||
"jsx": "react-jsx",
|
||||
"lib": [
|
||||
"es2023",
|
||||
"dom"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue