From ef396f3bfbf4cfc2c0f26f0f6e24bdff10c9f4a8 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sat, 13 May 2023 12:29:57 -0400 Subject: [PATCH] Code review cleanups --- kifu/ffi/wasm/src/lib.rs | 28 +---- kifu/hello-wasm/Cargo.lock | 158 ----------------------------- kifu/hello-wasm/Cargo.toml | 13 --- kifu/hello-wasm/index.html | 15 --- kifu/hello-wasm/src/lib.rs | 29 ------ kifu/kifu-core/.gitignore | 1 - kifu/kifu-core/build.rs | 12 --- kifu/kifu-core/typeshare/core.d.ts | 70 +++++++++++++ kifu/kifu-pwa/src/manifest.json | 6 +- kifu/kifu-pwa/src/sw.js | 4 +- 10 files changed, 75 insertions(+), 261 deletions(-) delete mode 100644 kifu/hello-wasm/Cargo.lock delete mode 100644 kifu/hello-wasm/Cargo.toml delete mode 100644 kifu/hello-wasm/index.html delete mode 100644 kifu/hello-wasm/src/lib.rs delete mode 100644 kifu/kifu-core/.gitignore delete mode 100644 kifu/kifu-core/build.rs create mode 100644 kifu/kifu-core/typeshare/core.d.ts diff --git a/kifu/ffi/wasm/src/lib.rs b/kifu/ffi/wasm/src/lib.rs index 6a457ca..2020293 100644 --- a/kifu/ffi/wasm/src/lib.rs +++ b/kifu/ffi/wasm/src/lib.rs @@ -1,6 +1,5 @@ -use wasm_bindgen::prelude::*; -// use serde::{Serialize, Deserialize}; use kifu_core::{CoreRequest, CoreResponse}; +use wasm_bindgen::prelude::*; #[wasm_bindgen] extern "C" { @@ -8,31 +7,6 @@ extern "C" { pub fn log(s: &str); } -/* -#[wasm_bindgen] -#[derive(Serialize, Deserialize)] -pub struct CoreRequest(kifu_core::Request); -*/ - -/* -#[wasm_bindgen] -impl CoreRequest { - #[wasm_bindgen(constructor)] - pub fn new(request: kifu_core::Request) -> Self { - Self(request) - } -} -*/ - -/* Somehow uncommenting this code actually causes the module to not load. Maybe a name conflict? - * Don't know. - */ -/* -#[wasm_bindgen] -#[derive(Serialize, Deserialize)] -pub struct CoreResponse(kifu_core::Response); -*/ - #[wasm_bindgen] #[derive(Debug)] pub struct CoreApp(kifu_core::CoreApp); diff --git a/kifu/hello-wasm/Cargo.lock b/kifu/hello-wasm/Cargo.lock deleted file mode 100644 index d4122d5..0000000 --- a/kifu/hello-wasm/Cargo.lock +++ /dev/null @@ -1,158 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "bumpalo" -version = "3.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "hello-wasm" -version = "0.1.0" -dependencies = [ - "wasm-bindgen", - "wasm-bindgen-futures", -] - -[[package]] -name = "js-sys" -version = "0.3.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "once_cell" -version = "1.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" - -[[package]] -name = "proc-macro2" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" - -[[package]] -name = "wasm-bindgen" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" - -[[package]] -name = "web-sys" -version = "0.3.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" -dependencies = [ - "js-sys", - "wasm-bindgen", -] diff --git a/kifu/hello-wasm/Cargo.toml b/kifu/hello-wasm/Cargo.toml deleted file mode 100644 index b3dd24b..0000000 --- a/kifu/hello-wasm/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "hello-wasm" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[lib] -crate-type = ["cdylib"] - -[dependencies] -wasm-bindgen = "0.2" -wasm-bindgen-futures = "0.4" diff --git a/kifu/hello-wasm/index.html b/kifu/hello-wasm/index.html deleted file mode 100644 index 776dc83..0000000 --- a/kifu/hello-wasm/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - hello-wasm example - - - - - diff --git a/kifu/hello-wasm/src/lib.rs b/kifu/hello-wasm/src/lib.rs deleted file mode 100644 index 6194d4f..0000000 --- a/kifu/hello-wasm/src/lib.rs +++ /dev/null @@ -1,29 +0,0 @@ -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - pub fn alert(s: &str); - #[wasm_bindgen(js_namespace = console)] - pub fn log(s: &str); -} - -#[wasm_bindgen] -pub async fn greet(name: &str) { - log(&format!("Hello, {}! This is an async function.", name)); -} - -#[wasm_bindgen] -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} diff --git a/kifu/kifu-core/.gitignore b/kifu/kifu-core/.gitignore deleted file mode 100644 index b849c73..0000000 --- a/kifu/kifu-core/.gitignore +++ /dev/null @@ -1 +0,0 @@ -typeshare diff --git a/kifu/kifu-core/build.rs b/kifu/kifu-core/build.rs deleted file mode 100644 index c744afe..0000000 --- a/kifu/kifu-core/build.rs +++ /dev/null @@ -1,12 +0,0 @@ -use std::process::Command; - -fn main() { - Command::new("typeshare") - .args(&[ - ".", - "--lang=typescript", - "--output-file=typeshare/core.d.ts", - ]) - .status() - .unwrap(); -} diff --git a/kifu/kifu-core/typeshare/core.d.ts b/kifu/kifu-core/typeshare/core.d.ts new file mode 100644 index 0000000..506286a --- /dev/null +++ b/kifu/kifu-core/typeshare/core.d.ts @@ -0,0 +1,70 @@ +/* + Generated by typeshare 1.5.1 +*/ + +export interface PlayStoneRequest { + column: number; + row: number; +} + +export interface Size { + width: number; + height: number; +} + +export type IntersectionElement = + | { type: "Unplayable", content?: undefined } + | { type: "Empty", content: CoreRequest } + | { type: "Filled", content: StoneElement }; + +export interface BoardElement { + size: Size; + spaces: IntersectionElement[]; +} + +export enum Color { + Black = "Black", + White = "White", +} + +export interface PlayerCardElement { + color: Color; + name: string; + rank: string; + clock: string; +} + +export interface ChatElement { + messages: string[]; +} + +export interface TextFieldElement { +} + +export interface PlayingFieldView { + board: BoardElement; + player_card_black: PlayerCardElement; + player_card_white: PlayerCardElement; + chat: ChatElement; + message: TextFieldElement; + current_player: Color; +} + +export interface Jitter { + x: number; + y: number; +} + +export interface StoneElement { + color: Color; + jitter: Jitter; + liberties?: number; +} + +export type CoreRequest = + | { type: "PlayingField", content?: undefined } + | { type: "PlayStoneRequest", content: PlayStoneRequest }; + +export type CoreResponse = + | { type: "PlayingFieldView", content: PlayingFieldView }; + diff --git a/kifu/kifu-pwa/src/manifest.json b/kifu/kifu-pwa/src/manifest.json index 6a4dec4..71bb6e3 100644 --- a/kifu/kifu-pwa/src/manifest.json +++ b/kifu/kifu-pwa/src/manifest.json @@ -1,8 +1,8 @@ { "lang": "en-us", - "name": "Temperature converter app", - "short_name": "Temperature converter", - "description": "A basic temperature converter application", + "name": "Kifu", + "short_name": "Kifu", + "description": "An app for playing Go", "start_url": "/", "background_color": "#2f3d58", "theme_color": "#2f3d58", diff --git a/kifu/kifu-pwa/src/sw.js b/kifu/kifu-pwa/src/sw.js index 6e46b71..315f891 100644 --- a/kifu/kifu-pwa/src/sw.js +++ b/kifu/kifu-pwa/src/sw.js @@ -6,9 +6,7 @@ self.addEventListener('install', event => { cache.addAll([ '/', '/kifu-bundle.js', - '/converter.css', - '/kifu_wasm.js', - '/kifu_wasm_bg.wasm', + '/kifu.css', ]); })()); });