Skip to content

Commit

Permalink
publish remote client (#58)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zeitlinger authored Oct 2, 2024
1 parent 6d112e5 commit bba2d10
Show file tree
Hide file tree
Showing 28 changed files with 209 additions and 271 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: weekly
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily


15 changes: 13 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@ jobs:
- uses: jetli/[email protected]
with:
version: 'latest'
# see https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
- run: ./scripts/publish-server.sh ${{ github.event.release.tag_name }}
- uses: jetli/[email protected]
with:
version: 'latest'
- name: Publish Server
# see https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
run: |
./scripts/publish-server.sh ${{ github.event.release.tag_name }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish Client
# rustup target add wasm32-unknown-unknown # automatically done by wasm-pack
run: |
./scripts/publish-client.sh ${{ github.event.release.tag_name }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
24 changes: 7 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@
- `cd client`
- `cargo run`.

### Run local web client
### Run remote with boardgamers-mono web client locally

- `cd client`
- `./build-local.sh local_client`
- `cd dist`
- `basic-http-server .`
- open `http://localhost:4000` in a browser.

### Run remote web client locally

- `cd client`
- `./build-remote.sh`
- `cd remote_client/dist`
- `basic-http-server .`
- `./scripts/build-remote-client.sh`
- `cd client/js/dist && basic-http-server .`
- `google-chrome --disable-web-security --user-data-dir=/tmp http://localhost:8612`

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

old

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

ctx.body = `
<html>
Expand Down Expand Up @@ -148,7 +138,7 @@ GameInfo.json (for now)
"preferences": [],
"rules": "",
"viewer": {
"url": "http://localhost:4000/client.js",
"url": "//cdn.jsdelivr.net/npm/@boardgamers/[email protected]/client.js",
"topLevelVariable": "clash",
"dependencies": {
"scripts": [],
Expand Down
12 changes: 12 additions & 0 deletions client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ debug = true
[profile.release]
debug = true

[features]
# disable file import and export
wasm = []

# may be needed for remote client
#[lib]
#name = "client"
#crate-type = ["cdylib", "rlib"]

[dependencies]
macroquad = "0.4.2"
hex2d = "1.1.0"
Expand All @@ -35,6 +26,7 @@ lazy_static = "1.4.0"
log = "0.4.20"
async-std = "1.13.0"
serde-wasm-bindgen = "0.6.5"
console_error_panic_hook = "0.1.7"

[[bin]]
name = "local_client"
Expand Down
153 changes: 0 additions & 153 deletions client/build-local.sh

This file was deleted.

File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions client/js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@boardgamers/clash-client",
"description": "A client for Clash of Cultures",
"version": "0.1.0",
"license": "MIT",
"repository": {
"type": "git",
"url": "[email protected]:boardgamers/clash.git"
},
"files": [
"assets/",
"client.js",
"client.wasm"
],
"main": "index.js",
"homepage": "https://www.boardgamers.space/",
"scripts": {
"build": "webpack"
},
"devDependencies": {
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"events": "^3.3.0"
}
}
14 changes: 14 additions & 0 deletions client/remote_client/src/control.js → client/js/src/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ export class Control extends EventEmitter {
super();
this.state = null;
this.player_index = null;
this._assets_url = null;

this.addListener("state", (data) => {
this.state = data;
});
// When we receive log slices, when executing a move
this.addListener("gamelog", (logData) => {
// Ignore the log data and tell the backend we want the new state
this.emit("fetchState");
});
this.addListener("state:updated", () => {
this.emit("fetchState");
});
Expand Down Expand Up @@ -36,6 +42,14 @@ export class Control extends EventEmitter {
send_ready() {
this.emit("ready");
}

get assets_url() {
return this._assets_url;
}

set assets_url(value) {
this._assets_url = value;
}
}

export function get_control() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ window.clash = {
const control = new Control();
window.clash_control = control;

run(selector);
run(selector, control);

return control;
},
Expand Down
6 changes: 4 additions & 2 deletions client/remote_client/src/run.js → client/js/src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function dynamicallyLoadScript(url, onload) {
document.head.appendChild(script);
}

export async function run(selector) {
export async function run(selector, control) {
const root = document.querySelector(selector);
const canvas = document.createElement("canvas");
canvas.setAttribute("id", "glcanvas");
Expand All @@ -31,7 +31,9 @@ export async function run(selector) {
version: "0.0.1",
name: "wbg",
});
const url = document.head.getElementsByTagName("script")[0].src.replace("client.js", "client.wasm");
const src = document.head.getElementsByTagName("script")[0].src;
control.assets_url = src.replace("client.js", "assets/");
const url = src.replace("client.js", "client.wasm");
console.log("Loading wasm from", url);
await load(url);
});
Expand Down
File renamed without changes.
Loading

0 comments on commit bba2d10

Please sign in to comment.