This commit is contained in:
45
src/RpgRuntimeApp.tsx
Normal file
45
src/RpgRuntimeApp.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
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;
|
||||
}
|
||||
| {
|
||||
token: number;
|
||||
kind: 'snapshot';
|
||||
snapshot: HydratedSavedGameSnapshot | null;
|
||||
};
|
||||
|
||||
export function RpgRuntimeApp({
|
||||
initialIntent,
|
||||
}: {
|
||||
initialIntent: RpgRuntimeAppIntent | null;
|
||||
}) {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
gameShellProps.entry.handleContinueGame(initialIntent.snapshot);
|
||||
}, [gameShellProps.entry, initialIntent]);
|
||||
|
||||
return <RpgRuntimeShell {...gameShellProps} />;
|
||||
}
|
||||
|
||||
export default RpgRuntimeApp;
|
||||
Reference in New Issue
Block a user