mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Implement saving and restoring belt paths
This commit is contained in:
@@ -14,6 +14,7 @@ import { SavegameInterface_V1001 } from "./schemas/1001";
|
||||
import { SavegameInterface_V1002 } from "./schemas/1002";
|
||||
import { SavegameInterface_V1003 } from "./schemas/1003";
|
||||
import { SavegameInterface_V1004 } from "./schemas/1004";
|
||||
import { SavegameInterface_V1005 } from "./schemas/1005";
|
||||
|
||||
const logger = createLogger("savegame");
|
||||
|
||||
@@ -45,7 +46,7 @@ export class Savegame extends ReadWriteProxy {
|
||||
* @returns {number}
|
||||
*/
|
||||
static getCurrentVersion() {
|
||||
return 1004;
|
||||
return 1005;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,6 +105,11 @@ export class Savegame extends ReadWriteProxy {
|
||||
data.version = 1004;
|
||||
}
|
||||
|
||||
if (data.version === 1004) {
|
||||
SavegameInterface_V1005.migrate1004to1005(data);
|
||||
data.version = 1005;
|
||||
}
|
||||
|
||||
return ExplainedResult.good();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { SavegameInterface_V1001 } from "./schemas/1001";
|
||||
import { SavegameInterface_V1002 } from "./schemas/1002";
|
||||
import { SavegameInterface_V1003 } from "./schemas/1003";
|
||||
import { SavegameInterface_V1004 } from "./schemas/1004";
|
||||
import { SavegameInterface_V1005 } from "./schemas/1005";
|
||||
|
||||
/** @type {Object.<number, typeof BaseSavegameInterface>} */
|
||||
export const savegameInterfaces = {
|
||||
@@ -13,6 +14,7 @@ export const savegameInterfaces = {
|
||||
1002: SavegameInterface_V1002,
|
||||
1003: SavegameInterface_V1003,
|
||||
1004: SavegameInterface_V1004,
|
||||
1005: SavegameInterface_V1005,
|
||||
};
|
||||
|
||||
const logger = createLogger("savegame_interface_registry");
|
||||
|
||||
@@ -40,6 +40,7 @@ export class SavegameSerializer {
|
||||
hubGoals: root.hubGoals.serialize(),
|
||||
pinnedShapes: root.hud.parts.pinnedShapes.serialize(),
|
||||
waypoints: root.hud.parts.waypoints.serialize(),
|
||||
beltPaths: root.systemMgr.systems.belt.serializePaths(),
|
||||
};
|
||||
|
||||
data.entities = this.internal.serializeEntityArray(root.entityMgr.entities);
|
||||
@@ -140,6 +141,7 @@ export class SavegameSerializer {
|
||||
errorReason = errorReason || root.hud.parts.pinnedShapes.deserialize(savegame.pinnedShapes);
|
||||
errorReason = errorReason || root.hud.parts.waypoints.deserialize(savegame.waypoints);
|
||||
errorReason = errorReason || this.internal.deserializeEntityArray(root, savegame.entities);
|
||||
errorReason = errorReason || root.systemMgr.systems.belt.deserializePaths(savegame.beltPaths);
|
||||
|
||||
// Check for errors
|
||||
if (errorReason) {
|
||||
|
||||
@@ -5,6 +5,10 @@ import { Entity } from "../game/entity";
|
||||
* }} SavegameStats
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* camera: any,
|
||||
@@ -14,7 +18,8 @@ import { Entity } from "../game/entity";
|
||||
* hubGoals: any,
|
||||
* pinnedShapes: any,
|
||||
* waypoints: any,
|
||||
* entities: Array<Entity>
|
||||
* entities: Array<Entity>,
|
||||
* beltPaths: Array<any>
|
||||
* }} SerializedGame
|
||||
*/
|
||||
|
||||
|
||||
29
src/js/savegame/schemas/1005.js
Normal file
29
src/js/savegame/schemas/1005.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createLogger } from "../../core/logging.js";
|
||||
import { SavegameInterface_V1004 } from "./1004.js";
|
||||
|
||||
const schema = require("./1005.json");
|
||||
const logger = createLogger("savegame_interface/1005");
|
||||
|
||||
export class SavegameInterface_V1005 extends SavegameInterface_V1004 {
|
||||
getVersion() {
|
||||
return 1005;
|
||||
}
|
||||
|
||||
getSchemaUncached() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../savegame_typedefs.js").SavegameData} data
|
||||
*/
|
||||
static migrate1004to1005(data) {
|
||||
logger.log("Migrating 1004 to 1005");
|
||||
const dump = data.dump;
|
||||
if (!dump) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// just reset belt paths for now
|
||||
dump.beltPaths = [];
|
||||
}
|
||||
}
|
||||
5
src/js/savegame/schemas/1005.json
Normal file
5
src/js/savegame/schemas/1005.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"type": "object",
|
||||
"required": [],
|
||||
"additionalProperties": true
|
||||
}
|
||||
Reference in New Issue
Block a user