mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
refactor processing requirement
This commit is contained in:
parent
997cde22d9
commit
15b8addb40
@ -3,13 +3,12 @@ import { enumDirection, Vector } from "../../core/vector";
|
|||||||
import { T } from "../../translations";
|
import { T } from "../../translations";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
import { enumItemProcessorTypes, ItemProcessorComponent, enumItemProcessorRequirements } from "../components/item_processor";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { defaultBuildingVariant, MetaBuilding } from "../meta_building";
|
import { defaultBuildingVariant, MetaBuilding } from "../meta_building";
|
||||||
import { GameRoot } from "../root";
|
import { GameRoot } from "../root";
|
||||||
import { enumHubGoalRewards } from "../tutorial_goals";
|
import { enumHubGoalRewards } from "../tutorial_goals";
|
||||||
import { WiredPinsComponent, enumPinSlotType } from "../components/wired_pins";
|
import { WiredPinsComponent, enumPinSlotType } from "../components/wired_pins";
|
||||||
import { ProcessingRequirementComponent } from "../components/processing_requirement";
|
|
||||||
|
|
||||||
/** @enum {string} */
|
/** @enum {string} */
|
||||||
export const enumPainterVariants = { mirrored: "mirrored", double: "double", quad: "quad" };
|
export const enumPainterVariants = { mirrored: "mirrored", double: "double", quad: "quad" };
|
||||||
@ -124,9 +123,6 @@ export class MetaPainterBuilding extends MetaBuilding {
|
|||||||
if (entity.components.WiredPins) {
|
if (entity.components.WiredPins) {
|
||||||
entity.removeComponent(WiredPinsComponent)
|
entity.removeComponent(WiredPinsComponent)
|
||||||
}
|
}
|
||||||
if (entity.components.ProcessingRequirement) {
|
|
||||||
entity.removeComponent(ProcessingRequirementComponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
@ -144,7 +140,9 @@ export class MetaPainterBuilding extends MetaBuilding {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.painter;
|
entity.components.ItemProcessor.type = enumItemProcessorTypes.painter;
|
||||||
|
entity.components.ItemProcessor.processingRequirement = null;
|
||||||
entity.components.ItemProcessor.inputsPerCharge = 2;
|
entity.components.ItemProcessor.inputsPerCharge = 2;
|
||||||
|
|
||||||
entity.components.ItemEjector.setSlots([
|
entity.components.ItemEjector.setSlots([
|
||||||
{ pos: new Vector(1, 0), direction: enumDirection.right },
|
{ pos: new Vector(1, 0), direction: enumDirection.right },
|
||||||
]);
|
]);
|
||||||
@ -154,9 +152,6 @@ export class MetaPainterBuilding extends MetaBuilding {
|
|||||||
if (entity.components.WiredPins) {
|
if (entity.components.WiredPins) {
|
||||||
entity.removeComponent(WiredPinsComponent)
|
entity.removeComponent(WiredPinsComponent)
|
||||||
}
|
}
|
||||||
if (entity.components.ProcessingRequirement) {
|
|
||||||
entity.removeComponent(ProcessingRequirementComponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
@ -177,6 +172,7 @@ export class MetaPainterBuilding extends MetaBuilding {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.painterDouble;
|
entity.components.ItemProcessor.type = enumItemProcessorTypes.painterDouble;
|
||||||
|
entity.components.ItemProcessor.processingRequirement = null;
|
||||||
entity.components.ItemProcessor.inputsPerCharge = 3;
|
entity.components.ItemProcessor.inputsPerCharge = 3;
|
||||||
|
|
||||||
entity.components.ItemEjector.setSlots([
|
entity.components.ItemEjector.setSlots([
|
||||||
@ -212,12 +208,6 @@ export class MetaPainterBuilding extends MetaBuilding {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entity.components.ProcessingRequirement) {
|
|
||||||
entity.addComponent(new ProcessingRequirementComponent({
|
|
||||||
processorType: enumItemProcessorTypes.painterQuad
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
@ -247,6 +237,7 @@ export class MetaPainterBuilding extends MetaBuilding {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.painterQuad;
|
entity.components.ItemProcessor.type = enumItemProcessorTypes.painterQuad;
|
||||||
|
entity.components.ItemProcessor.processingRequirement = enumItemProcessorRequirements.painterQuad;
|
||||||
entity.components.ItemProcessor.inputsPerCharge = 5;
|
entity.components.ItemProcessor.inputsPerCharge = 5;
|
||||||
|
|
||||||
entity.components.ItemEjector.setSlots([
|
entity.components.ItemEjector.setSlots([
|
||||||
|
@ -15,7 +15,6 @@ import { ConstantSignalComponent } from "./components/constant_signal";
|
|||||||
import { LogicGateComponent } from "./components/logic_gate";
|
import { LogicGateComponent } from "./components/logic_gate";
|
||||||
import { LeverComponent } from "./components/lever";
|
import { LeverComponent } from "./components/lever";
|
||||||
import { WireTunnelComponent } from "./components/wire_tunnel";
|
import { WireTunnelComponent } from "./components/wire_tunnel";
|
||||||
import { ProcessingRequirementComponent } from "./components/processing_requirement";
|
|
||||||
import { DisplayComponent } from "./components/display";
|
import { DisplayComponent } from "./components/display";
|
||||||
|
|
||||||
export function initComponentRegistry() {
|
export function initComponentRegistry() {
|
||||||
@ -35,7 +34,6 @@ export function initComponentRegistry() {
|
|||||||
gComponentRegistry.register(LogicGateComponent);
|
gComponentRegistry.register(LogicGateComponent);
|
||||||
gComponentRegistry.register(LeverComponent);
|
gComponentRegistry.register(LeverComponent);
|
||||||
gComponentRegistry.register(WireTunnelComponent);
|
gComponentRegistry.register(WireTunnelComponent);
|
||||||
gComponentRegistry.register(ProcessingRequirementComponent);
|
|
||||||
gComponentRegistry.register(DisplayComponent);
|
gComponentRegistry.register(DisplayComponent);
|
||||||
|
|
||||||
// IMPORTANT ^^^^^ UPDATE ENTITY COMPONENT STORAGE AFTERWARDS
|
// IMPORTANT ^^^^^ UPDATE ENTITY COMPONENT STORAGE AFTERWARDS
|
||||||
|
@ -22,6 +22,11 @@ export const enumItemProcessorTypes = {
|
|||||||
filter: "filter",
|
filter: "filter",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @enum {string} */
|
||||||
|
export const enumItemProcessorRequirements = {
|
||||||
|
painterQuad: "painterQuad"
|
||||||
|
};
|
||||||
|
|
||||||
export class ItemProcessorComponent extends Component {
|
export class ItemProcessorComponent extends Component {
|
||||||
static getId() {
|
static getId() {
|
||||||
return "ItemProcessor";
|
return "ItemProcessor";
|
||||||
@ -50,6 +55,7 @@ export class ItemProcessorComponent extends Component {
|
|||||||
duplicateWithoutContents() {
|
duplicateWithoutContents() {
|
||||||
return new ItemProcessorComponent({
|
return new ItemProcessorComponent({
|
||||||
processorType: this.type,
|
processorType: this.type,
|
||||||
|
processingRequirement: this.processingRequirement,
|
||||||
inputsPerCharge: this.inputsPerCharge,
|
inputsPerCharge: this.inputsPerCharge,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -58,10 +64,15 @@ export class ItemProcessorComponent extends Component {
|
|||||||
*
|
*
|
||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {enumItemProcessorTypes=} param0.processorType Which type of processor this is
|
* @param {enumItemProcessorTypes=} param0.processorType Which type of processor this is
|
||||||
|
* @param {enumItemProcessorRequirements=} param0.processingRequirement Applied processing requirement
|
||||||
* @param {number=} param0.inputsPerCharge How many items this machine needs until it can start working
|
* @param {number=} param0.inputsPerCharge How many items this machine needs until it can start working
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
constructor({ processorType = enumItemProcessorTypes.splitter, inputsPerCharge = 1 }) {
|
constructor({
|
||||||
|
processorType = enumItemProcessorTypes.splitter,
|
||||||
|
processingRequirement = null,
|
||||||
|
inputsPerCharge = 1
|
||||||
|
}) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
// Which slot to emit next, this is only a preference and if it can't emit
|
// Which slot to emit next, this is only a preference and if it can't emit
|
||||||
@ -72,6 +83,9 @@ export class ItemProcessorComponent extends Component {
|
|||||||
// Type of the processor
|
// Type of the processor
|
||||||
this.type = processorType;
|
this.type = processorType;
|
||||||
|
|
||||||
|
// Type of processing requirement
|
||||||
|
this.processingRequirement = processingRequirement;
|
||||||
|
|
||||||
// How many inputs we need for one charge
|
// How many inputs we need for one charge
|
||||||
this.inputsPerCharge = inputsPerCharge;
|
this.inputsPerCharge = inputsPerCharge;
|
||||||
|
|
||||||
|
@ -1,90 +0,0 @@
|
|||||||
import { Component } from "../component";
|
|
||||||
import { enumItemProcessorTypes } from "./item_processor";
|
|
||||||
import { Entity } from "../entity";
|
|
||||||
import { BOOL_TRUE_SINGLETON } from "../items/boolean_item";
|
|
||||||
import { BaseItem } from "../base_item";
|
|
||||||
import { ShapeItem } from "../items/shape_item";
|
|
||||||
|
|
||||||
export class ProcessingRequirementComponent extends Component {
|
|
||||||
static getId() {
|
|
||||||
return "ProcessingRequirement";
|
|
||||||
}
|
|
||||||
|
|
||||||
duplicateWithoutContents() {
|
|
||||||
return new ProcessingRequirementComponent({
|
|
||||||
processorType: this.type
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {object} param0
|
|
||||||
* @param {enumItemProcessorTypes=} param0.processorType Which type of processor this is
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
constructor({ processorType = enumItemProcessorTypes.painterQuad }) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
// Type of the processor
|
|
||||||
this.type = processorType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether it's possible to process something
|
|
||||||
* @param {Entity} entity
|
|
||||||
*/
|
|
||||||
canProcess(entity) {
|
|
||||||
switch (this.type) {
|
|
||||||
case enumItemProcessorTypes.painterQuad: {
|
|
||||||
// For quad-painter, pins match slots
|
|
||||||
// boolean true means "disable input"
|
|
||||||
// a color means "disable if not matched"
|
|
||||||
|
|
||||||
const processorComp = entity.components.ItemProcessor;
|
|
||||||
const pinsComp = entity.components.WiredPins;
|
|
||||||
|
|
||||||
/** @type {Object.<string, { item: BaseItem, sourceSlot: number }>} */
|
|
||||||
const itemsBySlot = {};
|
|
||||||
for (let i = 0; i < processorComp.inputSlots.length; ++i) {
|
|
||||||
itemsBySlot[processorComp.inputSlots[i].sourceSlot] = processorComp.inputSlots[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
// first slot is the shape
|
|
||||||
if (!itemsBySlot[0]) return false;
|
|
||||||
const shapeItem = /** @type {ShapeItem} */ (itemsBySlot[0].item);
|
|
||||||
|
|
||||||
// Here we check just basic things`
|
|
||||||
// Stop processing if anything except TRUE is
|
|
||||||
// set and there is no item.
|
|
||||||
for (let i = 0; i < 4; ++i) {
|
|
||||||
const netValue = pinsComp.slots[i].linkedNetwork ?
|
|
||||||
pinsComp.slots[i].linkedNetwork.currentValue :
|
|
||||||
null;
|
|
||||||
|
|
||||||
const currentItem = itemsBySlot[i + 1];
|
|
||||||
|
|
||||||
if ((netValue == null || !netValue.equals(BOOL_TRUE_SINGLETON)) && currentItem == null) {
|
|
||||||
let quadCount = 0;
|
|
||||||
|
|
||||||
for (let j = 0; j < 4; ++j) {
|
|
||||||
const layer = shapeItem.definition.layers[j];
|
|
||||||
if (layer && layer[i]) {
|
|
||||||
quadCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (quadCount > 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
assertAlways(false, "Unknown requirement for " + this.type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -15,7 +15,6 @@ import { ConstantSignalComponent } from "./components/constant_signal";
|
|||||||
import { LogicGateComponent } from "./components/logic_gate";
|
import { LogicGateComponent } from "./components/logic_gate";
|
||||||
import { LeverComponent } from "./components/lever";
|
import { LeverComponent } from "./components/lever";
|
||||||
import { WireTunnelComponent } from "./components/wire_tunnel";
|
import { WireTunnelComponent } from "./components/wire_tunnel";
|
||||||
import { ProcessingRequirementComponent } from "./components/processing_requirement";
|
|
||||||
import { DisplayComponent } from "./components/display";
|
import { DisplayComponent } from "./components/display";
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
|
|
||||||
@ -75,9 +74,6 @@ export class EntityComponentStorage {
|
|||||||
/** @type {WireTunnelComponent} */
|
/** @type {WireTunnelComponent} */
|
||||||
this.WireTunnel;
|
this.WireTunnel;
|
||||||
|
|
||||||
/** @type {ProcessingRequirementComponent} */
|
|
||||||
this.ProcessingRequirement;
|
|
||||||
|
|
||||||
/** @type {DisplayComponent} */
|
/** @type {DisplayComponent} */
|
||||||
this.Display;
|
this.Display;
|
||||||
|
|
||||||
|
@ -601,7 +601,7 @@ export class ShapeDefinition extends BasicSerializableObject {
|
|||||||
for (let quadrantIndex = 0; quadrantIndex < 4; ++quadrantIndex) {
|
for (let quadrantIndex = 0; quadrantIndex < 4; ++quadrantIndex) {
|
||||||
const item = quadrants[quadrantIndex];
|
const item = quadrants[quadrantIndex];
|
||||||
if (item) {
|
if (item) {
|
||||||
item.color = colors[quadrantIndex] || null;
|
item.color = colors[quadrantIndex] || item.color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { globalConfig } from "../../core/config";
|
import { globalConfig } from "../../core/config";
|
||||||
import { BaseItem } from "../base_item";
|
import { BaseItem } from "../base_item";
|
||||||
import { enumColors, enumColorMixingResults } from "../colors";
|
import { enumColors, enumColorMixingResults } from "../colors";
|
||||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
import { enumItemProcessorTypes, ItemProcessorComponent, enumItemProcessorRequirements } from "../components/item_processor";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||||
import { BOOL_TRUE_SINGLETON, BOOL_FALSE_SINGLETON } from "../items/boolean_item";
|
import { BOOL_TRUE_SINGLETON, BOOL_FALSE_SINGLETON } from "../items/boolean_item";
|
||||||
@ -72,10 +72,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
// Check if we have an empty queue and can start a new charge
|
// Check if we have an empty queue and can start a new charge
|
||||||
if (processorComp.itemsToEject.length === 0) {
|
if (processorComp.itemsToEject.length === 0) {
|
||||||
const procRequirementComp = entity.components.ProcessingRequirement;
|
if (entity.components.ItemProcessor.processingRequirement) {
|
||||||
|
if (this.canProcess(entity)) {
|
||||||
if (procRequirementComp) {
|
|
||||||
if (procRequirementComp.canProcess(entity)) {
|
|
||||||
this.startNewCharge(entity);
|
this.startNewCharge(entity);
|
||||||
}
|
}
|
||||||
} else if (processorComp.inputSlots.length >= processorComp.inputsPerCharge) {
|
} else if (processorComp.inputSlots.length >= processorComp.inputsPerCharge) {
|
||||||
@ -85,6 +83,66 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether it's possible to process something
|
||||||
|
* @param {Entity} entity
|
||||||
|
*/
|
||||||
|
canProcess(entity) {
|
||||||
|
switch (entity.components.ItemProcessor.processingRequirement) {
|
||||||
|
case enumItemProcessorRequirements.painterQuad: {
|
||||||
|
// For quad-painter, pins match slots
|
||||||
|
// boolean true means "disable input"
|
||||||
|
// a color means "disable if not matched"
|
||||||
|
|
||||||
|
const processorComp = entity.components.ItemProcessor;
|
||||||
|
const pinsComp = entity.components.WiredPins;
|
||||||
|
|
||||||
|
/** @type {Object.<string, { item: BaseItem, sourceSlot: number }>} */
|
||||||
|
const itemsBySlot = {};
|
||||||
|
for (let i = 0; i < processorComp.inputSlots.length; ++i) {
|
||||||
|
itemsBySlot[processorComp.inputSlots[i].sourceSlot] = processorComp.inputSlots[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// first slot is the shape
|
||||||
|
if (!itemsBySlot[0]) return false;
|
||||||
|
const shapeItem = /** @type {ShapeItem} */ (itemsBySlot[0].item);
|
||||||
|
|
||||||
|
// Here we check just basic things`
|
||||||
|
// Stop processing if anything except TRUE is
|
||||||
|
// set and there is no item.
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
const netValue = pinsComp.slots[i].linkedNetwork ?
|
||||||
|
pinsComp.slots[i].linkedNetwork.currentValue :
|
||||||
|
null;
|
||||||
|
|
||||||
|
const currentItem = itemsBySlot[i + 1];
|
||||||
|
|
||||||
|
if ((netValue == null || !netValue.equals(BOOL_TRUE_SINGLETON)) && currentItem == null) {
|
||||||
|
let quadCount = 0;
|
||||||
|
|
||||||
|
for (let j = 0; j < 4; ++j) {
|
||||||
|
const layer = shapeItem.definition.layers[j];
|
||||||
|
if (layer && layer[i]) {
|
||||||
|
quadCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quadCount > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
assertAlways(
|
||||||
|
false,
|
||||||
|
"Unknown requirement for " + entity.components.ItemProcessor.processingRequirement
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a new charge for the entity
|
* Starts a new charge for the entity
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
@ -361,7 +419,6 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
(!skipped[2] && colorBR) ? colorBR.color : null,
|
(!skipped[2] && colorBR) ? colorBR.color : null,
|
||||||
(!skipped[3] && colorBL) ? colorBL.color : null,
|
(!skipped[3] && colorBL) ? colorBL.color : null,
|
||||||
];
|
];
|
||||||
console.table([colorTL, skipped[0], colorTR, skipped[1]]);
|
|
||||||
|
|
||||||
const colorizedDefinition = this.root.shapeDefinitionMgr.shapeActionPaintWith4Colors(
|
const colorizedDefinition = this.root.shapeDefinitionMgr.shapeActionPaintWith4Colors(
|
||||||
shapeItem.definition,
|
shapeItem.definition,
|
||||||
|
Loading…
Reference in New Issue
Block a user