Skip to content

Commit

Permalink
Add forceVisualConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
irdkwmnsb committed Sep 17, 2024
1 parent 4c12d51 commit 1c71843
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions docs/frontend-tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ Examples:


- `https://host/overlay?forceWidgets=[{"type":"ScoreboardWidget","widgetId":"scoreboard","location":{"positionX":16,"positionY":16,"sizeX":1488,"sizeY":984},"settings":{"isInfinite":true,"startFromRow":1,"optimismLevel":"normal","group":"all"}}]`

## forceVisualConfig

You can pass forces visual config using the forceVisualConfig

Examples:
- `http://host/overelay?forceVisualConfig=`
2 changes: 1 addition & 1 deletion src/frontend/overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "vite",
"start": "VITE_WEBSOCKET_URL=ws://localhost:8080/api/overlay vite",
"build": "vite build",
"lint:css": "stylelint -f verbose './src/**/*.{js,jsx,ts,tsx,css,scss}'",
"lint:js": "eslint \"**/*.{js,jsx,ts,tsx}\"",
Expand Down
7 changes: 5 additions & 2 deletions src/frontend/overlay/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const WS_PROTO = window.location.protocol === "https:" ? "wss://" : "ws://";
const WS_PORT = import.meta.env.VITE_WEBSOCKET_PORT ?? window.location.port;
const VISUAL_CONFIG_URL = import.meta.env.VITE_VISUAL_CONFIG_URL ?? `${window.location.protocol}//${window.location.hostname}:${WS_PORT}/api/overlay/visualConfig.json`;

const urlParams = new URLSearchParams(window.location.search);
const queryVisualConfig = JSON.parse(urlParams.get("forceVisualConfig") ?? "{}");

const visualConfig = await fetch(VISUAL_CONFIG_URL)
.then(r => r.json())
.catch((e) => console.error("failed to load visual config: " + e)) ?? {};
Expand All @@ -17,10 +20,10 @@ const config_: typeof config = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const config: Record<string, any> = new Proxy(config_, {
get(target, key) {
return visualConfig[key] ?? target[key as string];
return queryVisualConfig[key] ?? visualConfig[key] ?? target[key as string];
},
set(target, key, value) {
target[key as string] = visualConfig[key] ?? value;
target[key as string] = queryVisualConfig[key] ?? visualConfig[key] ?? value;
return true;
}
});
Expand Down

0 comments on commit 1c71843

Please sign in to comment.