Files
healer-man/src/platform/RemoteDungeonHud.tsx
T
2026-09-14 13:20:20 -04:00

54 lines
3.0 KiB
TypeScript

import { useLayoutEffect } from "react";
import { useCombatStore } from "../game/combatStore";
import { useGameStore } from "../game/store";
import { clearBossTestingDungeons, registerBossTestingDungeon } from "../game/dungeonRegistry";
import { usePartyStore } from "../game/partyStore";
import { useManastormStore } from "../game/manastormStore";
import { useDungeonRunStore } from "../game/dungeonRunStore";
import { useOnlineSessionStore } from "../app/onlineSessionStore";
import { useOnlineGroupStore } from "../app/onlineGroupStore";
import { useShellStore } from "../app/shellStore";
import { useUiLayoutStore } from "../game/uiLayoutStore";
import { useDpsMeterStore } from "../game/dpsMeterStore";
import { DungeonCompanionHud } from "../ui/DungeonCompanionHud";
import type { CompanionCommand, CompanionSnapshot } from "./dualScreenSync";
export function RemoteDungeonHud({ snapshot, send }: {
snapshot: CompanionSnapshot;
send: (command: CompanionCommand) => void;
}) {
const hud = snapshot.game.hud;
useLayoutEffect(() => {
if (hud.bossTestingDungeon) registerBossTestingDungeon(hud.bossTestingDungeon.definition, hud.bossTestingDungeon.sourceDungeonId);
const session = useShellStore.getState().session;
useShellStore.setState({ ...hud.shell,
session: session?.ownerId === snapshot.session?.ownerId ? session : snapshot.session,
});
useUiLayoutStore.setState(hud.ui);
useGameStore.setState({ ...hud.game,
toggleMap: () => send({ name: "toggleMap" }),
openOverlay: (overlay) => send({ name: "openOverlay", overlay }),
});
if (!hud.bossTestingDungeon) clearBossTestingDungeons();
useCombatStore.setState({ ...hud.combat,
castActionBinding: (layer, control) => { send({ name: "castActionBinding", layer, control }); return { ok: false, affectedMobIds: [], damage: 0, healing: 0, levelsGained: 0 }; },
selectFriendlyActor: (id) => { send({ name: "selectFriendlyActor", id }); return true; },
clearTarget: () => send({ name: "clearTarget" }),
updateSettings: (patch) => { if (patch.threatMeterPosition) send({ name: "moveThreatMeter", position: patch.threatMeterPosition }); },
});
usePartyStore.setState({ ...hud.party,
selectMember: (memberId) => { if (memberId) send({ name: "selectPartyMember", memberId }); else send({ name: "clearPartySelection" }); return true; },
selectSelf: () => send({ name: "selectPlayer" }),
clearSelection: () => send({ name: "clearPartySelection" }),
setCommand: (command) => send({ name: "setPartyCommand", command }),
recallParty: () => send({ name: "recallParty" }),
});
useManastormStore.setState(hud.manastorm);
useDungeonRunStore.setState({ progress: hud.run });
useOnlineSessionStore.setState({ snapshot: hud.onlineSession });
useOnlineGroupStore.setState(hud.onlineGroup);
useDpsMeterStore.setState(hud.dps);
}, [hud, send, snapshot.session]);
return <DungeonCompanionHud send={send} remote completion={hud.completion} interaction={hud.interaction} />;
}