mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Fix keys being stuck, show savegame levels in main menu
This commit is contained in:
@@ -63,9 +63,7 @@ export class Savegame extends ReadWriteProxy {
|
||||
return {
|
||||
version: this.getCurrentVersion(),
|
||||
dump: null,
|
||||
stats: {
|
||||
buildingsPlaced: 0,
|
||||
},
|
||||
stats: {},
|
||||
lastUpdate: Date.now(),
|
||||
};
|
||||
}
|
||||
@@ -79,7 +77,6 @@ export class Savegame extends ReadWriteProxy {
|
||||
return ExplainedResult.bad("Can not migrate savegame, too old");
|
||||
}
|
||||
|
||||
console.log("TODO: Migrate from", data.version);
|
||||
if (data.version === 1000) {
|
||||
SavegameInterface_V1001.migrate1000to1001(data);
|
||||
data.version = 1001;
|
||||
@@ -222,6 +219,12 @@ export class Savegame extends ReadWriteProxy {
|
||||
saveMetadata() {
|
||||
this.metaDataRef.lastUpdate = new Date().getTime();
|
||||
this.metaDataRef.version = this.getCurrentVersion();
|
||||
if (!this.hasGameDump()) {
|
||||
this.metaDataRef.level = 0;
|
||||
} else {
|
||||
this.metaDataRef.level = this.currentData.dump.hubGoals.level;
|
||||
}
|
||||
|
||||
return this.app.savegameMgr.writeAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ export const enumLocalSavegameStatus = {
|
||||
* @typedef {{
|
||||
* lastUpdate: number,
|
||||
* version: number,
|
||||
* internalId: string
|
||||
* internalId: string,
|
||||
* level: number
|
||||
* }} SavegameMetadata
|
||||
*
|
||||
* @typedef {{
|
||||
@@ -48,7 +49,7 @@ export class SavegameManager extends ReadWriteProxy {
|
||||
}
|
||||
|
||||
getCurrentVersion() {
|
||||
return 1000;
|
||||
return 1001;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,6 +69,13 @@ export class SavegameManager extends ReadWriteProxy {
|
||||
* @param {SavegamesData} data
|
||||
*/
|
||||
migrate(data) {
|
||||
if (data.version < 1001) {
|
||||
data.savegames.forEach(savegame => {
|
||||
savegame.level = 0;
|
||||
});
|
||||
data.version = 1001;
|
||||
}
|
||||
|
||||
return ExplainedResult.good();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ export class SavegameSerializer {
|
||||
map: root.map.serialize(),
|
||||
entityMgr: root.entityMgr.serialize(),
|
||||
hubGoals: root.hubGoals.serialize(),
|
||||
pinnedShapes: root.hud.parts.pinnedShapes.serialize(),
|
||||
};
|
||||
|
||||
data.entities = this.internal.serializeEntityArray(root.entityMgr.entities);
|
||||
@@ -118,7 +119,7 @@ export class SavegameSerializer {
|
||||
|
||||
/**
|
||||
* Tries to load the savegame from a given dump
|
||||
* @param {SerializedGame} savegame
|
||||
* @param {import("./savegame_typedefs").SerializedGame} savegame
|
||||
* @param {GameRoot} root
|
||||
* @returns {ExplainedResult}
|
||||
*/
|
||||
@@ -135,6 +136,7 @@ export class SavegameSerializer {
|
||||
errorReason = errorReason || root.camera.deserialize(savegame.camera);
|
||||
errorReason = errorReason || root.map.deserialize(savegame.map);
|
||||
errorReason = errorReason || root.hubGoals.deserialize(savegame.hubGoals);
|
||||
errorReason = errorReason || root.hud.parts.pinnedShapes.deserialize(savegame.pinnedShapes);
|
||||
errorReason = errorReason || this.internal.deserializeEntityArray(root, savegame.entities);
|
||||
|
||||
// Check for errors
|
||||
@@ -144,47 +146,4 @@ export class SavegameSerializer {
|
||||
|
||||
return ExplainedResult.good();
|
||||
}
|
||||
|
||||
/////////// MIGRATION HELPERS ///////////
|
||||
|
||||
/**
|
||||
* Performs a function on each component (useful to add / remove / alter properties for migration)
|
||||
* @param {SerializedGame} savegame
|
||||
* @param {typeof Component} componentHandle
|
||||
* @param {function} modifier
|
||||
*/
|
||||
migration_migrateComponent(savegame, componentHandle, modifier) {
|
||||
const targetId = componentHandle.getId();
|
||||
for (const entityListId in savegame.entities) {
|
||||
for (let i = 0; i < savegame.entities[entityListId].length; ++i) {
|
||||
const list = savegame.entities[entityListId][i];
|
||||
for (let k = 0; k < list.length; ++k) {
|
||||
const entity = list[k];
|
||||
const components = entity.components;
|
||||
if (components[targetId]) {
|
||||
modifier(components[targetId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an operation on each object which is a PooledObject (usually Projectiles). Useful to
|
||||
* perform migrations
|
||||
* @param {Array<any>} pools
|
||||
* @param {string} targetClassKey
|
||||
* @param {function} modifier
|
||||
*/
|
||||
migration_migrateGenericObjectPool(pools, targetClassKey, modifier) {
|
||||
for (let i = 0; i < pools.length; ++i) {
|
||||
const pool = pools[i];
|
||||
if (pool.key === targetClassKey) {
|
||||
const entries = pool.data.entries;
|
||||
for (const uid in entries) {
|
||||
modifier(entries[uid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Entity } from "../game/entity";
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* buildingsPlaced: number
|
||||
* }} SavegameStats
|
||||
*/
|
||||
|
||||
import { Entity } from "../game/entity";
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* camera: any,
|
||||
@@ -13,6 +12,7 @@ import { Entity } from "../game/entity";
|
||||
* entityMgr: any,
|
||||
* map: any,
|
||||
* hubGoals: any,
|
||||
* pinnedShapes: any,
|
||||
* entities: Array<Entity>
|
||||
* }} SerializedGame
|
||||
*/
|
||||
@@ -22,6 +22,6 @@ import { Entity } from "../game/entity";
|
||||
* version: number,
|
||||
* dump: SerializedGame,
|
||||
* stats: SavegameStats,
|
||||
* lastUpdate: number
|
||||
* lastUpdate: number,
|
||||
* }} SavegameData
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,10 @@ export class SavegameInterface_V1001 extends SavegameInterface_V1000 {
|
||||
return true;
|
||||
}
|
||||
|
||||
dump.pinnedShapes = {
|
||||
shapes: [],
|
||||
};
|
||||
|
||||
const entities = dump.entities;
|
||||
for (let i = 0; i < entities.length; ++i) {
|
||||
const entity = entities[i];
|
||||
|
||||
Reference in New Issue
Block a user