Allow null and undefined values in persistent refs
Some checks failed
Build and Deploy / build-and-deploy (push) Successful in 57s
Run Tests / test (push) Failing after 2m6s

This commit is contained in:
thepaperpilot 2024-03-03 19:24:24 -06:00 committed by thepaperpilot
parent c30724d907
commit dfb14acc6e
4 changed files with 14 additions and 4 deletions

View file

@ -27,6 +27,13 @@ module.exports = {
allowNullableObject: true,
allowNullableBoolean: true
}
],
"eqeqeq": [
"error",
"always",
{
"null": "never"
}
]
},
globals: {

View file

@ -62,6 +62,8 @@ export type State =
| number
| boolean
| DecimalSource
| null
| undefined
| { [key: string]: State }
| { [key: number]: State };
@ -227,7 +229,7 @@ export function noPersist<T extends Persistent<S>, S extends State>(persistent:
if (key === PersistentState) {
return false;
}
if (key == SkipPersistence) {
if (key === SkipPersistence) {
return true;
}
return Reflect.has(target, key);
@ -279,7 +281,7 @@ globalBus.on("addLayer", (layer: GenericLayer, saveData: Record<string, unknown>
// Handle SaveDataPath
const newPath = [layer.id, ...path, key];
if (
value[SaveDataPath] != undefined &&
value[SaveDataPath] != null &&
JSON.stringify(newPath) !== JSON.stringify(value[SaveDataPath])
) {
console.error(

View file

@ -64,7 +64,8 @@ export default window.player = player;
/** Convert a player save data object into a JSON string. Unwraps refs. */
export function stringifySave(player: Player): string {
return JSON.stringify(player, (key, value) => unref(value));
// Convert undefineds into nulls for proper parsing
return JSON.stringify(player, (key, value) => unref(value) ?? null);
}
declare global {

View file

@ -119,7 +119,7 @@ export async function loadSave(playerObj: Partial<Player>): Promise<void> {
playerObj.time &&
playerObj.devSpeed !== 0
) {
if (playerObj.offlineTime == undefined) playerObj.offlineTime = 0;
if (playerObj.offlineTime == null) playerObj.offlineTime = 0;
playerObj.offlineTime += Math.min(
playerObj.offlineTime + (Date.now() - playerObj.time) / 1000,
projInfo.offlineLimit * 3600