Added layersupport to waypoints!! (#703)
* Added layersupport to waypoints!! It will now save what layer its made on! * Added Migrator for 1006 to 1007 * Corrected Version Number * Updated Comment * Changed HUB Layer to be hardcoded
This commit is contained in:
parent
82aaf7f037
commit
944b3c011c
|
@ -1,6 +1,7 @@
|
||||||
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
|
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
|
||||||
import { globalConfig, THIRDPARTY_URLS } from "../../../core/config";
|
import { globalConfig, THIRDPARTY_URLS } from "../../../core/config";
|
||||||
import { DrawParameters } from "../../../core/draw_parameters";
|
import { DrawParameters } from "../../../core/draw_parameters";
|
||||||
|
import { gMetaBuildingRegistry } from "../../../core/global_registries";
|
||||||
import { Loader } from "../../../core/loader";
|
import { Loader } from "../../../core/loader";
|
||||||
import { DialogWithForm } from "../../../core/modal_dialog_elements";
|
import { DialogWithForm } from "../../../core/modal_dialog_elements";
|
||||||
import { FormElementInput } from "../../../core/modal_dialog_forms";
|
import { FormElementInput } from "../../../core/modal_dialog_forms";
|
||||||
|
@ -16,8 +17,10 @@ import {
|
||||||
import { Vector } from "../../../core/vector";
|
import { Vector } from "../../../core/vector";
|
||||||
import { T } from "../../../translations";
|
import { T } from "../../../translations";
|
||||||
import { BaseItem } from "../../base_item";
|
import { BaseItem } from "../../base_item";
|
||||||
|
import { MetaHubBuilding } from "../../buildings/hub";
|
||||||
import { enumMouseButton } from "../../camera";
|
import { enumMouseButton } from "../../camera";
|
||||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||||
|
import { layers } from "../../root";
|
||||||
import { ShapeDefinition } from "../../shape_definition";
|
import { ShapeDefinition } from "../../shape_definition";
|
||||||
import { BaseHUDPart } from "../base_hud_part";
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||||
|
@ -26,7 +29,8 @@ import { enumNotificationType } from "./notifications";
|
||||||
/** @typedef {{
|
/** @typedef {{
|
||||||
* label: string | null,
|
* label: string | null,
|
||||||
* center: { x: number, y: number },
|
* center: { x: number, y: number },
|
||||||
* zoomLevel: number
|
* zoomLevel: number,
|
||||||
|
* layer: Layer,
|
||||||
* }} Waypoint */
|
* }} Waypoint */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,6 +102,7 @@ export class HUDWaypoints extends BaseHUDPart {
|
||||||
label: null,
|
label: null,
|
||||||
center: { x: 0, y: 0 },
|
center: { x: 0, y: 0 },
|
||||||
zoomLevel: 3,
|
zoomLevel: 3,
|
||||||
|
layer: gMetaBuildingRegistry.findByClass(MetaHubBuilding).getLayer(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -228,6 +233,7 @@ export class HUDWaypoints extends BaseHUDPart {
|
||||||
* @param {Waypoint} waypoint
|
* @param {Waypoint} waypoint
|
||||||
*/
|
*/
|
||||||
moveToWaypoint(waypoint) {
|
moveToWaypoint(waypoint) {
|
||||||
|
this.root.currentLayer = waypoint.layer;
|
||||||
this.root.camera.setDesiredCenter(new Vector(waypoint.center.x, waypoint.center.y));
|
this.root.camera.setDesiredCenter(new Vector(waypoint.center.x, waypoint.center.y));
|
||||||
this.root.camera.setDesiredZoom(waypoint.zoomLevel);
|
this.root.camera.setDesiredZoom(waypoint.zoomLevel);
|
||||||
}
|
}
|
||||||
|
@ -326,6 +332,7 @@ export class HUDWaypoints extends BaseHUDPart {
|
||||||
label,
|
label,
|
||||||
center: { x: position.x, y: position.y },
|
center: { x: position.x, y: position.y },
|
||||||
zoomLevel: this.root.camera.zoomLevel,
|
zoomLevel: this.root.camera.zoomLevel,
|
||||||
|
layer: this.root.currentLayer,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.sortWaypoints();
|
this.sortWaypoints();
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { SavegameInterface_V1003 } from "./schemas/1003";
|
||||||
import { SavegameInterface_V1004 } from "./schemas/1004";
|
import { SavegameInterface_V1004 } from "./schemas/1004";
|
||||||
import { SavegameInterface_V1005 } from "./schemas/1005";
|
import { SavegameInterface_V1005 } from "./schemas/1005";
|
||||||
import { SavegameInterface_V1006 } from "./schemas/1006";
|
import { SavegameInterface_V1006 } from "./schemas/1006";
|
||||||
|
import { SavegameInterface_V1007 } from "./schemas/1007";
|
||||||
|
|
||||||
const logger = createLogger("savegame");
|
const logger = createLogger("savegame");
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ export class Savegame extends ReadWriteProxy {
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
static getCurrentVersion() {
|
static getCurrentVersion() {
|
||||||
return 1006;
|
return 1007;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,6 +121,11 @@ export class Savegame extends ReadWriteProxy {
|
||||||
data.version = 1006;
|
data.version = 1006;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.version === 1006) {
|
||||||
|
SavegameInterface_V1007.migrate1006to1007(data);
|
||||||
|
data.version = 1007;
|
||||||
|
}
|
||||||
|
|
||||||
return ExplainedResult.good();
|
return ExplainedResult.good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { SavegameInterface_V1003 } from "./schemas/1003";
|
||||||
import { SavegameInterface_V1004 } from "./schemas/1004";
|
import { SavegameInterface_V1004 } from "./schemas/1004";
|
||||||
import { SavegameInterface_V1005 } from "./schemas/1005";
|
import { SavegameInterface_V1005 } from "./schemas/1005";
|
||||||
import { SavegameInterface_V1006 } from "./schemas/1006";
|
import { SavegameInterface_V1006 } from "./schemas/1006";
|
||||||
|
import { SavegameInterface_V1007 } from "./schemas/1007";
|
||||||
|
|
||||||
/** @type {Object.<number, typeof BaseSavegameInterface>} */
|
/** @type {Object.<number, typeof BaseSavegameInterface>} */
|
||||||
export const savegameInterfaces = {
|
export const savegameInterfaces = {
|
||||||
|
@ -17,6 +18,7 @@ export const savegameInterfaces = {
|
||||||
1004: SavegameInterface_V1004,
|
1004: SavegameInterface_V1004,
|
||||||
1005: SavegameInterface_V1005,
|
1005: SavegameInterface_V1005,
|
||||||
1006: SavegameInterface_V1006,
|
1006: SavegameInterface_V1006,
|
||||||
|
1007: SavegameInterface_V1007,
|
||||||
};
|
};
|
||||||
|
|
||||||
const logger = createLogger("savegame_interface_registry");
|
const logger = createLogger("savegame_interface_registry");
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
import { createLogger } from "../../core/logging.js";
|
||||||
|
import { SavegameInterface_V1006 } from "./1006.js";
|
||||||
|
|
||||||
|
const schema = require("./1007.json");
|
||||||
|
const logger = createLogger("savegame_interface/1007");
|
||||||
|
|
||||||
|
export class SavegameInterface_V1007 extends SavegameInterface_V1006 {
|
||||||
|
getVersion() {
|
||||||
|
return 1007;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSchemaUncached() {
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {import("../savegame_typedefs.js").SavegameData} data
|
||||||
|
*/
|
||||||
|
static migrate1006to1007(data) {
|
||||||
|
logger.log("Migrating 1006 to 1007");
|
||||||
|
const dump = data.dump;
|
||||||
|
if (!dump) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const waypoints = dump.waypoints.waypoints;
|
||||||
|
|
||||||
|
// set waypoint layer to "regular"
|
||||||
|
for (let i = 0; i < waypoints.length; ++i) {
|
||||||
|
const waypoint = waypoints[i];
|
||||||
|
waypoint.layer = "regular";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"required": [],
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
Reference in New Issue