1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Fix multiple issues regarding saving / restoring games

This commit is contained in:
tobspr
2020-07-05 16:56:01 +02:00
parent 0b9b35b79e
commit 34ef26b289
12 changed files with 73 additions and 39 deletions

View File

@@ -52,7 +52,8 @@ export class Blueprint {
}
averagePosition.divideScalarInplace(uids.length);
const blueprintOrigin = averagePosition.floor();
const blueprintOrigin = averagePosition.subScalars(0.5, 0.5).floor();
for (let i = 0; i < uids.length; ++i) {
newEntities[i].components.StaticMapEntity.origin.subInplace(blueprintOrigin);
}

View File

@@ -81,6 +81,7 @@ export class MetaEnergyGenerator extends MetaBuilding {
layer: enumLayer.wires,
},
],
instantEject: true,
})
);
@@ -88,7 +89,7 @@ export class MetaEnergyGenerator extends MetaBuilding {
new EnergyGeneratorComponent({
// Set by the energy generator system later
requiredKey: null,
acceptorSlotIndex: 2,
wasteAcceptorSlotIndex: 2,
})
);

View File

@@ -12,16 +12,27 @@ export class EnergyConsumerComponent extends Component {
return {
bufferSize: types.float,
perCharge: types.float,
stored: types.float,
piledOutput: types.float,
batteryPosition: types.vector,
energyType: types.enum(enumItemType),
wasteType: types.enum(enumItemType),
acceptorSlotIndex: types.uint,
ejectorSlotIndex: types.uint,
stored: types.float,
piledOutput: types.float,
};
}
duplicateWithoutContents() {
return new EnergyConsumerComponent({
bufferSize: this.bufferSize,
perCharge: this.perCharge,
batteryPosition: this.batteryPosition.copy(),
acceptorSlotIndex: this.acceptorSlotIndex,
ejectorSlotIndex: this.ejectorSlotIndex,
});
}
/**
*
* @param {object} param0

View File

@@ -3,7 +3,7 @@ import { BaseItem } from "../base_item";
import { Component } from "../component";
import { ShapeItem } from "../items/shape_item";
const maxQueueSize = 20;
const maxQueueSize = 4;
export class EnergyGeneratorComponent extends Component {
static getId() {
@@ -14,16 +14,24 @@ export class EnergyGeneratorComponent extends Component {
return {
requiredKey: types.nullable(types.string),
itemsInQueue: types.uint,
wasteAcceptorSlotIndex: types.uint,
};
}
duplicateWithoutContents() {
return new EnergyGeneratorComponent({
requiredKey: null,
wasteAcceptorSlotIndex: this.wasteAcceptorSlotIndex,
});
}
/**
*
* @param {object} param0
* @param {string} param0.requiredKey Which shape this generator needs, can be null if not computed yet
* @param {number} param0.acceptorSlotIndex
* @param {string=} param0.requiredKey Which shape this generator needs, can be null if not computed yet
* @param {number} param0.wasteAcceptorSlotIndex Which slot accepts the waste
*/
constructor({ requiredKey, acceptorSlotIndex = 0 }) {
constructor({ requiredKey, wasteAcceptorSlotIndex = 0 }) {
super();
this.requiredKey = requiredKey;
@@ -37,7 +45,7 @@ export class EnergyGeneratorComponent extends Component {
* Stores which slot accepts the waste
* @type {number}
*/
this.acceptorSlotIndex = acceptorSlotIndex;
this.wasteAcceptorSlotIndex = wasteAcceptorSlotIndex;
}
/**
@@ -46,7 +54,7 @@ export class EnergyGeneratorComponent extends Component {
* @param {number} slot
*/
tryTakeItem(item, slot) {
if (slot === this.acceptorSlotIndex) {
if (slot === this.wasteAcceptorSlotIndex) {
// this is the acceptor slot on the wires layer
// just destroy it
return true;

View File

@@ -48,6 +48,20 @@ export class WiredPinsComponent extends Component {
this.setSlots(slots);
}
duplicateWithoutContents() {
const slots = [];
for (let i = 0; i < this.slots.length; ++i) {
const slot = this.slots[i];
slots.push({
pos: slot.pos.copy(),
type: slot.type,
direction: slot.direction,
});
}
return new WiredPinsComponent({ slots });
}
/**
* Sets the slots of this building
* @param {Array<WirePinSlotDefinition>} slots

View File

@@ -82,7 +82,7 @@ export class PlatformWrapperImplBrowser extends PlatformWrapperInterface {
return new Promise(resolve => {
logger.log("Detecting storage");
if (!window.indexedDB) {
if (!window.indexedDB || G_IS_DEV) {
logger.log("Indexed DB not supported");
this.app.storage = new StorageImplBrowser(this.app);
resolve();

View File

@@ -26,10 +26,6 @@ export class SavegameSerializer {
* @returns {object}
*/
generateDumpFromGameRoot(root, sanityChecks = true) {
// Finalize particles before saving (Like granting destroy indicator rewards)
// root.particleMgr.finalizeBeforeSave();
// root.uiParticleMgr.finalizeBeforeSave();
// Now store generic savegame payload
const data = {
camera: root.camera.serialize(),

View File

@@ -1,15 +1,9 @@
/* typehints:start */
import { GameRoot } from "../game/root";
/* typehints:end */
import { gComponentRegistry } from "../core/global_registries";
import { createLogger } from "../core/logging";
import { Entity } from "../game/entity";
import { enumLayer, GameRoot } from "../game/root";
// Internal serializer methods
export class SerializerInternal {
constructor() {}
/**
* Serializes an array of entities
* @param {Array<Entity>} array
@@ -45,6 +39,11 @@ export class SerializerInternal {
deserializeEntity(root, payload) {
const entity = new Entity(root);
this.deserializeComponents(entity, payload.components);
entity.layer = payload.layer;
if (!enumLayer[payload.layer]) {
assert(false, "Invalid layer: " + payload.layer);
}
root.entityMgr.registerEntity(entity, payload.uid);