Skip to content

Commit bba2d10

Browse files
authored
publish remote client (#58)
* add panic hook * settler movement restriction * remote server * publish client * publish client * publish client * publish client * add dependabot.yml * fmt * publish client * publish client * fix end turn * publish client * publish client * publish client * publish client
1 parent 6d112e5 commit bba2d10

28 files changed

+209
-271
lines changed

.github/dependabot.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
- package-ecosystem: cargo
8+
directory: "/"
9+
schedule:
10+
interval: daily
11+
12+

.github/workflows/release.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,18 @@ jobs:
2222
- uses: jetli/[email protected]
2323
with:
2424
version: 'latest'
25-
# see https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
26-
- run: ./scripts/publish-server.sh ${{ github.event.release.tag_name }}
25+
- uses: jetli/[email protected]
26+
with:
27+
version: 'latest'
28+
- name: Publish Server
29+
# see https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
30+
run: |
31+
./scripts/publish-server.sh ${{ github.event.release.tag_name }}
32+
env:
33+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
34+
- name: Publish Client
35+
# rustup target add wasm32-unknown-unknown # automatically done by wasm-pack
36+
run: |
37+
./scripts/publish-client.sh ${{ github.event.release.tag_name }}
2738
env:
2839
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

+7-17
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,10 @@
99
- `cd client`
1010
- `cargo run`.
1111

12-
### Run local web client
12+
### Run remote with boardgamers-mono web client locally
1313

14-
- `cd client`
15-
- `./build-local.sh local_client`
16-
- `cd dist`
17-
- `basic-http-server .`
18-
- open `http://localhost:4000` in a browser.
19-
20-
### Run remote web client locally
21-
22-
- `cd client`
23-
- `./build-remote.sh`
24-
- `cd remote_client/dist`
25-
- `basic-http-server .`
14+
- `./scripts/build-remote-client.sh`
15+
- `cd client/js/dist && basic-http-server .`
2616
- `google-chrome --disable-web-security --user-data-dir=/tmp http://localhost:8612`
2717

2818
### Server wrapper
@@ -45,8 +35,8 @@
4535
- `docker run -d -p 27017:27017 mongo:4.4`
4636
- `cd apps/api && pnpm seed && echo cron=1 > .env`
4737
- `pnpm dev --filter @bgs/api --filter @bgs/game-server --filter @bgs/web --filter @bgs/admin`
48-
- admin: http://localhost:3000 ([email protected]/password)
49-
- user: http://localhost:8612/ ([email protected]/password)
38+
- admin: http://localhost:3000 ([email protected] / password)
39+
- user: http://localhost:8612/ ([email protected] / password)
5040

5141
old
5242

@@ -102,7 +92,7 @@ diff --git a/apps/api/app/resources.ts b/apps/api/app/resources.ts
10292
const viewer: ViewerInfo =
10393
gameInfo?.viewer?.alternate?.url && ctx.query.alternate === "1" ? gameInfo?.viewer.alternate : gameInfo.viewer;
10494
- const viewerUrl = ctx.query.customViewerUrl || viewer.url;
105-
+ const viewerUrl = "/home/gregor/source/clash/client/remote_client/index.js";
95+
+ const viewerUrl = "http://127.0.0.1:4000/client.js";
10696

10797
ctx.body = `
10898
<html>
@@ -148,7 +138,7 @@ GameInfo.json (for now)
148138
"preferences": [],
149139
"rules": "",
150140
"viewer": {
151-
"url": "http://localhost:4000/client.js",
141+
"url": "//cdn.jsdelivr.net/npm/@boardgamers/[email protected]/client.js",
152142
"topLevelVariable": "clash",
153143
"dependencies": {
154144
"scripts": [],

client/Cargo.lock

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/Cargo.toml

+1-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ debug = true
1414
[profile.release]
1515
debug = true
1616

17-
[features]
18-
# disable file import and export
19-
wasm = []
20-
21-
# may be needed for remote client
22-
#[lib]
23-
#name = "client"
24-
#crate-type = ["cdylib", "rlib"]
25-
2617
[dependencies]
2718
macroquad = "0.4.2"
2819
hex2d = "1.1.0"
@@ -35,6 +26,7 @@ lazy_static = "1.4.0"
3526
log = "0.4.20"
3627
async-std = "1.13.0"
3728
serde-wasm-bindgen = "0.6.5"
29+
console_error_panic_hook = "0.1.7"
3830

3931
[[bin]]
4032
name = "local_client"

client/build-local.sh

-153
This file was deleted.
File renamed without changes.

client/remote_client/package-lock.json client/js/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/js/package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@boardgamers/clash-client",
3+
"description": "A client for Clash of Cultures",
4+
"version": "0.1.0",
5+
"license": "MIT",
6+
"repository": {
7+
"type": "git",
8+
"url": "[email protected]:boardgamers/clash.git"
9+
},
10+
"files": [
11+
"assets/",
12+
"client.js",
13+
"client.wasm"
14+
],
15+
"main": "index.js",
16+
"homepage": "https://www.boardgamers.space/",
17+
"scripts": {
18+
"build": "webpack"
19+
},
20+
"devDependencies": {
21+
"webpack": "^5.94.0",
22+
"webpack-cli": "^5.1.4"
23+
},
24+
"dependencies": {
25+
"events": "^3.3.0"
26+
}
27+
}

client/remote_client/src/control.js client/js/src/control.js

+14
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ export class Control extends EventEmitter {
55
super();
66
this.state = null;
77
this.player_index = null;
8+
this._assets_url = null;
89

910
this.addListener("state", (data) => {
1011
this.state = data;
1112
});
13+
// When we receive log slices, when executing a move
14+
this.addListener("gamelog", (logData) => {
15+
// Ignore the log data and tell the backend we want the new state
16+
this.emit("fetchState");
17+
});
1218
this.addListener("state:updated", () => {
1319
this.emit("fetchState");
1420
});
@@ -36,6 +42,14 @@ export class Control extends EventEmitter {
3642
send_ready() {
3743
this.emit("ready");
3844
}
45+
46+
get assets_url() {
47+
return this._assets_url;
48+
}
49+
50+
set assets_url(value) {
51+
this._assets_url = value;
52+
}
3953
}
4054

4155
export function get_control() {

client/remote_client/src/index.js client/js/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ window.clash = {
66
const control = new Control();
77
window.clash_control = control;
88

9-
run(selector);
9+
run(selector, control);
1010

1111
return control;
1212
},

client/remote_client/src/run.js client/js/src/run.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function dynamicallyLoadScript(url, onload) {
88
document.head.appendChild(script);
99
}
1010

11-
export async function run(selector) {
11+
export async function run(selector, control) {
1212
const root = document.querySelector(selector);
1313
const canvas = document.createElement("canvas");
1414
canvas.setAttribute("id", "glcanvas");
@@ -31,7 +31,9 @@ export async function run(selector) {
3131
version: "0.0.1",
3232
name: "wbg",
3333
});
34-
const url = document.head.getElementsByTagName("script")[0].src.replace("client.js", "client.wasm");
34+
const src = document.head.getElementsByTagName("script")[0].src;
35+
control.assets_url = src.replace("client.js", "assets/");
36+
const url = src.replace("client.js", "client.wasm");
3537
console.log("Loading wasm from", url);
3638
await load(url);
3739
});
File renamed without changes.

0 commit comments

Comments
 (0)