mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Remove unused code (#526)
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
/* typehints:start */
|
||||
import { Application } from "../application";
|
||||
import { GameRoot } from "../game/root";
|
||||
/* typehints:end */
|
||||
|
||||
import { ReadWriteProxy } from "../core/read_write_proxy";
|
||||
import { ExplainedResult } from "../core/explained_result";
|
||||
import { SavegameSerializer } from "./savegame_serializer";
|
||||
@@ -18,20 +13,29 @@ import { SavegameInterface_V1005 } from "./schemas/1005";
|
||||
|
||||
const logger = createLogger("savegame");
|
||||
|
||||
/**
|
||||
* @typedef {import("../application").Application} Application
|
||||
* @typedef {import("../game/root").GameRoot} GameRoot
|
||||
* @typedef {import("./savegame_typedefs").SavegameData} SavegameData
|
||||
* @typedef {import("./savegame_typedefs").SavegameMetadata} SavegameMetadata
|
||||
* @typedef {import("./savegame_typedefs").SavegameStats} SavegameStats
|
||||
* @typedef {import("./savegame_typedefs").SerializedGame} SerializedGame
|
||||
*/
|
||||
|
||||
export class Savegame extends ReadWriteProxy {
|
||||
/**
|
||||
*
|
||||
* @param {Application} app
|
||||
* @param {object} param0
|
||||
* @param {string} param0.internalId
|
||||
* @param {import("./savegame_manager").SavegameMetadata} param0.metaDataRef Handle to the meta data
|
||||
* @param {SavegameMetadata} param0.metaDataRef Handle to the meta data
|
||||
*/
|
||||
constructor(app, { internalId, metaDataRef }) {
|
||||
super(app, "savegame-" + internalId + ".bin");
|
||||
this.internalId = internalId;
|
||||
this.metaDataRef = metaDataRef;
|
||||
|
||||
/** @type {import("./savegame_typedefs").SavegameData} */
|
||||
/** @type {SavegameData} */
|
||||
this.currentData = this.getDefaultData();
|
||||
|
||||
assert(
|
||||
@@ -65,7 +69,7 @@ export class Savegame extends ReadWriteProxy {
|
||||
|
||||
/**
|
||||
* Returns the savegames default data
|
||||
* @returns {import("./savegame_typedefs").SavegameData}
|
||||
* @returns {SavegameData}
|
||||
*/
|
||||
getDefaultData() {
|
||||
return {
|
||||
@@ -78,7 +82,7 @@ export class Savegame extends ReadWriteProxy {
|
||||
|
||||
/**
|
||||
* Migrates the savegames data
|
||||
* @param {import("./savegame_typedefs").SavegameData} data
|
||||
* @param {SavegameData} data
|
||||
*/
|
||||
migrate(data) {
|
||||
if (data.version < 1000) {
|
||||
@@ -115,7 +119,7 @@ export class Savegame extends ReadWriteProxy {
|
||||
|
||||
/**
|
||||
* Verifies the savegames data
|
||||
* @param {import("./savegame_typedefs").SavegameData} data
|
||||
* @param {SavegameData} data
|
||||
*/
|
||||
verify(data) {
|
||||
if (!data.dump) {
|
||||
@@ -140,7 +144,7 @@ export class Savegame extends ReadWriteProxy {
|
||||
}
|
||||
/**
|
||||
* Returns the statistics of the savegame
|
||||
* @returns {import("./savegame_typedefs").SavegameStats}
|
||||
* @returns {SavegameStats}
|
||||
*/
|
||||
getStatistics() {
|
||||
return this.currentData.stats;
|
||||
@@ -163,7 +167,7 @@ export class Savegame extends ReadWriteProxy {
|
||||
|
||||
/**
|
||||
* Returns the current game dump
|
||||
* @returns {import("./savegame_typedefs").SerializedGame}
|
||||
* @returns {SerializedGame}
|
||||
*/
|
||||
getCurrentDump() {
|
||||
return this.currentData.dump;
|
||||
|
||||
@@ -7,31 +7,21 @@ const logger = createLogger("savegame_manager");
|
||||
|
||||
const Rusha = require("rusha");
|
||||
|
||||
/**
|
||||
* @typedef {import("./savegame_typedefs").SavegamesData} SavegamesData
|
||||
* @typedef {import("./savegame_typedefs").SavegameMetadata} SavegameMetadata
|
||||
*/
|
||||
|
||||
/** @enum {string} */
|
||||
export const enumLocalSavegameStatus = {
|
||||
offline: "offline",
|
||||
synced: "synced",
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* lastUpdate: number,
|
||||
* version: number,
|
||||
* internalId: string,
|
||||
* level: number
|
||||
* }} SavegameMetadata
|
||||
*
|
||||
* @typedef {{
|
||||
* version: number,
|
||||
* savegames: Array<SavegameMetadata>
|
||||
* }} SavegamesData
|
||||
*/
|
||||
|
||||
export class SavegameManager extends ReadWriteProxy {
|
||||
constructor(app) {
|
||||
super(app, "savegames.bin");
|
||||
|
||||
/** @type {SavegamesData} */
|
||||
this.currentData = this.getDefaultData();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
/* typehints:start */
|
||||
import { Component } from "../game/component";
|
||||
import { GameRoot } from "../game/root";
|
||||
/* typehints:end */
|
||||
|
||||
import { ExplainedResult } from "../core/explained_result";
|
||||
import { createLogger } from "../core/logging";
|
||||
// import { BuildingComponent } from "../components/impl/building";
|
||||
import { gComponentRegistry } from "../core/global_registries";
|
||||
import { SerializerInternal } from "./serializer_internal";
|
||||
|
||||
/**
|
||||
* @typedef {import("../game/component").Component} Component
|
||||
* @typedef {import("../game/component").StaticComponent} StaticComponent
|
||||
* @typedef {import("../game/entity").Entity} Entity
|
||||
* @typedef {import("../game/root").GameRoot} GameRoot
|
||||
* @typedef {import("../savegame/savegame_typedefs").SerializedGame} SerializedGame
|
||||
*/
|
||||
|
||||
const logger = createLogger("savegame_serializer");
|
||||
|
||||
/**
|
||||
* Allows to serialize a savegame
|
||||
* Serializes a savegame
|
||||
*/
|
||||
export class SavegameSerializer {
|
||||
constructor() {
|
||||
@@ -26,7 +28,7 @@ export class SavegameSerializer {
|
||||
* @returns {object}
|
||||
*/
|
||||
generateDumpFromGameRoot(root, sanityChecks = true) {
|
||||
// Now store generic savegame payload
|
||||
/** @type {SerializedGame} */
|
||||
const data = {
|
||||
camera: root.camera.serialize(),
|
||||
time: root.time.serialize(),
|
||||
@@ -35,11 +37,10 @@ export class SavegameSerializer {
|
||||
hubGoals: root.hubGoals.serialize(),
|
||||
pinnedShapes: root.hud.parts.pinnedShapes.serialize(),
|
||||
waypoints: root.hud.parts.waypoints.serialize(),
|
||||
entities: this.internal.serializeEntityArray(root.entityMgr.entities),
|
||||
beltPaths: root.systemMgr.systems.belt.serializePaths(),
|
||||
};
|
||||
|
||||
data.entities = this.internal.serializeEntityArray(root.entityMgr.entities);
|
||||
|
||||
if (!G_IS_RELEASE) {
|
||||
if (sanityChecks) {
|
||||
// Sanity check
|
||||
@@ -55,7 +56,7 @@ export class SavegameSerializer {
|
||||
|
||||
/**
|
||||
* Verifies if there are logical errors in the savegame
|
||||
* @param {object} savegame
|
||||
* @param {SerializedGame} savegame
|
||||
* @returns {ExplainedResult}
|
||||
*/
|
||||
verifyLogicalErrors(savegame) {
|
||||
@@ -66,47 +67,44 @@ export class SavegameSerializer {
|
||||
const seenUids = [];
|
||||
|
||||
// Check for duplicate UIDS
|
||||
for (const entityListId in savegame.entities) {
|
||||
for (let i = 0; i < savegame.entities[entityListId].length; ++i) {
|
||||
const list = savegame.entities[entityListId][i];
|
||||
for (let k = 0; k < list.length; ++k) {
|
||||
const entity = list[k];
|
||||
const uid = entity.uid;
|
||||
if (!Number.isInteger(uid)) {
|
||||
return ExplainedResult.bad("Entity has invalid uid: " + uid);
|
||||
}
|
||||
if (seenUids.indexOf(uid) >= 0) {
|
||||
return ExplainedResult.bad("Duplicate uid " + uid);
|
||||
}
|
||||
seenUids.push(uid);
|
||||
for (let i = 0; i < savegame.entities.length; ++i) {
|
||||
/** @type {Entity} */
|
||||
const entity = savegame.entities[i];
|
||||
|
||||
// Verify components
|
||||
if (!entity.components) {
|
||||
return ExplainedResult.bad(
|
||||
"Entity is missing key 'components': " + JSON.stringify(entity)
|
||||
);
|
||||
}
|
||||
const components = entity.components;
|
||||
for (const componentId in components) {
|
||||
// Verify component data
|
||||
const componentData = components[componentId];
|
||||
const componentClass = gComponentRegistry.findById(componentId);
|
||||
const uid = entity.uid;
|
||||
if (!Number.isInteger(uid)) {
|
||||
return ExplainedResult.bad("Entity has invalid uid: " + uid);
|
||||
}
|
||||
if (seenUids.indexOf(uid) >= 0) {
|
||||
return ExplainedResult.bad("Duplicate uid " + uid);
|
||||
}
|
||||
seenUids.push(uid);
|
||||
|
||||
// Check component id is known
|
||||
if (!componentClass) {
|
||||
return ExplainedResult.bad("Unknown component id: " + componentId);
|
||||
}
|
||||
// Verify components
|
||||
if (!entity.components) {
|
||||
return ExplainedResult.bad("Entity is missing key 'components': " + JSON.stringify(entity));
|
||||
}
|
||||
|
||||
// Check component data is ok
|
||||
const componentVerifyError = /** @type {typeof Component} */ (componentClass).verify(
|
||||
componentData
|
||||
);
|
||||
if (componentVerifyError) {
|
||||
return ExplainedResult.bad(
|
||||
"Component " + componentId + " has invalid data: " + componentVerifyError
|
||||
);
|
||||
}
|
||||
}
|
||||
const components = entity.components;
|
||||
for (const componentId in components) {
|
||||
const componentClass = gComponentRegistry.findById(componentId);
|
||||
|
||||
// Check component id is known
|
||||
if (!componentClass) {
|
||||
return ExplainedResult.bad("Unknown component id: " + componentId);
|
||||
}
|
||||
|
||||
// Verify component data
|
||||
const componentData = components[componentId];
|
||||
const componentVerifyError = /** @type {StaticComponent} */ (componentClass).verify(
|
||||
componentData
|
||||
);
|
||||
|
||||
// Check component data is ok
|
||||
if (componentVerifyError) {
|
||||
return ExplainedResult.bad(
|
||||
"Component " + componentId + " has invalid data: " + componentVerifyError
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,7 +114,7 @@ export class SavegameSerializer {
|
||||
|
||||
/**
|
||||
* Tries to load the savegame from a given dump
|
||||
* @param {import("./savegame_typedefs").SerializedGame} savegame
|
||||
* @param {SerializedGame} savegame
|
||||
* @param {GameRoot} root
|
||||
* @returns {ExplainedResult}
|
||||
*/
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
import { Entity } from "../game/entity";
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* }} SavegameStats
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import("../game/entity").Entity} Entity
|
||||
*
|
||||
* @typedef {{}} SavegameStats
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* camera: any,
|
||||
* time: any,
|
||||
@@ -21,13 +14,25 @@ import { Entity } from "../game/entity";
|
||||
* entities: Array<Entity>,
|
||||
* beltPaths: Array<any>
|
||||
* }} SerializedGame
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @typedef {{
|
||||
* version: number,
|
||||
* dump: SerializedGame,
|
||||
* stats: SavegameStats,
|
||||
* lastUpdate: number,
|
||||
* }} SavegameData
|
||||
*
|
||||
* @typedef {{
|
||||
* lastUpdate: number,
|
||||
* version: number,
|
||||
* internalId: string,
|
||||
* level: number
|
||||
* }} SavegameMetadata
|
||||
*
|
||||
* @typedef {{
|
||||
* version: number,
|
||||
* savegames: Array<SavegameMetadata>
|
||||
* }} SavegamesData
|
||||
*/
|
||||
|
||||
export default {};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { BasicSerializableObject } from "./serialization";
|
||||
/* typehints:end */
|
||||
|
||||
import { Vector } from "../core/vector";
|
||||
import { round4Digits, schemaObject, accessNestedPropertyReverse } from "../core/utils";
|
||||
import { round4Digits } from "../core/utils";
|
||||
export const globalJsonSchemaDefs = {};
|
||||
|
||||
/**
|
||||
@@ -28,6 +28,19 @@ export function schemaToJsonSchema(schema) {
|
||||
return jsonSchema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create a json schema object
|
||||
* @param {any} properties
|
||||
*/
|
||||
function schemaObject(properties) {
|
||||
return {
|
||||
type: "object",
|
||||
required: Object.keys(properties).slice(),
|
||||
additionalProperties: false,
|
||||
properties,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Base serialization data type
|
||||
*/
|
||||
@@ -75,23 +88,6 @@ export class BaseDataType {
|
||||
return {
|
||||
$ref: "#/definitions/" + key,
|
||||
};
|
||||
|
||||
// return this.getAsJsonSchemaUncached();
|
||||
// if (!globalJsonSchemaDefs[key]) {
|
||||
// // schema.$id = key;
|
||||
// globalJsonSchemaDefs[key] = {
|
||||
// $id: key,
|
||||
// definitions: {
|
||||
// ["d-" + key]: schema
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
|
||||
// return {
|
||||
// $ref: key + "#/definitions/d-" + key
|
||||
// }
|
||||
|
||||
// // return this.getAsJsonSchemaUncached();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user