1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Update blueprint.js

Only create SerializerInternal when needed.
This commit is contained in:
FatCatX 2021-06-15 21:45:05 -07:00
parent fe021b1f0e
commit 0f693938ee

View File

@ -16,7 +16,6 @@ export class Blueprint {
*/ */
constructor(entities) { constructor(entities) {
this.entities = entities; this.entities = entities;
this.serializer = new SerializerInternal();
} }
/** /**
@ -34,7 +33,7 @@ export class Blueprint {
* Serialize * Serialize
*/ */
serialize() { serialize() {
let data = this.serializer.serializeEntityArray(this.entities); let data = new SerializerInternal().serializeEntityArray(this.entities);
// Remove unneeded fields // Remove unneeded fields
for (let i = 0; i < data.length; ++i) { for (let i = 0; i < data.length; ++i) {
const entry = data[i]; const entry = data[i];
@ -58,6 +57,8 @@ export class Blueprint {
if (!Array.isArray(json)) { if (!Array.isArray(json)) {
return; return;
} }
const serializer = new SerializerInternal();
/** @type {Array<Entity>} */ /** @type {Array<Entity>} */
const entityArray = []; const entityArray = [];
for (let i = 0; i < json.length; ++i) { for (let i = 0; i < json.length; ++i) {
@ -70,7 +71,7 @@ export class Blueprint {
if (staticData.code == undefined || staticData.origin == undefined) { if (staticData.code == undefined || staticData.origin == undefined) {
return; return;
} }
const result = new SerializerInternal().deserializeEntity(root, value); const result = serializer.deserializeEntity(root, value);
if (typeof result === "string") { if (typeof result === "string") {
throw new Error(result); throw new Error(result);
} }