mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Add save migration
This commit is contained in:
parent
07f89c45a3
commit
694b95c25c
@ -1,6 +1,8 @@
|
|||||||
import { types } from "../../savegame/serialization";
|
import { types } from "../../savegame/serialization";
|
||||||
|
import { TypeString } from "../../savegame/serialization_data_types";
|
||||||
import { BaseItem } from "../base_item";
|
import { BaseItem } from "../base_item";
|
||||||
import { Component } from "../component";
|
import { Component } from "../component";
|
||||||
|
import { typeItemSingleton } from "../item_resolver";
|
||||||
|
|
||||||
/** @enum {string} */
|
/** @enum {string} */
|
||||||
export const enumItemProcessorTypes = {
|
export const enumItemProcessorTypes = {
|
||||||
@ -54,6 +56,19 @@ export class ItemProcessorComponent extends Component {
|
|||||||
static getSchema() {
|
static getSchema() {
|
||||||
return {
|
return {
|
||||||
nextOutputSlot: types.uint,
|
nextOutputSlot: types.uint,
|
||||||
|
currentCharge: types.nullable(
|
||||||
|
types.structured({
|
||||||
|
remainingTime: types.ufloat,
|
||||||
|
items: types.array(
|
||||||
|
types.structured({
|
||||||
|
item: typeItemSingleton,
|
||||||
|
extraProgress: types.nullable(types.float),
|
||||||
|
requiredSlot: types.nullable(types.uint),
|
||||||
|
preferredSlot: types.nullable(types.uint),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
})
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import { SavegameInterface_V1008 } from "./schemas/1008";
|
|||||||
import { SavegameInterface_V1009 } from "./schemas/1009";
|
import { SavegameInterface_V1009 } from "./schemas/1009";
|
||||||
import { MODS } from "../mods/modloader";
|
import { MODS } from "../mods/modloader";
|
||||||
import { SavegameInterface_V1010 } from "./schemas/1010";
|
import { SavegameInterface_V1010 } from "./schemas/1010";
|
||||||
|
import { SavegameInterface_V1011 } from "./schemas/1011";
|
||||||
|
|
||||||
const logger = createLogger("savegame");
|
const logger = createLogger("savegame");
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ export class Savegame extends ReadWriteProxy {
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
static getCurrentVersion() {
|
static getCurrentVersion() {
|
||||||
return 1010;
|
return 1011;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,6 +169,11 @@ export class Savegame extends ReadWriteProxy {
|
|||||||
data.version = 1010;
|
data.version = 1010;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.version === 1010) {
|
||||||
|
SavegameInterface_V1011.migrate1010to1011(data);
|
||||||
|
data.version = 1011;
|
||||||
|
}
|
||||||
|
|
||||||
return ExplainedResult.good();
|
return ExplainedResult.good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import { SavegameInterface_V1007 } from "./schemas/1007";
|
|||||||
import { SavegameInterface_V1008 } from "./schemas/1008";
|
import { SavegameInterface_V1008 } from "./schemas/1008";
|
||||||
import { SavegameInterface_V1009 } from "./schemas/1009";
|
import { SavegameInterface_V1009 } from "./schemas/1009";
|
||||||
import { SavegameInterface_V1010 } from "./schemas/1010";
|
import { SavegameInterface_V1010 } from "./schemas/1010";
|
||||||
|
import { SavegameInterface_V1011 } from "./schemas/1011";
|
||||||
|
|
||||||
/** @type {Object.<number, typeof BaseSavegameInterface>} */
|
/** @type {Object.<number, typeof BaseSavegameInterface>} */
|
||||||
export const savegameInterfaces = {
|
export const savegameInterfaces = {
|
||||||
@ -25,6 +26,7 @@ export const savegameInterfaces = {
|
|||||||
1008: SavegameInterface_V1008,
|
1008: SavegameInterface_V1008,
|
||||||
1009: SavegameInterface_V1009,
|
1009: SavegameInterface_V1009,
|
||||||
1010: SavegameInterface_V1010,
|
1010: SavegameInterface_V1010,
|
||||||
|
1011: SavegameInterface_V1011,
|
||||||
};
|
};
|
||||||
|
|
||||||
const logger = createLogger("savegame_interface_registry");
|
const logger = createLogger("savegame_interface_registry");
|
||||||
|
44
src/js/savegame/schemas/1011.js
Normal file
44
src/js/savegame/schemas/1011.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { createLogger } from "../../core/logging.js";
|
||||||
|
import { ItemProcessorComponent } from "../../game/components/item_processor.js";
|
||||||
|
import { MinerComponent } from "../../game/components/miner.js";
|
||||||
|
import { Entity } from "../../game/entity.js";
|
||||||
|
import { SavegameInterface_V1010 } from "./1010.js";
|
||||||
|
|
||||||
|
const schema = require("./1011.json");
|
||||||
|
const logger = createLogger("savegame_interface/1011");
|
||||||
|
|
||||||
|
export class SavegameInterface_V1011 extends SavegameInterface_V1010 {
|
||||||
|
getVersion() {
|
||||||
|
return 1011;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSchemaUncached() {
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {import("../savegame_typedefs.js").SavegameData} data
|
||||||
|
*/
|
||||||
|
static migrate1010to1011(data) {
|
||||||
|
logger.log("Migrating 1010 to 1011");
|
||||||
|
const dump = data.dump;
|
||||||
|
if (!dump) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {Array<Entity} */
|
||||||
|
const entities = dump.entities;
|
||||||
|
|
||||||
|
for (let i = 0; i < entities.length; i++) {
|
||||||
|
const entity = entities[i];
|
||||||
|
const minerComp = entity.components.Miner;
|
||||||
|
if (minerComp) {
|
||||||
|
minerComp.progress = 0;
|
||||||
|
}
|
||||||
|
const processorComp = entity.components.ItemProcessor;
|
||||||
|
if (processorComp) {
|
||||||
|
processorComp.currentCharge = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
src/js/savegame/schemas/1011.json
Normal file
5
src/js/savegame/schemas/1011.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"required": [],
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user