From 6a19a944355140cc4409869d97456c274f303f22 Mon Sep 17 00:00:00 2001 From: dgs4349 Date: Sun, 27 Sep 2020 20:32:39 -0400 Subject: [PATCH] fixing serializer changes --- src/js/core/config.local.js | 6 +++--- src/js/game/core.js | 2 +- src/js/savegame/schemas/1006.js | 15 ++++++++++++--- src/js/savegame/serializer_internal.js | 9 ++++++--- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/js/core/config.local.js b/src/js/core/config.local.js index 87aaaa14..b5aa3572 100644 --- a/src/js/core/config.local.js +++ b/src/js/core/config.local.js @@ -9,7 +9,7 @@ export default { // noArtificialDelays: true, // ----------------------------------------------------------------------------------- // Disables writing of savegames, useful for testing the same savegame over and over - // disableSavegameWrite: true, + disableSavegameWrite: true, // ----------------------------------------------------------------------------------- // Shows bounds of all entities // showEntityBounds: true, @@ -33,7 +33,7 @@ export default { // allBuildingsUnlocked: true, // ----------------------------------------------------------------------------------- // Disables cost of blueprints - // blueprintsNoCost: true, + blueprintsNoCost: true, // ----------------------------------------------------------------------------------- // Disables cost of upgrades // upgradesNoCost: true, @@ -75,7 +75,7 @@ export default { // instantMiners: true, // ----------------------------------------------------------------------------------- // When using fastGameEnter, controls whether a new game is started or the last one is resumed - // resumeGameOnFastEnter: true, + resumeGameOnFastEnter: true, // ----------------------------------------------------------------------------------- // Special option used to render the trailer // renderForTrailer: true, diff --git a/src/js/game/core.js b/src/js/game/core.js index 306643f9..73580a0e 100644 --- a/src/js/game/core.js +++ b/src/js/game/core.js @@ -417,7 +417,7 @@ export class GameCore { this.overlayAlpha = lerp(this.overlayAlpha, desiredOverlayAlpha, 0.25); // On low performance, skip the fade - if (this.root.entityMgr.entities.length > 5000 || this.root.dynamicTickrate.averageFps < 50) { + if (this.root.entityMgr.entities.size > 5000 || this.root.dynamicTickrate.averageFps < 50) { this.overlayAlpha = desiredOverlayAlpha; } diff --git a/src/js/savegame/schemas/1006.js b/src/js/savegame/schemas/1006.js index e6b2e263..f4512bcf 100644 --- a/src/js/savegame/schemas/1006.js +++ b/src/js/savegame/schemas/1006.js @@ -253,8 +253,15 @@ export class SavegameInterface_V1006 extends SavegameInterface_V1005 { newStaticComp.originalRotation = staticComp.originalRotation; newStaticComp.rotation = staticComp.rotation; - // @ts-ignore - newStaticComp.code = spriteMapping[staticComp.blueprintSpriteKey]; + /** + * in one of our files: + * we dont seem to actually have a blueprintspritekey + * but we do have this attribute called code + */ + + if (staticComp.blueprintSpriteKey) { + newStaticComp.code = spriteMapping[staticComp.blueprintSpriteKey]; + } else newStaticComp.code = staticComp.code; // Hub special case if (entity.components.Hub) { @@ -277,9 +284,11 @@ export class SavegameInterface_V1006 extends SavegameInterface_V1005 { } if (!newStaticComp.code) { + console.dir(entity); + console.dir(staticComp); throw new Error( // @ts-ignore - "1006 Migration: Could not reconstruct code for " + staticComp.blueprintSpriteKey + "1006 Migration: Could not reconstruct code for " + code ); } diff --git a/src/js/savegame/serializer_internal.js b/src/js/savegame/serializer_internal.js index fa02a437..940283d0 100644 --- a/src/js/savegame/serializer_internal.js +++ b/src/js/savegame/serializer_internal.js @@ -11,12 +11,15 @@ const logger = createLogger("serializer_internal"); export class SerializerInternal { /** * Serializes an array of entities - * @param {Array} array + * @param {Array|Set} array */ serializeEntityArray(array) { const serialized = []; - for (let i = 0; i < array.length; ++i) { - const entity = array[i]; + + const arr = Array.isArray(array) ? array : [...array.values()]; + + for (let i = 0; i < arr.length; ++i) { + const entity = arr[i]; if (!entity.queuedForDestroy && !entity.destroyed) { serialized.push(entity.serialize()); }