Move RTS menu panel authority to daemon
This commit is contained in:
parent
e4b155576f
commit
b86635fda5
15 changed files with 361 additions and 195 deletions
|
|
@ -5,7 +5,6 @@ import {
|
|||
type EveSurfaceComponent,
|
||||
} from "../node_modules/@gamecult/eve-browser-lowering/dist/index.js";
|
||||
import type {
|
||||
AetheriaMenuSurfaceComponent,
|
||||
AetheriaMenuSurfaceDocument,
|
||||
AetheriaRtsApi,
|
||||
Viewport,
|
||||
|
|
@ -22,7 +21,6 @@ declare global {
|
|||
const host = requiredElement<HTMLElement>("#eve-surface-host");
|
||||
const statusEl = requiredElement<HTMLElement>("#status");
|
||||
let latestEveSurfaceKey = "";
|
||||
let activeMainMenuSurfaceId = "aetheria.main_menu.root";
|
||||
let renderDaemonEveSurfaceNow: (() => Promise<void>) | null = null;
|
||||
let eveSurfacePoll: number | null = null;
|
||||
|
||||
|
|
@ -48,14 +46,13 @@ async function showDaemonEveSurface(): Promise<void> {
|
|||
const surface = await window.aetheriaRts.eveSurface({
|
||||
recordKey: "eve:surface:aetheria.daemon.game",
|
||||
});
|
||||
const loweredSurface = withActiveMainMenuPanel(surface, activeMainMenuSurfaceId);
|
||||
const surfaceKey = `${surface.providerId}:${surface.surface.id}:${surface.version}:${surface.updatedAtUtc}:${activeMainMenuSurfaceId}`;
|
||||
const surfaceKey = `${surface.providerId}:${surface.surface.id}:${surface.version}:${surface.updatedAtUtc}`;
|
||||
if (surfaceKey === latestEveSurfaceKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
latestEveSurfaceKey = surfaceKey;
|
||||
renderEveSurface(loweredSurface, host, {
|
||||
renderEveSurface(surface, host, {
|
||||
body: document.body,
|
||||
assetUrlResolver: resolveAetheriaAssetUrl,
|
||||
clientId: "aetheria.rts.electron",
|
||||
|
|
@ -79,70 +76,6 @@ async function showDaemonEveSurface(): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
async function showMainMenuPanel(surfaceId: string): Promise<void> {
|
||||
activeMainMenuSurfaceId = normalizeMainMenuSurfaceId(surfaceId);
|
||||
latestEveSurfaceKey = "";
|
||||
if (renderDaemonEveSurfaceNow) {
|
||||
await renderDaemonEveSurfaceNow();
|
||||
return;
|
||||
}
|
||||
|
||||
await showDaemonEveSurface();
|
||||
}
|
||||
|
||||
function normalizeMainMenuSurfaceId(surfaceId: string): string {
|
||||
switch (surfaceId) {
|
||||
case "aetheria.main_menu.settings":
|
||||
case "aetheria.main_menu.player_settings":
|
||||
case "aetheria.main_menu.verse_settings":
|
||||
case "aetheria.main_menu.input_settings":
|
||||
return surfaceId;
|
||||
default:
|
||||
return "aetheria.main_menu.root";
|
||||
}
|
||||
}
|
||||
|
||||
function withActiveMainMenuPanel(
|
||||
document: AetheriaMenuSurfaceDocument,
|
||||
panelSurfaceId: string,
|
||||
): AetheriaMenuSurfaceDocument {
|
||||
return {
|
||||
...document,
|
||||
surface: {
|
||||
...document.surface,
|
||||
root: rewriteMainMenuPanelSlot(document.surface.root, panelSurfaceId),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
type MutableEveComponent = AetheriaMenuSurfaceComponent & {
|
||||
layout?: Record<string, string>;
|
||||
style?: Record<string, string>;
|
||||
};
|
||||
|
||||
function rewriteMainMenuPanelSlot(
|
||||
component: AetheriaMenuSurfaceComponent,
|
||||
panelSurfaceId: string,
|
||||
): AetheriaMenuSurfaceComponent {
|
||||
const source = component as MutableEveComponent;
|
||||
const props = source.props ?? {};
|
||||
const embeddedDocuments = source.embeddedDocuments ?? [];
|
||||
const isMainMenuSlot = props.slotId === "mainMenuPanel" ||
|
||||
embeddedDocuments.some(slot => slot.slotId === "mainMenuPanel");
|
||||
return {
|
||||
...source,
|
||||
props: isMainMenuSlot
|
||||
? { ...props, documentId: panelSurfaceId }
|
||||
: props,
|
||||
embeddedDocuments: isMainMenuSlot
|
||||
? embeddedDocuments.map(slot => slot.slotId === "mainMenuPanel"
|
||||
? { ...slot, documentId: panelSurfaceId }
|
||||
: slot)
|
||||
: source.embeddedDocuments,
|
||||
children: source.children.map(child => rewriteMainMenuPanelSlot(child, panelSurfaceId)),
|
||||
};
|
||||
}
|
||||
|
||||
async function resolveEveDocument(
|
||||
request: EveEmbeddedDocumentRequest,
|
||||
component: EveSurfaceComponent,
|
||||
|
|
@ -219,11 +152,6 @@ function resolveAetheriaAssetUrl(uri: string): string {
|
|||
}
|
||||
|
||||
async function submitEveCommand(intent: EveCommandIntent): Promise<void> {
|
||||
if (intent.command.startsWith("aetheria.main_menu.")) {
|
||||
handleMenuCommand(intent.command);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const receipt = await window.aetheriaRts.submitEveCommand({
|
||||
providerId: intent.providerId,
|
||||
|
|
@ -234,37 +162,17 @@ async function submitEveCommand(intent: EveCommandIntent): Promise<void> {
|
|||
payload: intent.payload,
|
||||
});
|
||||
setStatus(`${intent.command}: ${receipt.accepted ? "submitted" : "rejected"}`);
|
||||
latestEveSurfaceKey = "";
|
||||
if (renderDaemonEveSurfaceNow) {
|
||||
window.setTimeout(() => {
|
||||
void renderDaemonEveSurfaceNow?.();
|
||||
}, 120);
|
||||
}
|
||||
} catch (error) {
|
||||
setStatus(error instanceof Error ? error.message : `Failed to submit ${intent.command}.`);
|
||||
}
|
||||
}
|
||||
|
||||
function handleMenuCommand(command: string): void {
|
||||
switch (command) {
|
||||
case "aetheria.main_menu.root.show_settings":
|
||||
void showMainMenuPanel("aetheria.main_menu.settings");
|
||||
return;
|
||||
case "aetheria.main_menu.settings.show_player_settings":
|
||||
void showMainMenuPanel("aetheria.main_menu.player_settings");
|
||||
return;
|
||||
case "aetheria.main_menu.settings.show_verse_settings":
|
||||
void showMainMenuPanel("aetheria.main_menu.verse_settings");
|
||||
return;
|
||||
case "aetheria.main_menu.settings.show_input_settings":
|
||||
void showMainMenuPanel("aetheria.main_menu.input_settings");
|
||||
return;
|
||||
case "aetheria.main_menu.settings.back_to_settings":
|
||||
void showMainMenuPanel("aetheria.main_menu.settings");
|
||||
return;
|
||||
case "aetheria.main_menu.settings.back_to_main":
|
||||
void showMainMenuPanel("aetheria.main_menu.root");
|
||||
return;
|
||||
default:
|
||||
setStatus(`Aetheria Starbridge: ${command || "no command"}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function wireWindowControls(): void {
|
||||
document.querySelectorAll<HTMLButtonElement>("[data-window-control]").forEach(button => {
|
||||
if (button.dataset.windowControlWired === "true") {
|
||||
|
|
|
|||
Loading…
Reference in a new issue