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

Store wires state on save

This commit is contained in:
tobspr 2020-08-29 23:38:49 +02:00
parent b478f4be63
commit 091401e52b
4 changed files with 192 additions and 189 deletions

View File

@ -1,6 +1,6 @@
import { GameRoot } from "./root";
import { globalConfig, IS_DEBUG } from "../core/config";
import { globalConfig } from "../core/config";
import { createLogger } from "../core/logging";
import { GameRoot } from "./root";
// How important it is that a savegame is created
/**
@ -13,9 +13,6 @@ export const enumSavePriority = {
const logger = createLogger("autosave");
// Internals
let MIN_INTERVAL_SECS = 60;
export class AutomaticSave {
constructor(root) {
/** @type {GameRoot} */

View File

@ -142,14 +142,14 @@ export class GameSystemManager {
// WIRES section
add("lever", LeverSystem);
// Wires must be before all gate, signal etc logic!
add("wire", WireSystem);
// IMPORTANT: We have 2 phases: In phase 1 we compute the output values of all gates,
// processors etc. In phase 2 we propagate it through the wires network
add("logicGate", LogicGateSystem);
add("beltReader", BeltReaderSystem);
// Wires must be after all gate, signal etc logic!
add("wire", WireSystem);
add("display", DisplaySystem);
add("itemProcessorOverlays", ItemProcessorOverlaysSystem);

View File

@ -120,6 +120,7 @@ export class WireSystem extends GameSystemWithFilter {
this.root.signals.entityAdded.add(this.queueRecomputeIfWire, this);
this.needsRecompute = true;
this.isFirstRecompute = true;
this.staleArea = new StaleAreaDetector({
root: this.root,
@ -157,24 +158,29 @@ export class WireSystem extends GameSystemWithFilter {
this.networks = [];
// Clear all network references
const wireEntities = this.root.entityMgr.getAllWithComponent(WireComponent);
const tunnelEntities = this.root.entityMgr.getAllWithComponent(WireTunnelComponent);
const pinEntities = this.root.entityMgr.getAllWithComponent(WiredPinsComponent);
// Clear all network references, but not on the first update since thats the deserializing one
if (!this.isFirstRecompute) {
for (let i = 0; i < wireEntities.length; ++i) {
wireEntities[i].components.Wire.linkedNetwork = null;
}
const tunnelEntities = this.root.entityMgr.getAllWithComponent(WireTunnelComponent);
for (let i = 0; i < tunnelEntities.length; ++i) {
tunnelEntities[i].components.WireTunnel.linkedNetworks = [];
}
const pinEntities = this.root.entityMgr.getAllWithComponent(WiredPinsComponent);
for (let i = 0; i < pinEntities.length; ++i) {
const slots = pinEntities[i].components.WiredPins.slots;
for (let k = 0; k < slots.length; ++k) {
slots[k].linkedNetwork = null;
}
}
} else {
logger.log("Recomputing wires first time");
this.isFirstRecompute = false;
}
VERBOSE_WIRES && logger.log("Recomputing slots");

View File

@ -26,7 +26,7 @@ export class SerializerInternal {
/**
*
* @param {GameRoot} root
* @param {Array<any>} array
* @param {Array<Entity>} array
* @returns {string|void}
*/
deserializeEntityArray(root, array) {