mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-05 17:14:03 +00:00
Migrate old savegames
This commit is contained in:
parent
665360c5a5
commit
9075841768
@ -520,7 +520,7 @@
|
||||
"spriteSourceSize": {"x":1,"y":0,"w":143,"h":144},
|
||||
"sourceSize": {"w":144,"h":144}
|
||||
},
|
||||
"sprites/blueprints/rotater-fl.png":
|
||||
"sprites/blueprints/rotater-rotate180.png":
|
||||
{
|
||||
"frame": {"x":423,"y":1591,"w":142,"h":144},
|
||||
"rotated": false,
|
||||
@ -928,7 +928,7 @@
|
||||
"spriteSourceSize": {"x":2,"y":0,"w":141,"h":143},
|
||||
"sourceSize": {"w":144,"h":144}
|
||||
},
|
||||
"sprites/buildings/rotater-fl.png":
|
||||
"sprites/buildings/rotater-rotate180.png":
|
||||
{
|
||||
"frame": {"x":1611,"y":612,"w":141,"h":143},
|
||||
"rotated": false,
|
||||
@ -1487,6 +1487,6 @@
|
||||
"format": "RGBA8888",
|
||||
"size": {"w":2048,"h":2048},
|
||||
"scale": "0.75",
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:c38df9b4e442ab7ca6aca0b780d0839e:99e8394e24df838bd0f576e1caf16c3d:908b89f5ca8ff73e331a35a3b14d0604$"
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:f21861f754636ac30e87fdbab4b77dbd:161fc7d539e5ffa693c8470dcc931f75:908b89f5ca8ff73e331a35a3b14d0604$"
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
@ -520,7 +520,7 @@
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":48,"h":48},
|
||||
"sourceSize": {"w":48,"h":48}
|
||||
},
|
||||
"sprites/blueprints/rotater-fl.png":
|
||||
"sprites/blueprints/rotater-rotate180.png":
|
||||
{
|
||||
"frame": {"x":965,"y":165,"w":48,"h":48},
|
||||
"rotated": false,
|
||||
@ -928,7 +928,7 @@
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":48,"h":48},
|
||||
"sourceSize": {"w":48,"h":48}
|
||||
},
|
||||
"sprites/buildings/rotater-fl.png":
|
||||
"sprites/buildings/rotater-rotate180.png":
|
||||
{
|
||||
"frame": {"x":397,"y":254,"w":48,"h":48},
|
||||
"rotated": false,
|
||||
@ -1487,6 +1487,6 @@
|
||||
"format": "RGBA8888",
|
||||
"size": {"w":1024,"h":1024},
|
||||
"scale": "0.25",
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:c38df9b4e442ab7ca6aca0b780d0839e:99e8394e24df838bd0f576e1caf16c3d:908b89f5ca8ff73e331a35a3b14d0604$"
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:f21861f754636ac30e87fdbab4b77dbd:161fc7d539e5ffa693c8470dcc931f75:908b89f5ca8ff73e331a35a3b14d0604$"
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 279 KiB After Width: | Height: | Size: 279 KiB |
@ -520,7 +520,7 @@
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":96,"h":96},
|
||||
"sourceSize": {"w":96,"h":96}
|
||||
},
|
||||
"sprites/blueprints/rotater-fl.png":
|
||||
"sprites/blueprints/rotater-rotate180.png":
|
||||
{
|
||||
"frame": {"x":525,"y":1100,"w":95,"h":96},
|
||||
"rotated": false,
|
||||
@ -928,7 +928,7 @@
|
||||
"spriteSourceSize": {"x":1,"y":0,"w":95,"h":96},
|
||||
"sourceSize": {"w":96,"h":96}
|
||||
},
|
||||
"sprites/buildings/rotater-fl.png":
|
||||
"sprites/buildings/rotater-rotate180.png":
|
||||
{
|
||||
"frame": {"x":213,"y":1234,"w":95,"h":96},
|
||||
"rotated": false,
|
||||
@ -1487,6 +1487,6 @@
|
||||
"format": "RGBA8888",
|
||||
"size": {"w":1024,"h":2048},
|
||||
"scale": "0.5",
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:c38df9b4e442ab7ca6aca0b780d0839e:99e8394e24df838bd0f576e1caf16c3d:908b89f5ca8ff73e331a35a3b14d0604$"
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:f21861f754636ac30e87fdbab4b77dbd:161fc7d539e5ffa693c8470dcc931f75:908b89f5ca8ff73e331a35a3b14d0604$"
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 705 KiB After Width: | Height: | Size: 705 KiB |
@ -86,7 +86,10 @@ export function getCodeFromBuildingData(metaBuilding, variant, rotationVariant)
|
||||
const hash = metaBuilding.getId() + "/" + variant + "/" + rotationVariant;
|
||||
const result = variantsCache.get(hash);
|
||||
if (G_IS_DEV) {
|
||||
assertAlways(!!result, "Building not found by data: " + hash);
|
||||
if (!result) {
|
||||
console.warn("Known hashes:", Array.from(variantsCache.keys()));
|
||||
assertAlways(false, "Building not found by data: " + hash);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -16,8 +16,6 @@ export const beltOverlayMatrices = {
|
||||
[enumDirection.right]: generateMatrixRotations([0, 0, 0, 0, 1, 1, 0, 1, 0]),
|
||||
};
|
||||
|
||||
export class MetaBeltBaseBuilding extends MetaBuilding {}
|
||||
|
||||
export class MetaBeltBuilding extends MetaBuilding {
|
||||
constructor() {
|
||||
super("belt");
|
||||
|
@ -68,6 +68,10 @@ export class HUDEntityDebugger extends BaseHUDPart {
|
||||
* @param {Array} recursion
|
||||
*/
|
||||
propertyToHTML(name, val, indent = 0, recursion = []) {
|
||||
if (indent > 20) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (val !== null && typeof val === "object") {
|
||||
// Array is displayed like object, with indexes
|
||||
recursion.push(val);
|
||||
|
@ -6,17 +6,16 @@ import { DialogWithForm } from "../../../core/modal_dialog_elements";
|
||||
import { FormElementInput } from "../../../core/modal_dialog_forms";
|
||||
import { Rectangle } from "../../../core/rectangle";
|
||||
import { STOP_PROPAGATION } from "../../../core/signal";
|
||||
import { arrayDeleteValue, lerp, makeDiv, removeAllChildren, clamp } from "../../../core/utils";
|
||||
import { arrayDeleteValue, lerp, makeDiv, removeAllChildren } from "../../../core/utils";
|
||||
import { Vector } from "../../../core/vector";
|
||||
import { T } from "../../../translations";
|
||||
import { BaseItem } from "../../base_item";
|
||||
import { enumMouseButton } from "../../camera";
|
||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||
import { ShapeDefinition } from "../../shape_definition";
|
||||
import { BaseHUDPart } from "../base_hud_part";
|
||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||
import { enumNotificationType } from "./notifications";
|
||||
import { ShapeDefinition } from "../../shape_definition";
|
||||
import { BaseItem } from "../../base_item";
|
||||
import { ShapeItem } from "../../items/shape_item";
|
||||
|
||||
/** @typedef {{
|
||||
* label: string | null,
|
||||
|
@ -10,6 +10,7 @@ import { SavegameInterface_V1002 } from "./schemas/1002";
|
||||
import { SavegameInterface_V1003 } from "./schemas/1003";
|
||||
import { SavegameInterface_V1004 } from "./schemas/1004";
|
||||
import { SavegameInterface_V1005 } from "./schemas/1005";
|
||||
import { SavegameInterface_V1006 } from "./schemas/1006";
|
||||
|
||||
const logger = createLogger("savegame");
|
||||
|
||||
@ -50,7 +51,7 @@ export class Savegame extends ReadWriteProxy {
|
||||
* @returns {number}
|
||||
*/
|
||||
static getCurrentVersion() {
|
||||
return 1005;
|
||||
return 1006;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,6 +115,11 @@ export class Savegame extends ReadWriteProxy {
|
||||
data.version = 1005;
|
||||
}
|
||||
|
||||
if (data.version === 1005) {
|
||||
SavegameInterface_V1006.migrate1005to1006(data);
|
||||
data.version = 1006;
|
||||
}
|
||||
|
||||
return ExplainedResult.good();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import { SavegameInterface_V1002 } from "./schemas/1002";
|
||||
import { SavegameInterface_V1003 } from "./schemas/1003";
|
||||
import { SavegameInterface_V1004 } from "./schemas/1004";
|
||||
import { SavegameInterface_V1005 } from "./schemas/1005";
|
||||
import { SavegameInterface_V1006 } from "./schemas/1006";
|
||||
|
||||
/** @type {Object.<number, typeof BaseSavegameInterface>} */
|
||||
export const savegameInterfaces = {
|
||||
@ -15,6 +16,7 @@ export const savegameInterfaces = {
|
||||
1003: SavegameInterface_V1003,
|
||||
1004: SavegameInterface_V1004,
|
||||
1005: SavegameInterface_V1005,
|
||||
1006: SavegameInterface_V1006,
|
||||
};
|
||||
|
||||
const logger = createLogger("savegame_interface_registry");
|
||||
|
265
src/js/savegame/schemas/1006.js
Normal file
265
src/js/savegame/schemas/1006.js
Normal file
@ -0,0 +1,265 @@
|
||||
import { gMetaBuildingRegistry } from "../../core/global_registries.js";
|
||||
import { createLogger } from "../../core/logging.js";
|
||||
import { MetaBeltBuilding } from "../../game/buildings/belt.js";
|
||||
import { enumCutterVariants, MetaCutterBuilding } from "../../game/buildings/cutter.js";
|
||||
import { MetaHubBuilding } from "../../game/buildings/hub.js";
|
||||
import { enumMinerVariants, MetaMinerBuilding } from "../../game/buildings/miner.js";
|
||||
import { MetaMixerBuilding } from "../../game/buildings/mixer.js";
|
||||
import { enumPainterVariants, MetaPainterBuilding } from "../../game/buildings/painter.js";
|
||||
import { enumRotaterVariants, MetaRotaterBuilding } from "../../game/buildings/rotater.js";
|
||||
import { enumSplitterVariants, MetaSplitterBuilding } from "../../game/buildings/splitter.js";
|
||||
import { MetaStackerBuilding } from "../../game/buildings/stacker.js";
|
||||
import { enumTrashVariants, MetaTrashBuilding } from "../../game/buildings/trash.js";
|
||||
import {
|
||||
enumUndergroundBeltVariants,
|
||||
MetaUndergroundBeltBuilding,
|
||||
} from "../../game/buildings/underground_belt.js";
|
||||
import { getCodeFromBuildingData } from "../../game/building_codes.js";
|
||||
import { StaticMapEntityComponent } from "../../game/components/static_map_entity.js";
|
||||
import { Entity } from "../../game/entity.js";
|
||||
import { defaultBuildingVariant, MetaBuilding } from "../../game/meta_building.js";
|
||||
import { SavegameInterface_V1005 } from "./1005.js";
|
||||
|
||||
const schema = require("./1006.json");
|
||||
const logger = createLogger("savegame_interface/1006");
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {typeof MetaBuilding} metaBuilding
|
||||
* @param {string=} variant
|
||||
* @param {number=} rotationVariant
|
||||
*/
|
||||
function findCode(metaBuilding, variant = defaultBuildingVariant, rotationVariant = 0) {
|
||||
return getCodeFromBuildingData(gMetaBuildingRegistry.findByClass(metaBuilding), variant, rotationVariant);
|
||||
}
|
||||
|
||||
export class SavegameInterface_V1006 extends SavegameInterface_V1005 {
|
||||
getVersion() {
|
||||
return 1006;
|
||||
}
|
||||
|
||||
getSchemaUncached() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
static computeSpriteMapping() {
|
||||
return {
|
||||
// Belt
|
||||
"sprites/blueprints/belt_top.png": findCode(MetaBeltBuilding, defaultBuildingVariant, 0),
|
||||
"sprites/blueprints/belt_left.png": findCode(MetaBeltBuilding, defaultBuildingVariant, 1),
|
||||
"sprites/blueprints/belt_right.png": findCode(MetaBeltBuilding, defaultBuildingVariant, 2),
|
||||
|
||||
// Splitter
|
||||
"sprites/blueprints/splitter.png": findCode(MetaSplitterBuilding),
|
||||
"sprites/blueprints/splitter-compact.png": findCode(
|
||||
MetaSplitterBuilding,
|
||||
enumSplitterVariants.compact
|
||||
),
|
||||
"sprites/blueprints/splitter-compact-inverse.png": findCode(
|
||||
MetaSplitterBuilding,
|
||||
enumSplitterVariants.compactInverse
|
||||
),
|
||||
|
||||
// Underground belt
|
||||
"sprites/blueprints/underground_belt_entry.png": findCode(
|
||||
MetaUndergroundBeltBuilding,
|
||||
defaultBuildingVariant,
|
||||
0
|
||||
),
|
||||
"sprites/blueprints/underground_belt_exit.png": findCode(
|
||||
MetaUndergroundBeltBuilding,
|
||||
defaultBuildingVariant,
|
||||
1
|
||||
),
|
||||
|
||||
"sprites/blueprints/underground_belt_entry-tier2.png": findCode(
|
||||
MetaUndergroundBeltBuilding,
|
||||
enumUndergroundBeltVariants.tier2,
|
||||
0
|
||||
),
|
||||
"sprites/blueprints/underground_belt_exit-tier2.png": findCode(
|
||||
MetaUndergroundBeltBuilding,
|
||||
enumUndergroundBeltVariants.tier2,
|
||||
1
|
||||
),
|
||||
|
||||
// Miner
|
||||
"sprites/blueprints/miner.png": findCode(MetaMinerBuilding),
|
||||
"sprites/blueprints/miner-chainable.png": findCode(
|
||||
MetaMinerBuilding,
|
||||
enumMinerVariants.chainable,
|
||||
0
|
||||
),
|
||||
|
||||
// Cutter
|
||||
"sprites/blueprints/cutter.png": findCode(MetaCutterBuilding),
|
||||
"sprites/blueprints/cutter-quad.png": findCode(MetaCutterBuilding, enumCutterVariants.quad),
|
||||
|
||||
// Rotater
|
||||
"sprites/blueprints/rotater.png": findCode(MetaRotaterBuilding),
|
||||
"sprites/blueprints/rotater-ccw.png": findCode(MetaRotaterBuilding, enumRotaterVariants.ccw),
|
||||
|
||||
// Stacker
|
||||
"sprites/blueprints/stacker.png": findCode(MetaStackerBuilding),
|
||||
|
||||
// Mixer
|
||||
"sprites/blueprints/mixer.png": findCode(MetaMixerBuilding),
|
||||
|
||||
// Painter
|
||||
"sprites/blueprints/painter.png": findCode(MetaPainterBuilding),
|
||||
"sprites/blueprints/painter-mirrored.png": findCode(
|
||||
MetaPainterBuilding,
|
||||
enumPainterVariants.mirrored
|
||||
),
|
||||
"sprites/blueprints/painter-double.png": findCode(
|
||||
MetaPainterBuilding,
|
||||
enumPainterVariants.double
|
||||
),
|
||||
"sprites/blueprints/painter-quad.png": findCode(MetaPainterBuilding, enumPainterVariants.quad),
|
||||
|
||||
// Trash / Storage
|
||||
"sprites/blueprints/trash.png": findCode(MetaTrashBuilding),
|
||||
"sprites/blueprints/trash-storage.png": findCode(MetaTrashBuilding, enumTrashVariants.storage),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../savegame_typedefs.js").SavegameData} data
|
||||
*/
|
||||
static migrate1005to1006(data) {
|
||||
logger.log("Migrating 1005 to 1006");
|
||||
const dump = data.dump;
|
||||
if (!dump) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update entities
|
||||
const entities = dump.entities;
|
||||
for (let i = 0; i < entities.length; ++i) {
|
||||
const entity = entities[i];
|
||||
const components = entity.components;
|
||||
this.migrateStaticComp1005to1006(entity);
|
||||
|
||||
// HUB
|
||||
if (components.Hub) {
|
||||
// @ts-ignore
|
||||
components.Hub = {};
|
||||
}
|
||||
|
||||
// Item Processor
|
||||
if (components.ItemProcessor) {
|
||||
// @ts-ignore
|
||||
components.ItemProcessor = {
|
||||
nextOutputSlot: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// OLD: Unremovable component
|
||||
// @ts-ignore
|
||||
if (components.Unremovable) {
|
||||
// @ts-ignore
|
||||
delete components.Unremovable;
|
||||
}
|
||||
|
||||
// OLD: ReplaceableMapEntity
|
||||
// @ts-ignore
|
||||
if (components.ReplaceableMapEntity) {
|
||||
// @ts-ignore
|
||||
delete components.ReplaceableMapEntity;
|
||||
}
|
||||
|
||||
// ItemAcceptor
|
||||
if (components.ItemAcceptor) {
|
||||
// @ts-ignore
|
||||
components.ItemAcceptor = {};
|
||||
}
|
||||
|
||||
// Belt
|
||||
if (components.Belt) {
|
||||
// @ts-ignore
|
||||
components.Belt = {};
|
||||
}
|
||||
|
||||
// Item Ejector
|
||||
if (components.ItemEjector) {
|
||||
// @ts-ignore
|
||||
components.ItemEjector = {
|
||||
slots: [],
|
||||
};
|
||||
}
|
||||
|
||||
// UndergroundBelt
|
||||
if (components.UndergroundBelt) {
|
||||
// @ts-ignore
|
||||
components.UndergroundBelt = {
|
||||
pendingItems: [],
|
||||
};
|
||||
}
|
||||
|
||||
// Miner
|
||||
if (components.Miner) {
|
||||
// @ts-ignore
|
||||
delete components.Miner.chainable;
|
||||
|
||||
components.Miner.lastMiningTime = 0;
|
||||
components.Miner.itemChainBuffer = [];
|
||||
}
|
||||
|
||||
// Storage
|
||||
if (components.Storage) {
|
||||
// @ts-ignore
|
||||
components.Storage = {
|
||||
storedCount: 0,
|
||||
storedItem: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
static migrateStaticComp1005to1006(entity) {
|
||||
const spriteMapping = this.computeSpriteMapping();
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
|
||||
/** @type {StaticMapEntityComponent} */
|
||||
const newStaticComp = {};
|
||||
newStaticComp.origin = staticComp.origin;
|
||||
newStaticComp.originalRotation = staticComp.originalRotation;
|
||||
newStaticComp.rotation = staticComp.rotation;
|
||||
|
||||
// @ts-ignore
|
||||
newStaticComp.code = spriteMapping[staticComp.blueprintSpriteKey];
|
||||
|
||||
// Hub special case
|
||||
if (entity.components.Hub) {
|
||||
newStaticComp.code = findCode(MetaHubBuilding);
|
||||
}
|
||||
|
||||
// Belt special case
|
||||
if (entity.components.Belt) {
|
||||
const actualCode = {
|
||||
top: findCode(MetaBeltBuilding, defaultBuildingVariant, 0),
|
||||
left: findCode(MetaBeltBuilding, defaultBuildingVariant, 1),
|
||||
right: findCode(MetaBeltBuilding, defaultBuildingVariant, 2),
|
||||
}[entity.components.Belt.direction];
|
||||
if (actualCode !== newStaticComp.code) {
|
||||
if (G_IS_DEV) {
|
||||
console.warn("Belt mismatch");
|
||||
}
|
||||
newStaticComp.code = actualCode;
|
||||
}
|
||||
}
|
||||
|
||||
if (!newStaticComp.code) {
|
||||
throw new Error(
|
||||
// @ts-ignore
|
||||
"1006 Migration: Could not reconstruct code for " + staticComp.blueprintSpriteKey
|
||||
);
|
||||
}
|
||||
|
||||
entity.components.StaticMapEntity = newStaticComp;
|
||||
}
|
||||
}
|
5
src/js/savegame/schemas/1006.json
Normal file
5
src/js/savegame/schemas/1006.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"type": "object",
|
||||
"required": [],
|
||||
"additionalProperties": true
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
import { globalConfig } from "../core/config";
|
||||
import { createLogger } from "../core/logging";
|
||||
import { Vector } from "../core/vector";
|
||||
import { getBuildingDataFromCode } from "../game/building_codes";
|
||||
@ -78,7 +79,9 @@ export class SerializerInternal {
|
||||
deserializeComponents(root, entity, data) {
|
||||
for (const componentId in data) {
|
||||
if (!entity.components[componentId]) {
|
||||
if (G_IS_DEV && !globalConfig.debug.disableSlowAsserts) {
|
||||
logger.warn("Entity no longer has component:", componentId);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user