51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { useEffect, useRef } from 'react';
|
|
|
|
import { RpgRuntimeShell } from './components/rpg-runtime-shell/RpgRuntimeShell';
|
|
import { useRpgRuntimeSession } from './hooks/rpg-session/useRpgRuntimeSession';
|
|
import type { HydratedSavedGameSnapshot } from './persistence/runtimeSnapshotTypes';
|
|
import type { CustomWorldProfile } from './types';
|
|
|
|
export type RpgRuntimeAppIntent =
|
|
| {
|
|
token: number;
|
|
kind: 'custom-world';
|
|
profile: CustomWorldProfile;
|
|
mode?: 'play' | 'test';
|
|
}
|
|
| {
|
|
token: number;
|
|
kind: 'snapshot';
|
|
snapshot: HydratedSavedGameSnapshot | null;
|
|
};
|
|
|
|
export function RpgRuntimeApp({
|
|
initialIntent,
|
|
onExitRuntime,
|
|
}: {
|
|
initialIntent: RpgRuntimeAppIntent | null;
|
|
onExitRuntime?: () => void;
|
|
}) {
|
|
const gameShellProps = useRpgRuntimeSession();
|
|
const handledIntentTokenRef = useRef<number | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (!initialIntent || handledIntentTokenRef.current === initialIntent.token) {
|
|
return;
|
|
}
|
|
|
|
handledIntentTokenRef.current = initialIntent.token;
|
|
if (initialIntent.kind === 'custom-world') {
|
|
gameShellProps.entry.handleCustomWorldSelect(initialIntent.profile, {
|
|
mode: initialIntent.mode ?? 'play',
|
|
});
|
|
return;
|
|
}
|
|
|
|
gameShellProps.entry.handleContinueGame(initialIntent.snapshot);
|
|
}, [gameShellProps.entry, initialIntent]);
|
|
|
|
return <RpgRuntimeShell {...gameShellProps} onExitTestRuntime={onExitRuntime} />;
|
|
}
|
|
|
|
export default RpgRuntimeApp;
|