Carry RTS body icons into Electron bindings

This commit is contained in:
Meta Vens 2026-07-04 23:22:05 +01:00
commit 4f05925bd9
5 changed files with 139 additions and 45 deletions

View file

@ -10,46 +10,6 @@ import type {
export type Viewport = CultMeshViewportRequest;
export type AetheriaMenuSurfaceRequest = {
surfaceId?: string;
inGame?: boolean;
canOpenRuntimeInputScreen?: boolean;
};
export type AetheriaMenuSurfaceDocument = {
providerId: string;
providerKind: string;
title: string;
version: number;
updatedAtUtc: string;
surface: AetheriaMenuSurfaceTree;
commands: AetheriaMenuSurfaceCommand[];
};
export type AetheriaMenuSurfaceTree = {
id: string;
root: AetheriaMenuSurfaceComponent;
styles: AetheriaMenuStyleToken[];
};
export type AetheriaMenuSurfaceComponent = {
id: string;
kind: string;
props: Record<string, string>;
children: AetheriaMenuSurfaceComponent[];
};
export type AetheriaMenuStyleToken = {
name: string;
value: string;
};
export type AetheriaMenuSurfaceCommand = {
command: string;
label: string;
transport: string;
};
export type AetheriaRuntimeSetMoveVectorRequest = {
actorEntityKey: string;
directionX: number;
@ -327,9 +287,50 @@ export type BodyView = {
y: number;
radius: number;
isAsteroidBelt: boolean;
iconAsset: AssetRef;
};
export type AetheriaMenuSurfaceRequest = {
surfaceId?: string;
inGame?: boolean;
canOpenRuntimeInputScreen?: boolean;
};
export type AetheriaMenuSurfaceDocument = {
providerId: string;
providerKind: string;
title: string;
version: number;
updatedAtUtc: string;
surface: AetheriaMenuSurfaceTree;
commands: AetheriaMenuSurfaceCommand[];
};
export type AetheriaMenuSurfaceTree = {
id: string;
root: AetheriaMenuSurfaceComponent;
styles: AetheriaMenuStyleToken[];
};
export type AetheriaMenuSurfaceComponent = {
id: string;
kind: string;
props: Record<string, string>;
children: AetheriaMenuSurfaceComponent[];
};
export type AetheriaMenuStyleToken = {
name: string;
value: string;
};
export type AetheriaMenuSurfaceCommand = {
command: string;
label: string;
transport: string;
};
export type AetheriaRtsApi = {
mapViewport(request: Viewport): Promise<ViewportResponse>;
objectsViewport(request: Viewport): Promise<ObjectsViewportResponse>;

View file

@ -116,6 +116,12 @@ export const AetheriaRtsIpcChannels = {
setTarget: "aetheria-rts:set-target",
surfaceCatalog: "aetheria-rts:surface-catalog",
surfaceCatalogIndex: "aetheria-rts:surface-catalog-index",
mainMenuSurface: "aetheria-rts:main-menu-surface",
debugSurface: "aetheria-rts:debug-surface",
debugSurfaceWatch: "aetheria-rts:debug-surface-watch",
debugSurfaceWatchStop: "aetheria-rts:debug-surface-watch-stop",
debugSurfaceChanged: "aetheria-rts:debug-surface-changed",
windowControl: "aetheria-rts:window-control",
health: "aetheria-rts:health",
} as const;
@ -1193,7 +1199,8 @@ export type AetheriaRuntimeRtsBodyViewSlot =
| "y"
| "radius"
| "isAsteroidBelt"
| "body";
| "body"
| "iconAsset";
export const aetheriaRuntimeRtsBodyViewSlots: Record<AetheriaRuntimeRtsBodyViewSlot, number> = {
bodyKey: 0,
@ -1205,6 +1212,7 @@ export const aetheriaRuntimeRtsBodyViewSlots: Record<AetheriaRuntimeRtsBodyViewS
radius: 6,
isAsteroidBelt: 7,
body: 8,
iconAsset: 9,
};
export type AetheriaRuntimeStarbridgeScenarioDocumentSlot =
@ -1681,6 +1689,7 @@ export type BodyView = {
y: number;
radius: number;
isAsteroidBelt: boolean;
iconAsset: AssetRef;
};

View file

@ -354,15 +354,17 @@ function toGravityInfluence(body: unknown[]): GravityInfluence {
}
function toBodyView(body: unknown[]): BodyView {
const kind = str(body[bodySlots.kind]);
return {
bodyKey: str(body[bodySlots.bodyKey]),
orbitKey: str(body[bodySlots.orbitKey]),
name: str(body[bodySlots.name]),
kind: str(body[bodySlots.kind]),
kind,
x: num(body[bodySlots.gravityInfluenceCenterX]),
y: num(body[bodySlots.gravityInfluenceCenterZ]),
radius: Math.max(32, num(body[bodySlots.bodyRadiusMultiplier]) * 70),
isAsteroidBelt: str(body[bodySlots.kind]).toLowerCase().includes("asteroid"),
isAsteroidBelt: kind.toLowerCase().includes("asteroid"),
iconAsset: bodyIconAsset(kind),
};
}
@ -462,6 +464,16 @@ function entityIconAsset(kind: string, controlled: boolean): AssetRef {
return spriteAsset("map.entity.ship", "Sprites/Map/ship");
}
function bodyIconAsset(kind: string): AssetRef {
const normalized = kind.trim().toLowerCase();
if (normalized.includes("sun") || normalized.includes("star"))
return spriteAsset("map.body.sun", "Sprites/Map/sun");
if (normalized.includes("asteroid"))
return spriteAsset("map.body.asteroid", "Sprites/Map/planet");
return spriteAsset("map.body.planet", "Sprites/Map/planet");
}
function itemIconAsset(itemKey: string): AssetRef {
const key = itemKey.trim();
return key.length > 0

View file

@ -73,6 +73,6 @@ contextBridge.exposeInMainWorld("aetheriaRts", {
void ipcRenderer.invoke(channels.debugSurfaceWatchStop, subscriptionId);
};
},
windowControl: action => ipcRenderer.invoke(channels.windowControl, action),
windowControl: request => ipcRenderer.invoke(channels.windowControl, request),
health: () => ipcRenderer.invoke(channels.health),
});

View file

@ -37,6 +37,12 @@ const ipcChannels = [
["setTarget", "aetheria-rts:set-target"],
["surfaceCatalog", "aetheria-rts:surface-catalog"],
["surfaceCatalogIndex", "aetheria-rts:surface-catalog-index"],
["mainMenuSurface", "aetheria-rts:main-menu-surface"],
["debugSurface", "aetheria-rts:debug-surface"],
["debugSurfaceWatch", "aetheria-rts:debug-surface-watch"],
["debugSurfaceWatchStop", "aetheria-rts:debug-surface-watch-stop"],
["debugSurfaceChanged", "aetheria-rts:debug-surface-changed"],
["windowControl", "aetheria-rts:window-control"],
["health", "aetheria-rts:health"],
];
@ -1030,6 +1036,46 @@ export type AetheriaRuntimeViewportFeedSnapshot = {
${renderRtsDocumentTypes("Viewport")}
export type AetheriaMenuSurfaceRequest = {
surfaceId?: string;
inGame?: boolean;
canOpenRuntimeInputScreen?: boolean;
};
export type AetheriaMenuSurfaceDocument = {
providerId: string;
providerKind: string;
title: string;
version: number;
updatedAtUtc: string;
surface: AetheriaMenuSurfaceTree;
commands: AetheriaMenuSurfaceCommand[];
};
export type AetheriaMenuSurfaceTree = {
id: string;
root: AetheriaMenuSurfaceComponent;
styles: AetheriaMenuStyleToken[];
};
export type AetheriaMenuSurfaceComponent = {
id: string;
kind: string;
props: Record<string, string>;
children: AetheriaMenuSurfaceComponent[];
};
export type AetheriaMenuStyleToken = {
name: string;
value: string;
};
export type AetheriaMenuSurfaceCommand = {
command: string;
label: string;
transport: string;
};
export type AetheriaRtsApi = {
mapViewport(request: Viewport): Promise<ViewportResponse>;
objectsViewport(request: Viewport): Promise<ObjectsViewportResponse>;
@ -1045,6 +1091,10 @@ export type AetheriaRtsApi = {
setTarget(request: AetheriaRuntimeSetTargetRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
surfaceCatalog(): Promise<CultMeshSurfaceCatalogDiagnostic>;
surfaceCatalogIndex(): Promise<CultMeshSurfaceCatalogIndexDiagnostic>;
mainMenuSurface(request: AetheriaMenuSurfaceRequest): Promise<AetheriaMenuSurfaceDocument>;
debugSurface(): Promise<AetheriaMenuSurfaceDocument>;
watchDebugSurface(callback: (surface: AetheriaMenuSurfaceDocument) => void): () => void;
windowControl(action: "minimize" | "maximize" | "close"): Promise<void>;
health(): Promise<unknown>;
};
`;
@ -1289,6 +1339,7 @@ export type BodyView = {
y: number;
radius: number;
isAsteroidBelt: boolean;
iconAsset: AssetRef;
};
`;
}
@ -1302,7 +1353,11 @@ function renderIpcChannelLines() {
function renderPreload() {
const channelLines = renderIpcChannelLines();
const apiLines = ipcChannels
.filter(([name]) => name !== "viewportFeedUpdate" && name !== "viewportFeedStop")
.filter(([name]) => name !== "viewportFeedUpdate" &&
name !== "viewportFeedStop" &&
name !== "debugSurfaceWatch" &&
name !== "debugSurfaceWatchStop" &&
name !== "debugSurfaceChanged")
.map(([name]) => {
if (name === "viewportFeed") {
return ` watchViewportFeed: (request, callback) => {
@ -1318,6 +1373,23 @@ function renderPreload() {
ipcRenderer.off(channels.viewportFeedUpdate, listener);
void ipcRenderer.invoke(channels.viewportFeedStop, subscriptionId);
};
},`;
}
if (name === "debugSurface") {
return ` debugSurface: () => ipcRenderer.invoke(channels.debugSurface),
watchDebugSurface: callback => {
const subscriptionId = \`debug-surface-\${Date.now().toString(36)}-\${Math.random().toString(36).slice(2)}\`;
const listener = (_event, message) => {
if (message?.subscriptionId === subscriptionId) {
callback(message.surface);
}
};
ipcRenderer.on(channels.debugSurfaceChanged, listener);
void ipcRenderer.invoke(channels.debugSurfaceWatch, subscriptionId);
return () => {
ipcRenderer.off(channels.debugSurfaceChanged, listener);
void ipcRenderer.invoke(channels.debugSurfaceWatchStop, subscriptionId);
};
},`;
}
const hasNoArguments = name === "health" ||