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 efd8e3d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 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=`
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 efd8e3d

Please sign in to comment.