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:
parent
b478f4be63
commit
091401e52b
@ -1,6 +1,6 @@
|
|||||||
import { GameRoot } from "./root";
|
import { globalConfig } from "../core/config";
|
||||||
import { globalConfig, IS_DEBUG } from "../core/config";
|
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
|
import { GameRoot } from "./root";
|
||||||
|
|
||||||
// How important it is that a savegame is created
|
// How important it is that a savegame is created
|
||||||
/**
|
/**
|
||||||
@ -13,9 +13,6 @@ export const enumSavePriority = {
|
|||||||
|
|
||||||
const logger = createLogger("autosave");
|
const logger = createLogger("autosave");
|
||||||
|
|
||||||
// Internals
|
|
||||||
let MIN_INTERVAL_SECS = 60;
|
|
||||||
|
|
||||||
export class AutomaticSave {
|
export class AutomaticSave {
|
||||||
constructor(root) {
|
constructor(root) {
|
||||||
/** @type {GameRoot} */
|
/** @type {GameRoot} */
|
||||||
|
@ -142,14 +142,14 @@ export class GameSystemManager {
|
|||||||
// WIRES section
|
// WIRES section
|
||||||
add("lever", LeverSystem);
|
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,
|
// 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
|
// processors etc. In phase 2 we propagate it through the wires network
|
||||||
add("logicGate", LogicGateSystem);
|
add("logicGate", LogicGateSystem);
|
||||||
add("beltReader", BeltReaderSystem);
|
add("beltReader", BeltReaderSystem);
|
||||||
|
|
||||||
// Wires must be after all gate, signal etc logic!
|
|
||||||
add("wire", WireSystem);
|
|
||||||
|
|
||||||
add("display", DisplaySystem);
|
add("display", DisplaySystem);
|
||||||
|
|
||||||
add("itemProcessorOverlays", ItemProcessorOverlaysSystem);
|
add("itemProcessorOverlays", ItemProcessorOverlaysSystem);
|
||||||
|
@ -120,6 +120,7 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
this.root.signals.entityAdded.add(this.queueRecomputeIfWire, this);
|
this.root.signals.entityAdded.add(this.queueRecomputeIfWire, this);
|
||||||
|
|
||||||
this.needsRecompute = true;
|
this.needsRecompute = true;
|
||||||
|
this.isFirstRecompute = true;
|
||||||
|
|
||||||
this.staleArea = new StaleAreaDetector({
|
this.staleArea = new StaleAreaDetector({
|
||||||
root: this.root,
|
root: this.root,
|
||||||
@ -157,24 +158,29 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
this.networks = [];
|
this.networks = [];
|
||||||
|
|
||||||
// Clear all network references
|
|
||||||
const wireEntities = this.root.entityMgr.getAllWithComponent(WireComponent);
|
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) {
|
for (let i = 0; i < wireEntities.length; ++i) {
|
||||||
wireEntities[i].components.Wire.linkedNetwork = null;
|
wireEntities[i].components.Wire.linkedNetwork = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tunnelEntities = this.root.entityMgr.getAllWithComponent(WireTunnelComponent);
|
|
||||||
for (let i = 0; i < tunnelEntities.length; ++i) {
|
for (let i = 0; i < tunnelEntities.length; ++i) {
|
||||||
tunnelEntities[i].components.WireTunnel.linkedNetworks = [];
|
tunnelEntities[i].components.WireTunnel.linkedNetworks = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const pinEntities = this.root.entityMgr.getAllWithComponent(WiredPinsComponent);
|
|
||||||
for (let i = 0; i < pinEntities.length; ++i) {
|
for (let i = 0; i < pinEntities.length; ++i) {
|
||||||
const slots = pinEntities[i].components.WiredPins.slots;
|
const slots = pinEntities[i].components.WiredPins.slots;
|
||||||
for (let k = 0; k < slots.length; ++k) {
|
for (let k = 0; k < slots.length; ++k) {
|
||||||
slots[k].linkedNetwork = null;
|
slots[k].linkedNetwork = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logger.log("Recomputing wires first time");
|
||||||
|
this.isFirstRecompute = false;
|
||||||
|
}
|
||||||
|
|
||||||
VERBOSE_WIRES && logger.log("Recomputing slots");
|
VERBOSE_WIRES && logger.log("Recomputing slots");
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ export class SerializerInternal {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {GameRoot} root
|
* @param {GameRoot} root
|
||||||
* @param {Array<any>} array
|
* @param {Array<Entity>} array
|
||||||
* @returns {string|void}
|
* @returns {string|void}
|
||||||
*/
|
*/
|
||||||
deserializeEntityArray(root, array) {
|
deserializeEntityArray(root, array) {
|
||||||
|
Loading…
Reference in New Issue
Block a user