mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Fix tslint errors
This commit is contained in:
@@ -141,24 +141,6 @@ export class SavegameSerializer {
|
||||
// entities
|
||||
errorReason = errorReason || root.entityMgr.deserialize(savegame.entityMgr);
|
||||
|
||||
// resources
|
||||
errorReason =
|
||||
errorReason ||
|
||||
this.internal.deserializeEntityArrayFixedType(
|
||||
root,
|
||||
savegame.entities.resources,
|
||||
this.internal.deserializeResource
|
||||
);
|
||||
|
||||
// buildings
|
||||
errorReason =
|
||||
errorReason ||
|
||||
this.internal.deserializeEntityArray(
|
||||
root,
|
||||
savegame.entities.buildings,
|
||||
this.internal.deserializeBuilding
|
||||
);
|
||||
|
||||
// other stuff
|
||||
errorReason = errorReason || root.time.deserialize(savegame.time);
|
||||
errorReason = errorReason || root.camera.deserialize(savegame.camera);
|
||||
|
||||
@@ -270,8 +270,7 @@ export function deserializeSchema(obj, schema, data, baseclassErrorResult = null
|
||||
|
||||
const errorStatus = schema[key].deserializeWithVerify(data[key], obj, key, obj.root);
|
||||
if (errorStatus) {
|
||||
error(
|
||||
"serialization",
|
||||
logger.error(
|
||||
"Deserialization failed with error '" + errorStatus + "' on object",
|
||||
obj,
|
||||
"and key",
|
||||
@@ -294,17 +293,17 @@ export function deserializeSchema(obj, schema, data, baseclassErrorResult = null
|
||||
export function verifySchema(schema, data) {
|
||||
for (const key in schema) {
|
||||
if (!data.hasOwnProperty(key)) {
|
||||
error("verify", "Data", data, "does not contain", key, "(schema:", schema, ")");
|
||||
logger.error("Data", data, "does not contain", key, "(schema:", schema, ")");
|
||||
return "verify: missing key required by schema in stored data: " + key;
|
||||
}
|
||||
if (!schema[key].allowNull() && (data[key] === null || data[key] === undefined)) {
|
||||
error("verify", "Data", data, "has null value for", key, "(schema:", schema, ")");
|
||||
logger.error("Data", data, "has null value for", key, "(schema:", schema, ")");
|
||||
return "verify: non-nullable entry is null: " + key;
|
||||
}
|
||||
|
||||
const errorStatus = schema[key].verifySerializedValue(data[key]);
|
||||
if (errorStatus) {
|
||||
error("verify", errorStatus);
|
||||
logger.error(errorStatus);
|
||||
return "verify: " + errorStatus;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Vector } from "../core/vector";
|
||||
import { createLogger } from "../core/logging";
|
||||
import { gMetaBuildingRegistry } from "../core/global_registries";
|
||||
import { Entity } from "../game/entity";
|
||||
import { MapResourcesSystem } from "../game/systems/map_resources";
|
||||
|
||||
const logger = createLogger("serializer_internal");
|
||||
|
||||
@@ -80,61 +81,6 @@ export class SerializerInternal {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a building
|
||||
* @param {GameRoot} root
|
||||
* @param {{ $: string, data: any }} payload
|
||||
*/
|
||||
deserializeBuilding(root, payload) {
|
||||
const data = payload.data;
|
||||
const id = payload.$;
|
||||
if (!gMetaBuildingRegistry.hasId(id)) {
|
||||
return "Metaclass not found for building: '" + id + "'";
|
||||
}
|
||||
const meta = gMetaBuildingRegistry.findById(id);
|
||||
if (!meta) {
|
||||
return "Metaclass not found for building: '" + id + "'";
|
||||
}
|
||||
|
||||
const tile = new Vector(data.x, data.y).toTileSpace();
|
||||
const instance = root.logic.internalPlaceBuildingLocalClientOnly({
|
||||
tile: tile,
|
||||
metaBuilding: meta,
|
||||
uid: data.uid,
|
||||
});
|
||||
|
||||
// Apply component specific properties
|
||||
const errorStatus = this.deserializeComponents(instance, data.components);
|
||||
if (errorStatus) {
|
||||
return errorStatus;
|
||||
}
|
||||
|
||||
// Apply enhancements
|
||||
instance.updateEnhancements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a blueprint
|
||||
* @param {GameRoot} root
|
||||
* @param {any} data
|
||||
* @returns {string|void}
|
||||
*/
|
||||
deserializeBlueprint(root, data) {
|
||||
const id = data.meta;
|
||||
const metaClass = gMetaBuildingRegistry.findById(id);
|
||||
if (!metaClass) {
|
||||
return "Metaclass not found for blueprint: '" + id + "'";
|
||||
}
|
||||
|
||||
const tile = new Vector(data.x, data.y).toTileSpace();
|
||||
const instance = root.logic.internalPlaceBlueprintLocalClientOnly({
|
||||
tile: tile,
|
||||
metaBuilding: metaClass,
|
||||
uid: data.uid,
|
||||
});
|
||||
return this.deserializeComponents(instance, data.components);
|
||||
}
|
||||
|
||||
/////// COMPONENTS ////
|
||||
|
||||
/**
|
||||
@@ -161,20 +107,4 @@ export class SerializerInternal {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a resource
|
||||
* @param {GameRoot} root
|
||||
* @param {object} data
|
||||
* @returns {string|void}
|
||||
*/
|
||||
deserializeResource(root, data) {
|
||||
const id = data.key;
|
||||
const instance = new MapResource(root, this.neutralFaction, id);
|
||||
root.logic.internalPlaceMapEntityLocalClientOnly(
|
||||
new Vector(data.x, data.y).toTileSpace(),
|
||||
instance,
|
||||
data.uid
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user