mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Fix savegame bugs
This commit is contained in:
parent
e1e27b4822
commit
65721e0837
@ -199,7 +199,7 @@ export class BeltPath extends BasicSerializableObject {
|
||||
/**
|
||||
* Finds the entity which accepts our items
|
||||
* @param {boolean=} debug_Silent Whether debug output should be silent
|
||||
* @return { (BaseItem, number) => boolean }
|
||||
* @return { (BaseItem, number?) => boolean }
|
||||
*/
|
||||
computeAcceptingEntityAndSlot(debug_Silent = false) {
|
||||
DEBUG && !debug_Silent && logger.log("Recomputing acceptor target");
|
||||
|
@ -3,9 +3,9 @@ import { Entity } from "../entity";
|
||||
/* typehints:end */
|
||||
|
||||
import { enumDirection, Vector } from "../../core/vector";
|
||||
import { enumConstantSignalType, ConstantSignalComponent } from "../components/constant_signal";
|
||||
import { ConstantSignalComponent } from "../components/constant_signal";
|
||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||
import { enumItemProducerType, ItemProducerComponent } from "../components/item_producer";
|
||||
import { ItemProducerComponent } from "../components/item_producer";
|
||||
import { MetaBuilding } from "../meta_building";
|
||||
|
||||
export class MetaConstantProducerBuilding extends MetaBuilding {
|
||||
@ -36,15 +36,7 @@ export class MetaConstantProducerBuilding extends MetaBuilding {
|
||||
slots: [{ pos: new Vector(0, 0), direction: enumDirection.top }],
|
||||
})
|
||||
);
|
||||
entity.addComponent(
|
||||
new ItemProducerComponent({
|
||||
type: enumItemProducerType.wireless,
|
||||
})
|
||||
);
|
||||
entity.addComponent(
|
||||
new ConstantSignalComponent({
|
||||
type: enumConstantSignalType.wireless,
|
||||
})
|
||||
);
|
||||
entity.addComponent(new ItemProducerComponent({}));
|
||||
entity.addComponent(new ConstantSignalComponent({}));
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,7 @@ import { Entity } from "../entity";
|
||||
/* typehints:end */
|
||||
|
||||
import { enumDirection, Vector } from "../../core/vector";
|
||||
import { enumBeltReaderType, BeltReaderComponent } from "../components/belt_reader";
|
||||
import { GoalAcceptorComponent } from "../components/goal_acceptor";
|
||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
||||
import { MetaBuilding } from "../meta_building";
|
||||
|
@ -110,6 +110,6 @@ export class MetaReaderBuilding extends MetaBuilding {
|
||||
})
|
||||
);
|
||||
|
||||
entity.addComponent(new BeltReaderComponent({}));
|
||||
entity.addComponent(new BeltReaderComponent());
|
||||
}
|
||||
}
|
||||
|
@ -16,20 +16,12 @@ export class BeltReaderComponent extends Component {
|
||||
|
||||
static getSchema() {
|
||||
return {
|
||||
type: types.string,
|
||||
lastItem: types.nullable(typeItemSingleton),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} param0
|
||||
* @param {string=} param0.type
|
||||
*/
|
||||
constructor({ type = enumBeltReaderType.wired }) {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.type = type;
|
||||
|
||||
this.clear();
|
||||
}
|
||||
|
||||
@ -58,8 +50,4 @@ export class BeltReaderComponent extends Component {
|
||||
*/
|
||||
this.lastThroughputComputation = 0;
|
||||
}
|
||||
|
||||
isWireless() {
|
||||
return this.type === enumBeltReaderType.wireless;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,8 @@
|
||||
import { gItemRegistry } from "../../core/global_registries";
|
||||
import { types } from "../../savegame/serialization";
|
||||
import { Component } from "../component";
|
||||
import { BaseItem } from "../base_item";
|
||||
import { Component } from "../component";
|
||||
import { typeItemSingleton } from "../item_resolver";
|
||||
|
||||
/** @enum {string} */
|
||||
export const enumConstantSignalType = {
|
||||
wired: "wired",
|
||||
wireless: "wireless",
|
||||
};
|
||||
|
||||
export class ConstantSignalComponent extends Component {
|
||||
static getId() {
|
||||
return "ConstantSignal";
|
||||
@ -17,7 +10,6 @@ export class ConstantSignalComponent extends Component {
|
||||
|
||||
static getSchema() {
|
||||
return {
|
||||
type: types.string,
|
||||
signal: types.nullable(typeItemSingleton),
|
||||
};
|
||||
}
|
||||
@ -28,22 +20,15 @@ export class ConstantSignalComponent extends Component {
|
||||
*/
|
||||
copyAdditionalStateTo(otherComponent) {
|
||||
otherComponent.signal = this.signal;
|
||||
otherComponent.type = this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {string=} param0.type
|
||||
* @param {BaseItem=} param0.signal The signal to store
|
||||
*/
|
||||
constructor({ signal = null, type = enumConstantSignalType.wired }) {
|
||||
constructor({ signal = null }) {
|
||||
super();
|
||||
this.signal = signal;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
isWireless() {
|
||||
return this.type === enumConstantSignalType.wireless;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,6 @@
|
||||
import { types } from "../../savegame/serialization";
|
||||
import { Component } from "../component";
|
||||
|
||||
/** @enum {string} */
|
||||
export const enumItemProducerType = {
|
||||
wired: "wired",
|
||||
wireless: "wireless",
|
||||
};
|
||||
|
||||
export class ItemProducerComponent extends Component {
|
||||
static getId() {
|
||||
return "ItemProducer";
|
||||
@ -17,17 +11,4 @@ export class ItemProducerComponent extends Component {
|
||||
type: types.string,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} param0
|
||||
* @param {string=} param0.type
|
||||
*/
|
||||
constructor({ type = enumItemProducerType.wired }) {
|
||||
super();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
isWireless() {
|
||||
return this.type === enumItemProducerType.wireless;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ export class BeltReaderSystem extends GameSystemWithFilter {
|
||||
readerComp.lastItemTimes.shift();
|
||||
}
|
||||
|
||||
if (!entity.components.BeltReader.isWireless()) {
|
||||
if (pinsComp) {
|
||||
pinsComp.slots[1].value = readerComp.lastItem;
|
||||
pinsComp.slots[0].value =
|
||||
(readerComp.lastItemTimes[readerComp.lastItemTimes.length - 1] || 0) >
|
||||
|
@ -16,15 +16,11 @@ export class ConstantProducerSystem extends GameSystemWithFilter {
|
||||
update() {
|
||||
for (let i = 0; i < this.allEntities.length; ++i) {
|
||||
const entity = this.allEntities[i];
|
||||
const producerComp = entity.components.ItemProducer;
|
||||
const signalComp = entity.components.ConstantSignal;
|
||||
|
||||
if (!producerComp.isWireless() || !signalComp.isWireless()) {
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
if (!ejectorComp) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
|
||||
ejectorComp.tryEject(0, signalComp.signal);
|
||||
}
|
||||
}
|
||||
@ -41,7 +37,7 @@ export class ConstantProducerSystem extends GameSystemWithFilter {
|
||||
const producerComp = contents[i].components.ItemProducer;
|
||||
const signalComp = contents[i].components.ConstantSignal;
|
||||
|
||||
if (!producerComp || !producerComp.isWireless() || !signalComp || !signalComp.isWireless()) {
|
||||
if (!producerComp || !signalComp) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import { fillInLinkIntoTranslation } from "../../core/utils";
|
||||
import { T } from "../../translations";
|
||||
import { BaseItem } from "../base_item";
|
||||
import { enumColors } from "../colors";
|
||||
import { ConstantSignalComponent, enumConstantSignalType } from "../components/constant_signal";
|
||||
import { ConstantSignalComponent } from "../components/constant_signal";
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON } from "../items/boolean_item";
|
||||
@ -27,13 +27,11 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
for (let i = 0; i < this.allEntities.length; ++i) {
|
||||
const entity = this.allEntities[i];
|
||||
const signalComp = entity.components.ConstantSignal;
|
||||
|
||||
if (signalComp.isWireless()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
pinsComp.slots[0].value = signalComp.signal;
|
||||
|
||||
if (pinsComp) {
|
||||
pinsComp.slots[0].value = signalComp.signal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,19 +54,20 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
label: fillInLinkIntoTranslation(T.dialogs.editSignal.descShortKey, THIRDPARTY_URLS.shapeViewer),
|
||||
placeholder: "",
|
||||
defaultValue: "",
|
||||
validator: val => this.parseSignalCode(entity.components.ConstantSignal.type, val),
|
||||
validator: val => this.parseSignalCode(entity, val),
|
||||
});
|
||||
|
||||
const items = [...Object.values(COLOR_ITEM_SINGLETONS)];
|
||||
|
||||
if (entity.components.ConstantSignal.type === enumConstantSignalType.wired) {
|
||||
if (entity.components.WiredPins) {
|
||||
items.unshift(BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON);
|
||||
items.push(
|
||||
this.root.shapeDefinitionMgr.getShapeItemFromShortKey(
|
||||
this.root.gameMode.getBlueprintShapeKey()
|
||||
)
|
||||
);
|
||||
} else if (entity.components.ConstantSignal.type === enumConstantSignalType.wireless) {
|
||||
} else {
|
||||
// producer which can produce virtually anything
|
||||
const shapes = ["CuCuCuCu", "RuRuRuRu", "WuWuWuWu", "SuSuSuSu"];
|
||||
items.unshift(
|
||||
...shapes.reverse().map(key => this.root.shapeDefinitionMgr.getShapeItemFromShortKey(key))
|
||||
@ -129,10 +128,7 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
if (itemInput.chosenItem) {
|
||||
constantComp.signal = itemInput.chosenItem;
|
||||
} else {
|
||||
constantComp.signal = this.parseSignalCode(
|
||||
entity.components.ConstantSignal.type,
|
||||
signalValueInput.getValue()
|
||||
);
|
||||
constantComp.signal = this.parseSignalCode(entity, signalValueInput.getValue());
|
||||
}
|
||||
};
|
||||
|
||||
@ -171,11 +167,11 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
|
||||
/**
|
||||
* Tries to parse a signal code
|
||||
* @param {string} type
|
||||
* @param {Entity} entity
|
||||
* @param {string} code
|
||||
* @returns {BaseItem}
|
||||
*/
|
||||
parseSignalCode(type, code) {
|
||||
parseSignalCode(entity, code) {
|
||||
if (!this.root || !this.root.shapeDefinitionMgr) {
|
||||
// Stale reference
|
||||
return null;
|
||||
@ -188,7 +184,7 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
return COLOR_ITEM_SINGLETONS[codeLower];
|
||||
}
|
||||
|
||||
if (type === enumConstantSignalType.wired) {
|
||||
if (entity.components.WiredPins) {
|
||||
if (code === "1" || codeLower === "true") {
|
||||
return BOOL_TRUE_SINGLETON;
|
||||
}
|
||||
|
@ -15,14 +15,12 @@ export class ItemProducerSystem extends GameSystemWithFilter {
|
||||
update() {
|
||||
for (let i = 0; i < this.allEntities.length; ++i) {
|
||||
const entity = this.allEntities[i];
|
||||
const producerComp = entity.components.ItemProducer;
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
|
||||
if (producerComp.isWireless()) {
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
if (!pinsComp) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
const pin = pinsComp.slots[0];
|
||||
const network = pin.linkedNetwork;
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
import { GameRoot } from "../game/root";
|
||||
import { PuzzleGameMode } from "../game/modes/puzzle";
|
||||
/* typehints:end */
|
||||
import { enumConstantSignalType } from "../game/components/constant_signal";
|
||||
import { StaticMapEntityComponent } from "../game/components/static_map_entity";
|
||||
import { ShapeItem } from "../game/items/shape_item";
|
||||
import { Vector } from "../core/vector";
|
||||
@ -38,7 +37,6 @@ export class PuzzleSerializer {
|
||||
const signalComp = entity.components.ConstantSignal;
|
||||
|
||||
if (signalComp) {
|
||||
assert(signalComp.type === enumConstantSignalType.wireless, "not a wireless signal");
|
||||
assert(["shape", "color"].includes(signalComp.signal.getItemType()), "not a shape signal");
|
||||
buildings.push({
|
||||
type: "emitter",
|
||||
|
@ -275,7 +275,7 @@ export function deserializeSchema(obj, schema, data, baseclassErrorResult = null
|
||||
return baseclassErrorResult;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
if (data === null || typeof data === "undefined") {
|
||||
logger.error("Got 'NULL' data for", obj, "and schema", schema, "!");
|
||||
return "Got null data";
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ export class PuzzleMenuState extends TextualGameState {
|
||||
/**
|
||||
*
|
||||
* @param {*} category
|
||||
* @returns {Promise<import("../savegame/savegame_typedefs").PuzzleMetadata[]}
|
||||
* @returns {Promise<import("../savegame/savegame_typedefs").PuzzleMetadata[]>}
|
||||
*/
|
||||
getPuzzlesForCategory(category) {
|
||||
if (category === "levels") {
|
||||
|
Loading…
Reference in New Issue
Block a user