generated from nhcarrigan/template
fix: eliminate loading screen flash after prestige (#163)
Add reloadSilent which rehydrates state without toggling isLoading, preventing the game from unmounting and showing the loading screen after auto- or manual prestige.
This commit is contained in:
@@ -84,7 +84,7 @@ const categoryOrder: Array<PrestigeUpgradeCategory> = [
|
|||||||
const PrestigePanel = (): JSX.Element => {
|
const PrestigePanel = (): JSX.Element => {
|
||||||
const {
|
const {
|
||||||
state,
|
state,
|
||||||
reload,
|
reloadSilent,
|
||||||
formatNumber,
|
formatNumber,
|
||||||
buyPrestigeUpgrade,
|
buyPrestigeUpgrade,
|
||||||
enableNotifications,
|
enableNotifications,
|
||||||
@@ -141,7 +141,7 @@ const PrestigePanel = (): JSX.Element => {
|
|||||||
`You've reached prestige level ${data.newPrestigeCount.toString()}!`,
|
`You've reached prestige level ${data.newPrestigeCount.toString()}!`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await reload();
|
await reloadSilent();
|
||||||
} catch (error_: unknown) {
|
} catch (error_: unknown) {
|
||||||
setPrestigeError(
|
setPrestigeError(
|
||||||
error_ instanceof Error
|
error_ instanceof Error
|
||||||
|
|||||||
@@ -310,6 +310,12 @@ interface GameContextValue {
|
|||||||
*/
|
*/
|
||||||
reload: ()=> Promise<void>;
|
reload: ()=> Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload state from the server without showing the loading screen (used
|
||||||
|
* after prestige to avoid the visible flash/hang).
|
||||||
|
*/
|
||||||
|
reloadSilent: ()=> Promise<void>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unix timestamp of the last successful cloud save (null until first save response).
|
* Unix timestamp of the last successful cloud save (null until first save response).
|
||||||
*/
|
*/
|
||||||
@@ -718,6 +724,10 @@ export const GameProvider = ({
|
|||||||
|
|
||||||
/* No-op placeholder */
|
/* No-op placeholder */
|
||||||
});
|
});
|
||||||
|
const reloadSilentReference = useRef<()=> Promise<void>>(async() => {
|
||||||
|
|
||||||
|
/* No-op placeholder */
|
||||||
|
});
|
||||||
const [ schemaOutdated, setSchemaOutdated ] = useState(false);
|
const [ schemaOutdated, setSchemaOutdated ] = useState(false);
|
||||||
const [ saveSchemaVersion, setSaveSchemaVersion ] = useState(0);
|
const [ saveSchemaVersion, setSaveSchemaVersion ] = useState(0);
|
||||||
const [ currentSchemaVersion, setCurrentSchemaVersion ] = useState(0);
|
const [ currentSchemaVersion, setCurrentSchemaVersion ] = useState(0);
|
||||||
@@ -805,6 +815,32 @@ export const GameProvider = ({
|
|||||||
|
|
||||||
reloadReference.current = reload;
|
reloadReference.current = reload;
|
||||||
|
|
||||||
|
const reloadSilent = useCallback(async() => {
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
const data = await loadGame();
|
||||||
|
setState(data.state);
|
||||||
|
setLastSavedAt(data.state.player.lastSavedAt);
|
||||||
|
if (data.signature !== undefined) {
|
||||||
|
signatureReference.current = data.signature;
|
||||||
|
localStorage.setItem("elysium_save_signature", data.signature);
|
||||||
|
}
|
||||||
|
setLoginStreak(data.loginStreak);
|
||||||
|
setSchemaOutdated(data.schemaOutdated);
|
||||||
|
setSaveSchemaVersion(data.state.schemaVersion ?? 0);
|
||||||
|
setCurrentSchemaVersion(data.currentSchemaVersion);
|
||||||
|
setInGuild(data.inGuild);
|
||||||
|
} catch (error_: unknown) {
|
||||||
|
setError(
|
||||||
|
error_ instanceof Error
|
||||||
|
? error_.message
|
||||||
|
: "Failed to load game",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
reloadSilentReference.current = reloadSilent;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
enableSoundsReference.current = enableSounds;
|
enableSoundsReference.current = enableSounds;
|
||||||
}, [ enableSounds ]);
|
}, [ enableSounds ]);
|
||||||
@@ -1315,7 +1351,7 @@ export const GameProvider = ({
|
|||||||
if (enableNotificationsReference.current) {
|
if (enableNotificationsReference.current) {
|
||||||
sendNotification("⭐ Prestige!", "You have ascended!");
|
sendNotification("⭐ Prestige!", "You have ascended!");
|
||||||
}
|
}
|
||||||
await reloadReference.current();
|
await reloadSilentReference.current();
|
||||||
}).
|
}).
|
||||||
catch(() => {
|
catch(() => {
|
||||||
|
|
||||||
@@ -2373,6 +2409,7 @@ export const GameProvider = ({
|
|||||||
offlineEssence,
|
offlineEssence,
|
||||||
offlineGold,
|
offlineGold,
|
||||||
reload,
|
reload,
|
||||||
|
reloadSilent,
|
||||||
resetProgress,
|
resetProgress,
|
||||||
saveSchemaVersion,
|
saveSchemaVersion,
|
||||||
schemaOutdated,
|
schemaOutdated,
|
||||||
|
|||||||
Reference in New Issue
Block a user