mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Migrate old savegames
This commit is contained in:
parent
4e18fa74d4
commit
23db5b117e
@ -40,6 +40,9 @@
|
||||
<meta http-equiv="Expires" content="0" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
|
||||
<link rel="canonical" href="https://shapez.io" />
|
||||
|
||||
<!-- a/b testing -->
|
||||
<script src="https://www.googleoptimize.com/optimize.js?id=OPT-M5NHCV7"></script>
|
||||
</head>
|
||||
|
||||
<body oncontextmenu="return false" style="background: #393747;"></body>
|
||||
|
@ -1,4 +1,12 @@
|
||||
export const CHANGELOG = [
|
||||
{
|
||||
version: "1.1.3",
|
||||
date: "unreleased",
|
||||
entries: [
|
||||
"Allow binding mouse buttons to actions (by Dimava)",
|
||||
"Fix belts being too slow when copied via blueprint (by Dimava)",
|
||||
],
|
||||
},
|
||||
{
|
||||
version: "1.1.2",
|
||||
date: "30.05.2020",
|
||||
|
@ -66,11 +66,6 @@ export class GoogleAnalyticsImpl extends AnalyticsInterface {
|
||||
}
|
||||
|
||||
trackUiClick(elementName) {
|
||||
// Only track a fraction of clicks to not annoy google analytics
|
||||
if (Math_random() < 0.9) {
|
||||
return;
|
||||
}
|
||||
|
||||
const stateKey = this.app.stateMgr.getCurrentState().key;
|
||||
const fullSelector = stateKey + ">" + elementName;
|
||||
|
||||
|
@ -10,8 +10,9 @@ import { BaseSavegameInterface } from "./savegame_interface";
|
||||
import { createLogger } from "../core/logging";
|
||||
import { globalConfig } from "../core/config";
|
||||
import { SavegameInterface_V1000 } from "./schemas/1000";
|
||||
import { getSavegameInterface } from "./savegame_interface_registry";
|
||||
import { getSavegameInterface, savegameInterfaces } from "./savegame_interface_registry";
|
||||
import { SavegameInterface_V1001 } from "./schemas/1001";
|
||||
import { SavegameInterface_V1002 } from "./schemas/1002";
|
||||
|
||||
const logger = createLogger("savegame");
|
||||
|
||||
@ -30,6 +31,11 @@ export class Savegame extends ReadWriteProxy {
|
||||
|
||||
/** @type {import("./savegame_typedefs").SavegameData} */
|
||||
this.currentData = this.getDefaultData();
|
||||
|
||||
assert(
|
||||
savegameInterfaces[Savegame.getCurrentVersion()],
|
||||
"Savegame interface not defined: " + Savegame.getCurrentVersion()
|
||||
);
|
||||
}
|
||||
|
||||
//////// RW Proxy Impl //////////
|
||||
@ -38,14 +44,14 @@ export class Savegame extends ReadWriteProxy {
|
||||
* @returns {number}
|
||||
*/
|
||||
static getCurrentVersion() {
|
||||
return 1001;
|
||||
return 1002;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {typeof BaseSavegameInterface}
|
||||
*/
|
||||
static getReaderClass() {
|
||||
return SavegameInterface_V1001;
|
||||
return savegameInterfaces[Savegame.getCurrentVersion()];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,6 +88,11 @@ export class Savegame extends ReadWriteProxy {
|
||||
data.version = 1001;
|
||||
}
|
||||
|
||||
if (data.version === 1001) {
|
||||
SavegameInterface_V1002.migrate1001to1002(data);
|
||||
data.version = 1002;
|
||||
}
|
||||
|
||||
return ExplainedResult.good();
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,13 @@ import { BaseSavegameInterface } from "./savegame_interface";
|
||||
import { SavegameInterface_V1000 } from "./schemas/1000";
|
||||
import { createLogger } from "../core/logging";
|
||||
import { SavegameInterface_V1001 } from "./schemas/1001";
|
||||
import { SavegameInterface_V1002 } from "./schemas/1002";
|
||||
|
||||
/** @type {Object.<number, typeof BaseSavegameInterface>} */
|
||||
const interfaces = {
|
||||
export const savegameInterfaces = {
|
||||
1000: SavegameInterface_V1000,
|
||||
1001: SavegameInterface_V1001,
|
||||
1002: SavegameInterface_V1002,
|
||||
};
|
||||
|
||||
const logger = createLogger("savegame_interface_registry");
|
||||
@ -27,7 +29,7 @@ export function getSavegameInterface(savegame) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const interfaceClass = interfaces[version];
|
||||
const interfaceClass = savegameInterfaces[version];
|
||||
if (!interfaceClass) {
|
||||
logger.warn("Version", version, "has no implemented interface!");
|
||||
return null;
|
||||
|
37
src/js/savegame/schemas/1002.js
Normal file
37
src/js/savegame/schemas/1002.js
Normal file
@ -0,0 +1,37 @@
|
||||
import { createLogger } from "../../core/logging.js";
|
||||
import { T } from "../../translations.js";
|
||||
import { SavegameInterface_V1001 } from "./1001.js";
|
||||
|
||||
const schema = require("./1002.json");
|
||||
const logger = createLogger("savegame_interface/1002");
|
||||
|
||||
export class SavegameInterface_V1002 extends SavegameInterface_V1001 {
|
||||
getVersion() {
|
||||
return 1002;
|
||||
}
|
||||
|
||||
getSchemaUncached() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../savegame_typedefs.js").SavegameData} data
|
||||
*/
|
||||
static migrate1001to1002(data) {
|
||||
logger.log("Migrating 1001 to 1002");
|
||||
const dump = data.dump;
|
||||
if (!dump) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const entities = dump.entities;
|
||||
for (let i = 0; i < entities.length; ++i) {
|
||||
const entity = entities[i];
|
||||
const beltComp = entity.components.Belt;
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
if (beltComp && ejectorComp) {
|
||||
ejectorComp.instantEject = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
5
src/js/savegame/schemas/1002.json
Normal file
5
src/js/savegame/schemas/1002.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"type": "object",
|
||||
"required": [],
|
||||
"additionalProperties": true
|
||||
}
|
Loading…
Reference in New Issue
Block a user