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