Allow null and undefined values in persistent refs
This commit is contained in:
parent
c30724d907
commit
dfb14acc6e
4 changed files with 14 additions and 4 deletions
|
@ -27,6 +27,13 @@ module.exports = {
|
|||
allowNullableObject: true,
|
||||
allowNullableBoolean: true
|
||||
}
|
||||
],
|
||||
"eqeqeq": [
|
||||
"error",
|
||||
"always",
|
||||
{
|
||||
"null": "never"
|
||||
}
|
||||
]
|
||||
},
|
||||
globals: {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue