Init Main project

This commit is contained in:
tyuXX 2026-11-15 12:57:24 +03:00
commit 9e581ae67f
220 changed files with 253987 additions and 0 deletions

57
src/client/router.ts Normal file
View file

@ -0,0 +1,57 @@
// (Tech support with -4 hours of sleep and 6th mug of coffee) Uhm, sir, have you tried turning it off and on again?
// Oh.
// Oh...
import { type ScreenName, setCurrentScreen } from "./state.js";
import { clear, hideTooltip } from "./ui.js";
export type ScreenRenderer = (
appEl: HTMLElement,
params: Record<string, any>,
) => (() => void) | void;
const appEl = document.getElementById("app") as HTMLElement;
let activeCleanup: (() => void) | null = null;
let screenRenderers: Partial<Record<ScreenName, ScreenRenderer>> = {};
const RIGHT_SIDEBAR_OFFSET_PX: Partial<Record<ScreenName, number>> = {
dashboard: 370,
builder: 440,
config: 440,
worldMap: 340,
};
export function registerScreenRenderers(
renderers: Partial<Record<ScreenName, ScreenRenderer>>,
): void {
screenRenderers = renderers;
}
export function navigate(
screen: ScreenName,
params: Record<string, any> = {},
): void {
if (activeCleanup) {
try {
activeCleanup();
} catch (err) {
console.warn("Cleanup error:", err);
}
activeCleanup = null;
}
setCurrentScreen(screen);
const sidebarOffset = RIGHT_SIDEBAR_OFFSET_PX[screen] ?? 0;
document.documentElement.style.setProperty(
"--right-sidebar-offset",
`${sidebarOffset}px`,
);
document.documentElement.classList.toggle(
"has-right-sidebar",
sidebarOffset > 0,
);
clear(appEl);
hideTooltip();
const cleanup = screenRenderers[screen]?.(appEl, params);
if (typeof cleanup === "function") {
activeCleanup = cleanup;
}
}