Compare commits

..

No commits in common. "d0af85b9739be34dc9d30b4bfd8ab907a6cdbd82" and "9e7350b08713a66c2e5e4cb6214aae742b65e7e8" have entirely different histories.

49 changed files with 5798 additions and 474 deletions

333
Cargo.lock generated
View File

@ -120,17 +120,6 @@ version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "async-channel"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35"
dependencies = [
"concurrent-queue",
"event-listener 2.5.3",
"futures-core",
]
[[package]] [[package]]
name = "async-channel" name = "async-channel"
version = "2.1.1" version = "2.1.1"
@ -144,126 +133,6 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "async-executor"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17ae5ebefcc48e7452b4987947920dac9450be1110cadf34d1b8c116bdbaf97c"
dependencies = [
"async-lock 3.3.0",
"async-task",
"concurrent-queue",
"fastrand 2.0.1",
"futures-lite 2.2.0",
"slab",
]
[[package]]
name = "async-global-executor"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c"
dependencies = [
"async-channel 2.1.1",
"async-executor",
"async-io 2.3.1",
"async-lock 3.3.0",
"blocking",
"futures-lite 2.2.0",
"once_cell",
]
[[package]]
name = "async-io"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af"
dependencies = [
"async-lock 2.8.0",
"autocfg 1.1.0",
"cfg-if",
"concurrent-queue",
"futures-lite 1.13.0",
"log 0.4.20",
"parking",
"polling 2.8.0",
"rustix 0.37.27",
"slab",
"socket2 0.4.10",
"waker-fn",
]
[[package]]
name = "async-io"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f97ab0c5b00a7cdbe5a371b9a782ee7be1316095885c8a4ea1daf490eb0ef65"
dependencies = [
"async-lock 3.3.0",
"cfg-if",
"concurrent-queue",
"futures-io",
"futures-lite 2.2.0",
"parking",
"polling 3.4.0",
"rustix 0.38.28",
"slab",
"tracing",
"windows-sys 0.52.0",
]
[[package]]
name = "async-lock"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b"
dependencies = [
"event-listener 2.5.3",
]
[[package]]
name = "async-lock"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d034b430882f8381900d3fe6f0aaa3ad94f2cb4ac519b429692a1bc2dda4ae7b"
dependencies = [
"event-listener 4.0.1",
"event-listener-strategy",
"pin-project-lite",
]
[[package]]
name = "async-std"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d"
dependencies = [
"async-channel 1.9.0",
"async-global-executor",
"async-io 1.13.0",
"async-lock 2.8.0",
"crossbeam-utils",
"futures-channel",
"futures-core",
"futures-io",
"futures-lite 1.13.0",
"gloo-timers",
"kv-log-macro",
"log 0.4.20",
"memchr",
"once_cell",
"pin-project-lite",
"pin-utils",
"slab",
"wasm-bindgen-futures",
]
[[package]]
name = "async-task"
version = "4.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799"
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.77" version = "0.1.77"
@ -284,12 +153,6 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "atomic-waker"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]] [[package]]
name = "atomic-write-file" name = "atomic-write-file"
version = "0.1.2" version = "0.1.2"
@ -412,22 +275,6 @@ dependencies = [
"generic-array 0.14.7", "generic-array 0.14.7",
] ]
[[package]]
name = "blocking"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118"
dependencies = [
"async-channel 2.1.1",
"async-lock 3.3.0",
"async-task",
"fastrand 2.0.1",
"futures-io",
"futures-lite 2.2.0",
"piper",
"tracing",
]
[[package]] [[package]]
name = "build_html" name = "build_html"
version = "2.4.0" version = "2.4.0"
@ -1025,15 +872,6 @@ dependencies = [
"zune-inflate", "zune-inflate",
] ]
[[package]]
name = "fastrand"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be"
dependencies = [
"instant",
]
[[package]] [[package]]
name = "fastrand" name = "fastrand"
version = "2.0.1" version = "2.0.1"
@ -1100,7 +938,7 @@ checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6"
name = "fitnesstrax" name = "fitnesstrax"
version = "0.5.0" version = "0.5.0"
dependencies = [ dependencies = [
"async-channel 2.1.1", "async-channel",
"async-trait", "async-trait",
"chrono", "chrono",
"chrono-tz", "chrono-tz",
@ -1300,34 +1138,6 @@ version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa"
[[package]]
name = "futures-lite"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce"
dependencies = [
"fastrand 1.9.0",
"futures-core",
"futures-io",
"memchr",
"parking",
"pin-project-lite",
"waker-fn",
]
[[package]]
name = "futures-lite"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "445ba825b27408685aaecefd65178908c36c6e96aaf6d8599419d46e624192ba"
dependencies = [
"fastrand 2.0.1",
"futures-core",
"futures-io",
"parking",
"pin-project-lite",
]
[[package]] [[package]]
name = "futures-macro" name = "futures-macro"
version = "0.3.29" version = "0.3.29"
@ -1584,18 +1394,6 @@ dependencies = [
"system-deps", "system-deps",
] ]
[[package]]
name = "gloo-timers"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c"
dependencies = [
"futures-channel",
"futures-core",
"js-sys",
"wasm-bindgen",
]
[[package]] [[package]]
name = "gm-control-panel" name = "gm-control-panel"
version = "0.1.0" version = "0.1.0"
@ -1967,7 +1765,7 @@ dependencies = [
"httpdate", "httpdate",
"itoa", "itoa",
"pin-project-lite", "pin-project-lite",
"socket2 0.5.5", "socket2",
"tokio", "tokio",
"tower-service", "tower-service",
"tracing", "tracing",
@ -2104,15 +1902,6 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "intl-memoizer" name = "intl-memoizer"
version = "0.5.1" version = "0.5.1"
@ -2132,17 +1921,6 @@ dependencies = [
"unic-langid", "unic-langid",
] ]
[[package]]
name = "io-lifetimes"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
dependencies = [
"hermit-abi",
"libc",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "ipnet" name = "ipnet"
version = "2.9.0" version = "2.9.0"
@ -2172,7 +1950,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
dependencies = [ dependencies = [
"hermit-abi", "hermit-abi",
"rustix 0.38.28", "rustix",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@ -2222,7 +2000,6 @@ dependencies = [
name = "kifu-core" name = "kifu-core"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-std",
"chrono", "chrono",
"config", "config",
"config-derive", "config-derive",
@ -2239,7 +2016,6 @@ dependencies = [
name = "kifu-gtk" name = "kifu-gtk"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-channel 2.1.1",
"cairo-rs", "cairo-rs",
"gio", "gio",
"glib", "glib",
@ -2253,15 +2029,6 @@ dependencies = [
"tokio", "tokio",
] ]
[[package]]
name = "kv-log-macro"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f"
dependencies = [
"log 0.4.20",
]
[[package]] [[package]]
name = "language-tags" name = "language-tags"
version = "0.2.2" version = "0.2.2"
@ -2338,12 +2105,6 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "linux-raw-sys"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.4.12" version = "0.4.12"
@ -2374,9 +2135,6 @@ name = "log"
version = "0.4.20" version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
dependencies = [
"value-bag",
]
[[package]] [[package]]
name = "logger" name = "logger"
@ -2929,17 +2687,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "piper"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4"
dependencies = [
"atomic-waker",
"fastrand 2.0.1",
"futures-io",
]
[[package]] [[package]]
name = "pkcs1" name = "pkcs1"
version = "0.7.5" version = "0.7.5"
@ -3001,36 +2748,6 @@ dependencies = [
"miniz_oxide 0.7.1", "miniz_oxide 0.7.1",
] ]
[[package]]
name = "polling"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce"
dependencies = [
"autocfg 1.1.0",
"bitflags 1.3.2",
"cfg-if",
"concurrent-queue",
"libc",
"log 0.4.20",
"pin-project-lite",
"windows-sys 0.48.0",
]
[[package]]
name = "polling"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30054e72317ab98eddd8561db0f6524df3367636884b7b21b703e4b280a84a14"
dependencies = [
"cfg-if",
"concurrent-queue",
"pin-project-lite",
"rustix 0.38.28",
"tracing",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "powerfmt" name = "powerfmt"
version = "0.2.0" version = "0.2.0"
@ -3480,20 +3197,6 @@ dependencies = [
"semver", "semver",
] ]
[[package]]
name = "rustix"
version = "0.37.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2"
dependencies = [
"bitflags 1.3.2",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys 0.3.8",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.28" version = "0.38.28"
@ -3503,7 +3206,7 @@ dependencies = [
"bitflags 2.4.1", "bitflags 2.4.1",
"errno", "errno",
"libc", "libc",
"linux-raw-sys 0.4.12", "linux-raw-sys",
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
@ -3763,16 +3466,6 @@ version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
[[package]]
name = "socket2"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "socket2" name = "socket2"
version = "0.5.5" version = "0.5.5"
@ -4117,9 +3810,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"fastrand 2.0.1", "fastrand",
"redox_syscall", "redox_syscall",
"rustix 0.38.28", "rustix",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@ -4260,7 +3953,7 @@ dependencies = [
"parking_lot", "parking_lot",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry", "signal-hook-registry",
"socket2 0.5.5", "socket2",
"tokio-macros", "tokio-macros",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@ -4646,12 +4339,6 @@ dependencies = [
"getrandom", "getrandom",
] ]
[[package]]
name = "value-bag"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "126e423afe2dd9ac52142e7e9d5ce4135d7e13776c529d27fd6bc49f19e3280b"
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"
@ -4697,12 +4384,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "waker-fn"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690"
[[package]] [[package]]
name = "want" name = "want"
version = "0.3.1" version = "0.3.1"

30
Makefile Normal file
View File

@ -0,0 +1,30 @@
all: test bin
test: kifu-core/test-oneshot sgf/test-oneshot
bin: kifu-gtk
kifu-core/dev:
cd kifu/core && make test
kifu-core/test:
cd kifu/core && make test
kifu-core/test-oneshot:
cd kifu/core && make test-oneshot
kifu-gtk:
cd kifu/gtk && make release
kifu-gtk/dev:
cd kifu/gtk && make dev
kifu-pwa:
cd kifu/pwa && make release
kifu-pwa/dev:
pushd kifu/pwa && make dev
kifu-pwa/server:
pushd kifu/pwa && make server

73
build.sh Executable file
View File

@ -0,0 +1,73 @@
#!/usr/bin/env bash
set -euo pipefail
RUST_ALL_TARGETS=(
"changeset"
"config"
"config-derive"
"coordinates"
"cyberpunk-splash"
"dashboard"
"emseries"
"file-service"
"fitnesstrax"
"fluent-ergonomics"
"geo-types"
"gm-control-panel"
"hex-grid"
"ifc"
"kifu-core"
"kifu-gtk"
"memorycache"
"nom-training"
"result-extended"
"screenplay"
"sgf"
"tree"
)
build_rust_targets() {
local CMD=$1
local TARGETS=${@/$CMD}
for target in $TARGETS; do
MODULE=$target CMD=$CMD ./builders/rust.sh
done
}
build_dist() {
local TARGETS=${@/$CMD}
for target in $TARGETS; do
if [ -f $target/dist.sh ]; then
build_rust_targets release ${TARGETS[*]}
cd $target && ./dist.sh
fi
done
}
export CARGO=`which cargo`
if [ -z "${TARGET-}" ]; then
TARGET="all"
fi
if [ -z "${CMD-}" ]; then
CMD="test release"
fi
if [ "${CMD}" == "clean" ]; then
cargo clean
exit 0
fi
for cmd in $CMD; do
if [ "${CMD}" == "dist" ]; then
build_dist $TARGET
elif [ "${TARGET}" == "all" ]; then
build_rust_targets $cmd ${RUST_ALL_TARGETS[*]}
else
build_rust_targets $cmd $TARGET
fi
done

41
builders/rust.sh Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail
if [ ! -z "$MODULE" ]; then
MODULE="-p $MODULE"
fi
if [ -z "${PARAMS-}" ]; then
PARAMS=""
fi
case $CMD in
build)
$CARGO build $MODULE $PARAMS
;;
lint)
$CARGO clippy $MODULE $PARAMS -- -Dwarnings
;;
test)
$CARGO test $MODULE $PARAMS
;;
run)
$CARGO run $MODULE $PARAMS
;;
release)
$CARGO clippy $MODULE $PARAMS -- -Dwarnings
$CARGO build --release $MODULE $PARAMS
$CARGO test --release $MODULE $PARAMS
;;
clean)
$CARGO clean $MODULE
;;
"")
echo "No command specified. Use build | lint | test | run | release | clean"
;;
*)
echo "$CMD is unknown. Use build | lint | test | run | release | clean"
;;
esac

View File

@ -70,7 +70,6 @@
dashboard = attrs: { nativeBuildInputs = gtkNativeInputs; }; dashboard = attrs: { nativeBuildInputs = gtkNativeInputs; };
fitnesstrax = import ./fitnesstrax/app/override.nix { gtkNativeInputs = gtkNativeInputs; }; fitnesstrax = import ./fitnesstrax/app/override.nix { gtkNativeInputs = gtkNativeInputs; };
kifu-gtk = import ./kifu/gtk/override.nix { gtkNativeInputs = gtkNativeInputs; };
}; };
}; };
@ -84,7 +83,6 @@
dashboard = cargo_nix.workspaceMembers.dashboard.build; dashboard = cargo_nix.workspaceMembers.dashboard.build;
file-service = cargo_nix.workspaceMembers.file-service.build; file-service = cargo_nix.workspaceMembers.file-service.build;
fitnesstrax = cargo_nix.workspaceMembers.fitnesstrax.build; fitnesstrax = cargo_nix.workspaceMembers.fitnesstrax.build;
kifu-gtk = cargo_nix.workspaceMembers.kifu-gtk.build;
all = pkgs.symlinkJoin { all = pkgs.symlinkJoin {
name = "all"; name = "all";
@ -93,7 +91,6 @@
dashboard dashboard
file-service file-service
fitnesstrax fitnesstrax
kifu-gtk
]; ];
}; };

6
kifu/core-types/Makefile Normal file
View File

@ -0,0 +1,6 @@
SOURCES = $(shell find ../core -name "*.rs")
dist/index.ts: $(SOURCES)
mkdir -p dist
typeshare ../core --lang=typescript --output-file=dist/index.ts

View File

@ -0,0 +1,13 @@
{
"name": "core-types",
"version": "0.0.1",
"description": "",
"types": "dist/index.ts",
"main": "dist/index.ts",
"scripts": {
"build": "make",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Savanni D'Gerinel <savanni@luminescent-dreams.com>",
"license": "GPL-3.0-or-later"
}

View File

@ -6,7 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
async-std = { version = "1" }
chrono = { version = "0.4" } chrono = { version = "0.4" }
config = { path = "../../config" } config = { path = "../../config" }
config-derive = { path = "../../config-derive" } config-derive = { path = "../../config-derive" }

View File

@ -1,5 +1,6 @@
use crate::{ use crate::{
database::Database, types::{AppState, Config, ConfigOption, DatabasePath, GameState, Player, Rank}, ui::{configuration, home, playing_field, ConfigurationView, HomeView, PlayingFieldView} types::{AppState, Config, ConfigOption, DatabasePath, GameState, Player, Rank},
ui::{configuration, home, playing_field, ConfigurationView, HomeView, PlayingFieldView},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
@ -74,46 +75,37 @@ pub enum CoreResponse {
UpdatedConfigurationView(ConfigurationView), UpdatedConfigurationView(ConfigurationView),
} }
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum CoreNotification {
BoardUpdated,
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct CoreApp { pub struct CoreApp {
// config: Arc<RwLock<Config>>, config: Arc<RwLock<Config>>,
// state: Arc<RwLock<AppState>>, state: Arc<RwLock<AppState>>,
database: Arc<RwLock<Option<Database>>>,
} }
impl CoreApp { impl CoreApp {
pub fn new(_config: Config) -> Self { pub fn new(config_path: std::path::PathBuf) -> Self {
// let config = Config::from_path(config_path).expect("configuration to open"); let config = Config::from_path(config_path).expect("configuration to open");
// let state = Arc::new(RwLock::new(AppState::new(db_path))); let db_path: DatabasePath = config.get().unwrap();
let state = Arc::new(RwLock::new(AppState::new(db_path)));
Self { Self {
// config: Arc::new(RwLock::new(config)), config: Arc::new(RwLock::new(config)),
// state, state,
database: Arc::new(RwLock::new(None)),
} }
} }
/*
pub async fn dispatch(&self, request: CoreRequest) -> CoreResponse { pub async fn dispatch(&self, request: CoreRequest) -> CoreResponse {
match request { match request {
CoreRequest::ChangeSetting(request) => match request { CoreRequest::ChangeSetting(request) => match request {
ChangeSettingRequest::LibraryPath(path) => { ChangeSettingRequest::LibraryPath(path) => {
// let mut config = self.config.write().unwrap(); let mut config = self.config.write().unwrap();
// config.set(ConfigOption::DatabasePath(DatabasePath(PathBuf::from( config.set(ConfigOption::DatabasePath(DatabasePath(PathBuf::from(
// path, path,
// )))); ))));
// CoreResponse::UpdatedConfigurationView(configuration(&config)) CoreResponse::UpdatedConfigurationView(configuration(&config))
unimplemented!()
} }
}, },
CoreRequest::CreateGame(create_request) => { CoreRequest::CreateGame(create_request) => {
/*
let mut app_state = self.state.write().unwrap(); let mut app_state = self.state.write().unwrap();
let white_player = { let white_player = {
match create_request.white_player { match create_request.white_player {
@ -132,37 +124,30 @@ impl CoreApp {
}); });
let game_state = app_state.game.as_ref().unwrap(); let game_state = app_state.game.as_ref().unwrap();
CoreResponse::PlayingFieldView(playing_field(game_state)) CoreResponse::PlayingFieldView(playing_field(game_state))
*/
unimplemented!()
} }
CoreRequest::Home => { CoreRequest::Home => {
// CoreResponse::HomeView(home(self.state.read().unwrap().database.all_games())) CoreResponse::HomeView(home(self.state.read().unwrap().database.all_games()))
unimplemented!()
} }
CoreRequest::OpenConfiguration => { CoreRequest::OpenConfiguration => {
// CoreResponse::ConfigurationView(configuration(&self.config.read().unwrap())) CoreResponse::ConfigurationView(configuration(&self.config.read().unwrap()))
unimplemented!()
} }
CoreRequest::PlayingField => { CoreRequest::PlayingField => {
// let app_state = self.state.read().unwrap(); let app_state = self.state.read().unwrap();
// let game = app_state.game.as_ref().unwrap(); let game = app_state.game.as_ref().unwrap();
// CoreResponse::PlayingFieldView(playing_field(game)) CoreResponse::PlayingFieldView(playing_field(game))
unimplemented!()
} }
CoreRequest::PlayStone(request) => { CoreRequest::PlayStone(request) => {
// let mut app_state = self.state.write().unwrap(); let mut app_state = self.state.write().unwrap();
// app_state.place_stone(request); app_state.place_stone(request);
// let game = app_state.game.as_ref().unwrap(); let game = app_state.game.as_ref().unwrap();
// CoreResponse::PlayingFieldView(playing_field(game)) CoreResponse::PlayingFieldView(playing_field(game))
unimplemented!()
} }
CoreRequest::StartGame => { CoreRequest::StartGame => {
unimplemented!() unimplemented!()
} }
} }
} }
*/
// pub async fn run(&self) {} pub async fn run(&self) {}
} }

View File

@ -12,6 +12,6 @@ pub use board::*;
mod database; mod database;
mod types; mod types;
pub use types::{BoardError, Color, Rank, Size, DatabasePath, Config, ConfigOption}; pub use types::{BoardError, Color, Rank, Size};
pub mod ui; pub mod ui;

View File

@ -25,12 +25,6 @@ impl std::ops::Deref for DatabasePath {
} }
} }
impl From<String> for DatabasePath {
fn from(s: String) -> Self {
Self(PathBuf::from(s))
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ConfigOption)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ConfigOption)]
pub struct Me(Player); pub struct Me(Player);

47
kifu/design/analysis.html Normal file
View File

@ -0,0 +1,47 @@
<!doctype html>
<html>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="styles.css" />
<body>
<div class="menu">
<ul>
<li> <a href="index.html">Index</a> </li>
<li> <a href="playing.html">Game Board for playing</a> </li>
<li> <a href="database.html">Game database</a> </li>
<li> <a href="analysis.html">Game board for analysis</a> </li>
<li> Connection management </li>
<li> Challenge list </li>
<li> Friends list </li>
<li> Open challenges </li>
</ul>
</div>
<div class="widget">
<div> US Go Congress 2023, DDK Tournament, Round 1, Board 25 </div>
<div class="game-analysis">
<div class="game-analysis__board">
<img src="game-screen.jpg" />
</div>
<div class="game-analysis__tree">
<div>
<img src="game-tree.jpg" />
</div>
<p> Shoring up the wall. Any chance to capture that group was lost a couple of moves back and Savanni knows it. </p>
</div>
</div>
<div class="game-info">
<div class="player-info">
<div> Savanni (10k) </div>
</div>
<div class="player-info">
<div> Opal (10k) </div>
</div>
</div>
</div>
</body>
</html>

118
kifu/design/database.html Normal file
View File

@ -0,0 +1,118 @@
<!doctype html>
<html>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="styles.css" />
<body>
<div class="menu">
<ul>
<li> <a href="index.html">Index</a> </li>
<li> <a href="playing.html">Game Board for playing</a> </li>
<li> <a href="database.html">Game database</a> </li>
<li> Game board for analysis </li>
<li> Connection management </li>
<li> Challenge list </li>
<li> Friends list </li>
<li> Open challenges </li>
</ul>
</div>
<div class="widget">
<div class="game-filter">
<input class="game-filter__term" placeholder="date" />
<input class="game-filter__term" placeholder="player name" />
<input class="game-filter__term" placeholder="minimum strength" />
<input class="game-filter__term" placeholder="maximum strength" />
</div>
<div class="game-database">
<div class="game-entry">
<a href="analysis.html"><img class="game-entry__icon" src="game-thumbnail.jpg" /></a>
<div class="game-entry__info-card">
<div class="game-entry__info-row">
2016-06-15
</div>
<div class="game-entry__info-row">
(B) Alpha Go (w)
</div>
<div class="game-entry__info-row">
(W) Lee Sedol
</div>
</div>
</div>
<div class="game-entry">
<img class="game-entry__icon" src="game-thumbnail.jpg" />
<div class="game-entry__info-card">
<div class="game-entry__info-row">
2016-06-15
</div>
<div class="game-entry__info-row">
(B) Alpha Go (w)
</div>
<div class="game-entry__info-row">
(W) Lee Sedol
</div>
</div>
</div>
<div class="game-entry">
<img class="game-entry__icon" src="game-thumbnail.jpg" />
<div class="game-entry__info-card">
<div class="game-entry__info-row">
2016-06-15
</div>
<div class="game-entry__info-row">
(B) Alpha Go (w)
</div>
<div class="game-entry__info-row">
(W) Lee Sedol
</div>
</div>
</div>
<div class="game-entry">
<img class="game-entry__icon" src="game-thumbnail.jpg" />
<div class="game-entry__info-card">
<div class="game-entry__info-row">
2016-06-15
</div>
<div class="game-entry__info-row">
(B) Alpha Go (w)
</div>
<div class="game-entry__info-row">
(W) Lee Sedol
</div>
</div>
</div>
<div class="game-entry">
<img class="game-entry__icon" src="game-thumbnail.jpg" />
<div class="game-entry__info-card">
<div class="game-entry__info-row">
2016-06-15
</div>
<div class="game-entry__info-row">
(B) Alpha Go (w)
</div>
<div class="game-entry__info-row">
(W) Lee Sedol
</div>
</div>
</div>
</div>
</div>
</body>
</html>

BIN
kifu/design/game-screen.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
kifu/design/game-tree.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

24
kifu/design/index.html Normal file
View File

@ -0,0 +1,24 @@
<!doctype html>
<html>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="styles.css" />
<body>
<div class="menu">
<ul>
<li> <a href="playing.html">Game Board for playing</a> </li>
<li> <a href="database.html">Game database</a> </li>
<li> <a href="analysis.html">Game board for analysis</a> </li>
<li> Connection management </li>
<li> Challenge list </li>
<li> Friends list </li>
<li> Open challenges </li>
</ul>
</div>
<div class="widget">
</div>
</body>
</html>

49
kifu/design/playing.html Normal file
View File

@ -0,0 +1,49 @@
<!doctype html>
<html>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="styles.css" />
<body>
<div class="menu">
<ul>
<li> <a href="index.html">Index</a> </li>
<li> <a href="playing.html">Game Board for playing</a> </li>
<li> Game database </li>
<li> Game board for analysis </li>
<li> Connection management </li>
<li> Challenge list </li>
<li> Friends list </li>
<li> Open challenges </li>
</ul>
</div>
<div class="widget">
<img src="game-screen.jpg" />
<div class="game-info">
<div class="player-info">
<div> Savanni (10k) </div> <div> 24:53 </div>
</div>
<div class="player-info">
<div> Opal (10k) </div> <div> 25:00 </div>
</div>
</div>
<div class="chat">
<div>
<textarea cols="80" rows="25">
[22:05] Savanni: oops
[22:06] Opal: you know I'll take advantage of that, right?
</textarea>
</div>
<div>
<input size="60"></input>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,270 @@
(;FF[4]
CA[UTF-8]
GM[1]
DT[2022-02-17]
GN[Amika Matĉo]
PC[https://online-go.com/review/823151]
PB[mearss25]
PW[savanni.dgerinel]
BR[16k]
WR[10k]
TM[1500]OT[15 fischer]
RE[W+46.5]
SZ[19]
KM[7.5]
RU[AGA]
;B[pd]SQ[ph]SQ[oi]LB[pi:B]LB[qi:A]SQ[pj]LB[qj:C]
;W[dp]
;B[dd]
;W[qp]
;B[ch]
;W[np]
;B[cl]
;W[qf]
;B[qh]
(;W[of]
(;B[nc]
;W[oi]
;B[pj]
;W[md]
;B[nk]
;W[jd]
;B[gc]
(;W[jj]
;B[mi]
;W[mj]
;B[lj]
;W[nj]
;B[ok]
;W[li]
;B[ki]
;W[lh]
;B[kj]
;W[kh]
;B[mk]
(;W[pi]
;B[qi]
;W[ji]
;B[ni]
;W[oj]
;B[nh]
;W[mh]
;B[oh]
;W[ng]
;B[ig]
;W[qc]
;B[pf]
;W[pg]
;B[ph]
;W[pe]
;B[qd]
;W[od]
;B[oc]
;W[pc]
;B[nd]
;W[oe]
;B[og]
;W[rd]
;B[mc]
;W[mf]
;B[ld]
;W[me]
;B[jh]
;W[cc]
;B[cd]
;W[dc]
;B[ec]
;W[eb]
;B[fd]
;W[fb]
;B[gb]
;W[bd]
;B[be]
;W[bc]
;B[ad]
;W[ce]
;B[de]
;W[ac]
;B[cf]
;W[ae]
;B[fa]
;W[ea]
;B[ga]
;W[ca]
;B[cq]
;W[dq]
;B[cp]
;W[cn]
;B[bn]
;W[do]
;B[cm]
;W[cr]
;B[co]
;W[dn]
;B[dm]
;W[fn]
;B[fm]
;W[hn]
;B[il]
;W[jp]
;B[hq]
;W[jq]
;B[er]
;W[dr]
;B[fq]
;W[ir]
;B[io]
;W[jm]
;B[kn]
;W[jn]
;B[ho]
;W[gn]
;B[hr]
;W[gp]
;B[gr]
;W[es]
;B[fs]
;W[ds]
;B[eq]
;W[hs]
;B[go]
;W[fp]
;B[en]
;W[eo]
;B[br]
;W[fo]
;B[mo]
;W[mp]
;B[lp]
;W[lq]
;B[ko]
;W[jo]
;B[km]
;W[ql]
;B[pl]
;W[pm]
;B[om]
;W[pn]
;B[on]
;W[oo]
;B[no]
;W[op]
;B[qk]
;W[rl]
;B[rk]
;W[rn]
;B[qg]
;W[rf]
;B[rg]
;W[kf]
;B[if]
;W[kc]
;B[lb]
;W[lc]
;B[kb]
;W[jb]
;B[ma]
;W[ob]
;B[nb]
;W[pa]
;B[ka]
;W[je]
;B[ie]
;W[id]
;B[hd]
;W[jl]
;B[ii]
;W[ik]
;B[hk]
;W[hl]
;B[gl]
;W[hm]
;B[ij]
;W[jk]
;B[gm]
;W[bf]
;B[bg]
;W[ce]
;B[cg]
;W[be]
;B[fh]
;W[jg]
;B[ih]
;W[em]
;B[el]
;W[gk]
;B[hj]
;W[fl]
;B[gj]
;W[fk]
;B[ek]
;W[kp]
;B[fj]
;W[sl]
;B[sk]
;W[kk]
;B[lk]
;W[lo]
;B[ln]
;W[lp]
;B[ll]
;W[sf]
;B[sg]
;W[ib]
;B[ic]
;W[jc]
;B[hc]
;W[is]
;B[bs]
;W[fc]
;B[ed]
;W[ne]
;B[na]
;W[oa]
;B[qa]
;W[pb]
;B[rc]
;W[qe]
;B[ag]
;W[jf]
;B[pf]
;W[kl]
;B[mm]
;W[pg]
;B[]
;W[pf]
;B[]
;W[]
)(;W[lk]
;B[kk]
;W[ll]
;B[kl]
;W[km]
;B[jm]
;W[kn]
))(;W[mj]
))(;B[nd]
;W[oh]
;B[qk]
))(;W[qc]
(;B[qd]
;W[pc]
;B[od]
;W[rd]
;B[re]
;W[rc]
;B[rf]
;W[nc]
;B[me]
)(;B[pc]TR[jc]
;W[qd]
;B[pe]
(;W[rf]
;B[og]
)(;W[pf]
;B[of]
;W[oe]
(;B[ne]
)(;B[nf]
)))))

44
kifu/design/styles.css Normal file
View File

@ -0,0 +1,44 @@
body {
background: hsl(0 0% 85%);
display: flex;
}
.menu {
border-right: 1px solid black;
padding: 8px;
}
.game-info {
display: flex;
justify-content: space-between;
}
.widget {
}
.game-database {
display: flex;
flex-wrap: wrap;
}
.game-entry {
display: flex;
width: 500px;
margin: 8px;
}
.game-entry__icon {
width: 300px;
}
.game-analysis {
display: flex;
}
.game-analysis__board {
flex-shrink: 1;
}
.game-analysis__tree {
flex-shrink: 0;
}

564
kifu/ffi/wasm/Cargo.lock generated Normal file
View File

@ -0,0 +1,564 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bumpalo"
version = "3.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
dependencies = [
"iana-time-zone",
"js-sys",
"num-integer",
"num-traits",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
dependencies = [
"termcolor",
"unicode-width",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "cxx"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93"
dependencies = [
"cc",
"cxxbridge-flags",
"cxxbridge-macro",
"link-cplusplus",
]
[[package]]
name = "cxx-build"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b"
dependencies = [
"cc",
"codespan-reporting",
"once_cell",
"proc-macro2",
"quote",
"scratch",
"syn 2.0.15",
]
[[package]]
name = "cxxbridge-flags"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb"
[[package]]
name = "cxxbridge-macro"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.15",
]
[[package]]
name = "grid"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0634107a3a005070dd73e27e74ecb691a94e9e5ba7829f434db7fbf73a6b5c47"
dependencies = [
"no-std-compat",
]
[[package]]
name = "iana-time-zone"
version = "0.1.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
dependencies = [
"cxx",
"cxx-build",
]
[[package]]
name = "itoa"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
[[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 = "kifu-core"
version = "0.1.0"
dependencies = [
"grid",
"serde",
"thiserror",
"typeshare",
]
[[package]]
name = "kifu-wasm"
version = "0.1.0"
dependencies = [
"kifu-core",
"serde",
"serde-wasm-bindgen",
"wasm-bindgen",
"wasm-bindgen-futures",
]
[[package]]
name = "libc"
version = "0.2.142"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317"
[[package]]
name = "link-cplusplus"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
dependencies = [
"cc",
]
[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
[[package]]
name = "no-std-compat"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c"
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[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 = "ryu"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
[[package]]
name = "scratch"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1"
[[package]]
name = "serde"
version = "1.0.160"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde-wasm-bindgen"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3b143e2833c57ab9ad3ea280d21fd34e285a42837aeb0ee301f4f41890fa00e"
dependencies = [
"js-sys",
"serde",
"wasm-bindgen",
]
[[package]]
name = "serde_derive"
version = "1.0.160"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.15",
]
[[package]]
name = "serde_json"
version = "1.0.96"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[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 = "syn"
version = "2.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "termcolor"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
dependencies = [
"winapi-util",
]
[[package]]
name = "thiserror"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.15",
]
[[package]]
name = "typeshare"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f44d1a2f454cb35fbe05b218c410792697e76bd868f48d3a418f2cd1a7d527d6"
dependencies = [
"chrono",
"serde",
"serde_json",
"typeshare-annotation",
]
[[package]]
name = "typeshare-annotation"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc670d0e358428857cc3b4bf504c691e572fccaec9542ff09212d3f13d74b7a9"
dependencies = [
"quote",
"syn 1.0.109",
]
[[package]]
name = "unicode-ident"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
[[package]]
name = "unicode-width"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[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 1.0.109",
"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 1.0.109",
"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",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
[[package]]
name = "windows_i686_gnu"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
[[package]]
name = "windows_i686_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"

19
kifu/ffi/wasm/Cargo.toml Normal file
View File

@ -0,0 +1,19 @@
[package]
name = "kifu-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]
kifu-core = { path = "../../core" }
serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = "0.5.0"
wasm-bindgen = "0.2"
wasm-bindgen-futures = "*"
[package.metadata.wasm-pack.profile.release]
wasm-opt = false

3
kifu/ffi/wasm/Makefile Normal file
View File

@ -0,0 +1,3 @@
all:
wasm-pack build --target web

26
kifu/ffi/wasm/src/lib.rs Normal file
View File

@ -0,0 +1,26 @@
use kifu_core::{CoreRequest, CoreResponse};
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
pub fn log(s: &str);
}
#[wasm_bindgen]
#[derive(Debug)]
pub struct CoreApp(kifu_core::CoreApp);
#[wasm_bindgen]
impl CoreApp {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
Self(kifu_core::CoreApp::new())
}
#[wasm_bindgen]
pub async fn dispatch(&self, param: &JsValue) -> JsValue {
let request: CoreRequest = serde_wasm_bindgen::from_value(param.clone()).unwrap();
serde_wasm_bindgen::to_value(&self.0.dispatch(request).await).unwrap()
}
}

View File

@ -9,17 +9,16 @@ screenplay = []
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] } adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] }
async-channel = { version = "2" } cairo-rs = { version = "0.18" }
cairo-rs = { version = "0.18" } gio = { version = "0.18" }
gio = { version = "0.18" } glib = { version = "0.18" }
glib = { version = "0.18" } gtk = { version = "0.7", package = "gtk4", features = [ "v4_8" ] }
gtk = { version = "0.7", package = "gtk4", features = [ "v4_8" ] } image = { version = "0.24" }
image = { version = "0.24" } kifu-core = { path = "../core" }
kifu-core = { path = "../core" } pango = { version = "*" }
pango = { version = "*" } sgf = { path = "../../sgf" }
sgf = { path = "../../sgf" } tokio = { version = "1.26", features = [ "full" ] }
tokio = { version = "1.26", features = [ "full" ] }
[build-dependencies] [build-dependencies]
glib-build-tools = "0.17" glib-build-tools = "0.17"

View File

@ -1,7 +1,7 @@
fn main() { fn main() {
glib_build_tools::compile_resources( glib_build_tools::compile_resources(
&["resources"], &["resources"],
"gresources.xml", "resources/gresources.xml",
"com.luminescent-dreams.kifu-gtk.gresource", "com.luminescent-dreams.kifu-gtk.gresource",
); );
} }

View File

@ -1,17 +0,0 @@
{ gtkNativeInputs }:
attrs:
let
gsettingsDir = "${attrs.crateName}-${attrs.version}";
in {
nativeBuildInputs = gtkNativeInputs;
postInstall = ''
install -Dt $out/share/applications resources/kifu.desktop
install -Dt $out/gsettings-schemas/${gsettingsDir}/glib-2.0/schemas resources/com.luminescent-dreams.kifu.gschema.xml
glib-compile-schemas $out/gsettings-schemas/${gsettingsDir}/glib-2.0/schemas
'';
# preFixup = ''
# gappsWrapperArgs+=(
# --prefix XDG_DATA_DIRS : $out/gsettings-schemas/${gsettingsDir}
# )
# '';
}

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<schemalist>
<schema id="com.luminescent-dreams.kifu-gtk.dev" path="/com/luminescent-dreams/kifu-gtk/dev/">
<key name="database-path" type="s">
<default>""</default>
<summary>Path to the directory of games</summary>
</key>
<key name="language" type="s">
<default>""</default>
<summary>Language override, use system settings if empty</summary>
</key>
</schema>
</schemalist>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<schemalist>
<schema id="com.luminescent-dreams.kifu-gtk" path="/com/luminescent-dreams/kifu-gtk/">
<key name="database-path" type="s">
<default>""</default>
<summary>Path to the directory of games</summary>
</key>
<key name="language" type="s">
<default>""</default>
<summary>Language override, use system settings if empty</summary>
</key>
</schema>
</schemalist>

View File

@ -1,5 +0,0 @@
[Desktop Entry]
Version=0.2
Type=Application
Name=Kifu
Exec=kifu

View File

@ -1,26 +1,22 @@
pub mod ui; pub mod ui;
use kifu_core::{CoreApp, CoreRequest, CoreResponse}; use kifu_core::{CoreApp, CoreRequest, CoreResponse};
use std::sync::Arc; use std::sync::Arc;
use tokio::{spawn, runtime::Runtime}; use tokio::runtime::Runtime;
#[derive(Clone)] #[derive(Clone)]
pub struct CoreApi { pub struct CoreApi {
pub notification_tx: async_channel::Sender<CoreResponse>, pub gtk_tx: gtk::glib::Sender<CoreResponse>,
pub rt: Arc<Runtime>, pub rt: Arc<Runtime>,
pub core: CoreApp, pub core: CoreApp,
} }
impl CoreApi { impl CoreApi {
pub fn dispatch(&self, request: CoreRequest) { pub fn dispatch(&self, request: CoreRequest) {
/* self.rt.spawn({
spawn({
/*
let gtk_tx = self.gtk_tx.clone(); let gtk_tx = self.gtk_tx.clone();
let core = self.core.clone(); let core = self.core.clone();
async move { gtk_tx.send(core.dispatch(request).await) } async move { gtk_tx.send(core.dispatch(request).await) }
*/
}); });
*/
} }
} }

View File

@ -1,5 +1,5 @@
use adw::prelude::*; use adw::prelude::*;
use kifu_core::{CoreApp, CoreRequest, CoreResponse, DatabasePath, Config, ConfigOption}; use kifu_core::{CoreApp, CoreRequest, CoreResponse};
use kifu_gtk::{ use kifu_gtk::{
perftrace, perftrace,
ui::{AppWindow, ConfigurationPage, Home, PlayingField}, ui::{AppWindow, ConfigurationPage, Home, PlayingField},
@ -7,12 +7,6 @@ use kifu_gtk::{
}; };
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
const APP_ID_DEV: &str = "com.luminescent-dreams.kifu-gtk.dev";
const APP_ID_PROD: &str = "com.luminescent-dreams.kifu-gtk";
const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/kifu-gtk/";
fn handle_response(api: CoreApi, app_window: &AppWindow, message: CoreResponse) { fn handle_response(api: CoreApi, app_window: &AppWindow, message: CoreResponse) {
let playing_field = Arc::new(RwLock::new(None)); let playing_field = Arc::new(RwLock::new(None));
match message { match message {
@ -54,17 +48,6 @@ fn main() {
gio::resources_register_include!("com.luminescent-dreams.kifu-gtk.gresource") gio::resources_register_include!("com.luminescent-dreams.kifu-gtk.gresource")
.expect("Failed to register resources"); .expect("Failed to register resources");
let app_id = if std::env::var_os("ENV") == Some("dev".into()) {
APP_ID_DEV
} else {
APP_ID_PROD
};
let settings = gio::Settings::new(app_id);
let db_path: String = settings.string("database-path").into();
let mut config = Config::new();
config.set(ConfigOption::DatabasePath(db_path.into()));
let runtime = Arc::new( let runtime = Arc::new(
tokio::runtime::Builder::new_multi_thread() tokio::runtime::Builder::new_multi_thread()
.enable_all() .enable_all()
@ -72,7 +55,6 @@ fn main() {
.unwrap(), .unwrap(),
); );
/*
let config_path = std::env::var("CONFIG") let config_path = std::env::var("CONFIG")
.map(std::path::PathBuf::from) .map(std::path::PathBuf::from)
.or({ .or({
@ -84,18 +66,15 @@ fn main() {
}) })
}) })
.expect("no config path could be found"); .expect("no config path could be found");
*/
let core = CoreApp::new(config); let core = CoreApp::new(config_path);
/*
let core_handle = runtime.spawn({ let core_handle = runtime.spawn({
let core = core.clone(); let core = core.clone();
async move { async move {
core.run().await; core.run().await;
} }
}); });
*/
let app = adw::Application::builder() let app = adw::Application::builder()
.application_id("com.luminescent-dreams.kifu-gtk") .application_id("com.luminescent-dreams.kifu-gtk")
@ -105,16 +84,13 @@ fn main() {
app.connect_activate({ app.connect_activate({
let runtime = runtime.clone(); let runtime = runtime.clone();
move |app| { move |app| {
let (notification_tx, notification_rx) = async_channel::unbounded::<CoreResponse>();
/*
let (gtk_tx, gtk_rx) = let (gtk_tx, gtk_rx) =
gtk::glib::MainContext::channel::<CoreResponse>(gtk::glib::Priority::DEFAULT); gtk::glib::MainContext::channel::<CoreResponse>(gtk::glib::Priority::DEFAULT);
*/
let app_window = AppWindow::new(app); let app_window = AppWindow::new(app);
let api = CoreApi { let api = CoreApi {
notification_tx, gtk_tx,
rt: runtime.clone(), rt: runtime.clone(),
core: core.clone(), core: core.clone(),
}; };
@ -130,7 +106,6 @@ fn main() {
app_window.window.present(); app_window.window.present();
/*
gtk_rx.attach(None, { gtk_rx.attach(None, {
let api = api.clone(); let api = api.clone();
move |message| { move |message| {
@ -140,7 +115,6 @@ fn main() {
glib::ControlFlow::Continue glib::ControlFlow::Continue
} }
}); });
*/
api.dispatch(CoreRequest::Home); api.dispatch(CoreRequest::Home);
} }
@ -149,5 +123,5 @@ fn main() {
println!("running the gtk loop"); println!("running the gtk loop");
app.run(); app.run();
/* let _ = runtime.block_on(core_handle); */ let _ = runtime.block_on(core_handle);
} }

16
kifu/pwa/Makefile Normal file
View File

@ -0,0 +1,16 @@
release: kifu-wasm core-types
NODE_ENV=production npm run build
dev: kifu-wasm core-types
npm run build
kifu-wasm:
pushd ../ffi/wasm && make && popd
core-types:
pushd ../core-types && make && popd
server:
npx http-server ./dist

1916
kifu/pwa/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

23
kifu/pwa/package.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "kifu-pwa",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"author": "Savanni D'Gerinel <savanni@luminescent-dreams.com>",
"license": "GPL-3.0-or-later",
"devDependencies": {
"@types/lodash": "^4.14.194",
"copy-webpack-plugin": "^11.0.0",
"ts-loader": "^9.4.2",
"typescript": "^5.0.4",
"webpack": "^5.82.0",
"webpack-cli": "^5.1.0"
},
"dependencies": {
"lodash": "^4.17.21"
}
}

View File

@ -0,0 +1 @@
export const assertNever = (_: never) => {};

View File

@ -0,0 +1,262 @@
import { BoardElement, Color, Size, CoreRequest } from "core-types";
import { assertNever } from "../assertNever";
const MARGIN = 20;
const BOARD_WIDTH = 800;
const BOARD_HEIGHT = 800;
type Pixel = { x: number; y: number };
type Coordinate = { column: number; row: number };
export interface GoBoardProps {
board: BoardElement;
onClick: (_: CoreRequest) => void;
}
export class GoBoard {
private board: BoardElement;
private pen: Pen;
private cursorLocation: Coordinate | null;
private backgroundBoard: HTMLCanvasElement;
private currentBoardState: HTMLCanvasElement;
canvas: HTMLCanvasElement;
constructor({ board, onClick }: GoBoardProps) {
this.board = board;
this.canvas = document.createElement("canvas");
this.canvas.classList.add("board");
this.canvas.width = BOARD_WIDTH;
this.canvas.height = BOARD_HEIGHT;
this.pen = new Pen(
this.canvas.width,
this.canvas.height,
MARGIN,
this.board.size.width,
this.board.size.height
);
this.backgroundBoard = document.createElement("canvas");
this.backgroundBoard.width = BOARD_WIDTH;
this.backgroundBoard.height = BOARD_HEIGHT;
this.renderBackgroundBoard();
this.currentBoardState = document.createElement("canvas");
this.currentBoardState.width = BOARD_WIDTH;
this.currentBoardState.height = BOARD_HEIGHT;
this.cursorLocation = null;
this.canvas.onmousemove = (event) => {
const bounds = this.canvas.getBoundingClientRect();
const coordinate = {
x: event.clientX - bounds.x,
y: event.clientY - bounds.y,
};
let address = this.pen.address(coordinate);
if (this.cursorLocation != address) {
this.cursorLocation = this.pen.address(coordinate);
this.renderBoard();
}
};
this.canvas.onclick = (_) => {
if (this.cursorLocation) {
const intersection =
this.board.spaces[boardAddress(this.board.size, this.cursorLocation)];
switch (intersection.type) {
case "Unplayable":
break;
case "Empty":
onClick(intersection.content);
break;
case "Filled":
break;
default:
assertNever(intersection);
}
}
};
}
setBoard(board: BoardElement) {
this.board = board;
this.pen = new Pen(
this.canvas.width,
this.canvas.height,
MARGIN,
this.board.size.width,
this.board.size.height
);
this.renderBoard();
}
renderBoard() {
// Cache:
// - Standard blank board with background
// - Current board state without the ghost stone
const ctx = this.canvas.getContext("2d");
if (!ctx) {
alert("could not get the canvas context");
return null;
}
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
ctx.drawImage(this.backgroundBoard, 0, 0);
let col = 0;
let row = 0;
for (let idx = 0; idx < this.board.spaces.length; idx++) {
const space = this.board.spaces[idx];
switch (space.type) {
case "Filled":
this.pen.stone(ctx, { column: col, row: row }, space.content.color);
break;
default:
break;
}
col = col + 1;
if (col == this.board.size.width) {
col = 0;
row = row + 1;
}
}
if (this.cursorLocation) {
this.pen.ghostStone(ctx, this.cursorLocation, Color.White);
}
}
private renderBackgroundBoard() {
const ctx = this.backgroundBoard.getContext("2d");
if (!ctx) {
alert("could not get the background canvas context");
return;
}
ctx.lineWidth = 2;
ctx.strokeStyle = "black";
ctx.beginPath();
for (var col = 0; col < this.board.size.width; col++) {
ctx.moveTo(MARGIN + col * this.pen.hspaceBetween, MARGIN);
ctx.lineTo(
MARGIN + col * this.pen.hspaceBetween,
MARGIN + (this.board.size.height - 1) * this.pen.vspaceBetween
);
}
for (var row = 0; row < this.board.size.height; row++) {
ctx.moveTo(MARGIN, MARGIN + row * this.pen.vspaceBetween);
ctx.lineTo(
MARGIN + (this.board.size.width - 1) * this.pen.hspaceBetween,
MARGIN + row * this.pen.vspaceBetween
);
}
ctx.closePath();
ctx.stroke();
this.pen.starPoint(ctx, { column: 3, row: 3 });
this.pen.starPoint(ctx, { column: 3, row: 9 });
this.pen.starPoint(ctx, { column: 3, row: 15 });
this.pen.starPoint(ctx, { column: 9, row: 3 });
this.pen.starPoint(ctx, { column: 9, row: 9 });
this.pen.starPoint(ctx, { column: 9, row: 15 });
this.pen.starPoint(ctx, { column: 15, row: 3 });
this.pen.starPoint(ctx, { column: 15, row: 9 });
this.pen.starPoint(ctx, { column: 15, row: 15 });
}
}
class Pen {
margin: number;
hspaceBetween: number;
vspaceBetween: number;
constructor(
width: number,
height: number,
margin: number,
columns: number,
rows: number
) {
this.margin = margin;
this.hspaceBetween = (width - margin * 2) / (columns - 1);
this.vspaceBetween = (height - margin * 2) / (rows - 1);
}
starPoint(ctx: CanvasRenderingContext2D, addr: Coordinate) {
ctx.fillStyle = "rgba(0, 0, 0, 1.0);";
ctx.beginPath();
const pixel = this.position(addr);
ctx.moveTo(pixel.x, pixel.y);
ctx.arc(pixel.x, pixel.y, 5, 0, 2 * Math.PI);
ctx.closePath();
ctx.fill();
}
ghostStone(ctx: CanvasRenderingContext2D, addr: Coordinate, color: Color) {
switch (color) {
case Color.White:
ctx.fillStyle = "rgba(230, 230, 230, 0.5)";
break;
case Color.Black:
ctx.fillStyle = "rgba(0, 0, 0, 0.5)";
break;
}
this.drawStone(ctx, addr);
}
stone(ctx: CanvasRenderingContext2D, addr: Coordinate, color: Color) {
switch (color) {
case Color.White:
ctx.fillStyle = "rgb(230, 230, 230)";
break;
case Color.Black:
ctx.fillStyle = "rgb(0, 0, 0)";
break;
}
this.drawStone(ctx, addr);
}
drawStone(ctx: CanvasRenderingContext2D, addr: Coordinate) {
ctx.beginPath();
const radius = this.hspaceBetween / 2 - 2;
const pixel = this.position(addr);
ctx.moveTo(pixel.x, pixel.y);
ctx.arc(pixel.x, pixel.y, radius, 0, 2.0 * Math.PI);
ctx.closePath();
ctx.fill();
}
position(addr: Coordinate): Pixel {
return {
x: this.margin + addr.column * this.hspaceBetween,
y: this.margin + addr.row * this.vspaceBetween,
};
}
address(pixel: Pixel): Coordinate | null {
if (
Math.round(pixel.x) < this.margin ||
Math.round(pixel.y) < this.margin
) {
return null;
} else {
return {
column: Math.round(
(Math.round(pixel.x) - this.margin) / this.hspaceBetween
),
row: Math.round(
(Math.round(pixel.y) - this.margin) / this.vspaceBetween
),
};
}
}
}
const boardAddress = (size: Size, coordinate: Coordinate): number =>
coordinate.column + size.width * coordinate.row;

24
kifu/pwa/src/coreApi.ts Normal file
View File

@ -0,0 +1,24 @@
import init, { CoreApp } from "kifu-wasm";
import { CoreResponse, CoreRequest, PlayingFieldView } from "core-types";
export class CoreApi {
core: CoreApp;
constructor() {
let app = new CoreApp();
this.core = app;
}
async dispatch(request: CoreRequest): Promise<CoreResponse> {
return await this.core.dispatch(request);
}
async playingField(): Promise<PlayingFieldView> {
return (await this.dispatch({ type: "PlayingField" })).content;
}
}
export const initCore = async (): Promise<CoreApi> => {
await init();
return new CoreApi();
};

BIN
kifu/pwa/src/icon512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 KiB

20
kifu/pwa/src/index.html Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<link rel="manifest" href="/manifest.json">
<link rel="stylesheet" href="kifu.css">
<title>Kifu</title>
<script type="module" src="kifu-bundle.js"></script>
</head>
<body>
<h1> Kifu </h1>
<div id="root"></div>
<script>
if('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js', { scope: '/' });
}
</script>
</body>
</html>

22
kifu/pwa/src/kifu.css Normal file
View File

@ -0,0 +1,22 @@
html {
background: rgb(243, 243, 243);
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 15pt;
}
html, body {
height: 100%;
margin: 0;
}
body {
display: grid;
}
canvas {
border: 1px solid black;
}
.board {
background-color: rgb(150, 150, 150);
}

62
kifu/pwa/src/main.ts Normal file
View File

@ -0,0 +1,62 @@
import { GoBoard } from "./components/Board";
import { CoreRequest, CoreResponse } from "core-types";
import { CoreApi, initCore } from "./coreApi";
// import { assertNever } from "./assertNever";
class UIState {
private currentView: GoBoard | null;
private rootElement: HTMLElement;
coreApi: CoreApi;
constructor(coreApi: CoreApi, root: HTMLElement) {
this.currentView = null;
this.rootElement = root;
this.coreApi = coreApi;
if (!root) {
console.log("root element not found");
return;
}
}
processResponse(response: CoreResponse) {
switch (response.type) {
case "PlayingFieldView":
if (this.currentView) {
this.currentView.setBoard(response.content.board);
} else {
this.currentView = new GoBoard({
board: response.content.board,
onClick: async (request: CoreRequest) => {
const response = await this.coreApi.dispatch(request);
this.processResponse(response);
},
});
this.rootElement?.appendChild(this.currentView.canvas);
this.currentView.renderBoard();
}
break;
default:
console.log("impossible branch: ", response);
alert("impossible branch");
// assertNever(response);
break;
}
}
}
const main = async () => {
let coreApi = await initCore();
let response = await coreApi.dispatch({ type: "PlayingField" });
const root = document.getElementById("root");
if (!root) {
console.log("root element not present");
return;
}
const uiState = new UIState(coreApi, root);
uiState.processResponse(response);
};
main();

View File

@ -0,0 +1,17 @@
{
"lang": "en-us",
"name": "Kifu",
"short_name": "Kifu",
"description": "An app for playing Go",
"start_url": "/",
"background_color": "#2f3d58",
"theme_color": "#2f3d58",
"orientation": "any",
"display": "standalone",
"icons": [
{
"src": "/icon512.png",
"sizes": "512x512"
}
]
}

29
kifu/pwa/src/sw.js Normal file
View File

@ -0,0 +1,29 @@
const CACHE_NAME = 'kifu-pwa-3';
self.addEventListener('install', event => {
event.waitUntil((async () => {
const cache = await caches.open(CACHE_NAME);
cache.addAll([
'/',
'/kifu-bundle.js',
'/kifu.css',
]);
})());
});
self.addEventListener('fetch', event => {
event.respondWith((async () => {
const cache = await caches.open(CACHE_NAME);
const cachedResponse = await cache.match(event.request);
if (cachedResponse) {
return cachedResponse;
} else {
try {
const fetchResponse = await fetch(event.request);
cache.put(event.request, fetchResponse.clone());
return fetchResponse;
} catch (e) {
}
}
})());
});

View File

@ -0,0 +1,28 @@
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
mode: "development",
entry: {
"kifu-bundle": "./src/main.ts",
sw: "./src/sw.js",
},
module: {
rules: [
{ test: /\.ts$/, use: "ts-loader", exclude: /node_modules/ },
{ test: /\.wasm$/, type: "asset/inline" }
],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: "src/index.html" },
{ from: "src/kifu.css" },
{ from: "src/manifest.json" },
{ from: "src/icon512.png" }
]
})
],
resolve: {
extensions: ['.ts'],
}
}

1981
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

8
package.json Normal file
View File

@ -0,0 +1,8 @@
{
"name": "tools",
"workspaces": [
"kifu/ffi/wasm/pkg",
"kifu/core-types",
"kifu/pwa"
]
}

11
tsconfig.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"skipLibCheck": true
}
}