mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Minor PR adjustments
This commit is contained in:
parent
e4f02abeb3
commit
d8b34ca438
@ -73,6 +73,12 @@ export class ItemProcessorComponent extends Component {
|
|||||||
// Type of processing requirement
|
// Type of processing requirement
|
||||||
this.processingRequirement = processingRequirement;
|
this.processingRequirement = processingRequirement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Our current inputs
|
||||||
|
* @type {Map<number, BaseItem>}
|
||||||
|
*/
|
||||||
|
this.inputSlots = new Map();
|
||||||
|
|
||||||
this.clear();
|
this.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,11 +88,7 @@ export class ItemProcessorComponent extends Component {
|
|||||||
// sure the outputs always match
|
// sure the outputs always match
|
||||||
this.nextOutputSlot = 0;
|
this.nextOutputSlot = 0;
|
||||||
|
|
||||||
/**
|
this.inputSlots.clear();
|
||||||
* Our current inputs
|
|
||||||
* @type {Array<BaseItem?>}
|
|
||||||
*/
|
|
||||||
this.inputSlots = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current input count
|
* Current input count
|
||||||
@ -121,15 +123,16 @@ export class ItemProcessorComponent extends Component {
|
|||||||
this.type === enumItemProcessorTypes.goal
|
this.type === enumItemProcessorTypes.goal
|
||||||
) {
|
) {
|
||||||
// Hub has special logic .. not really nice but efficient.
|
// Hub has special logic .. not really nice but efficient.
|
||||||
this.inputSlots.push(item);
|
this.inputSlots.set(this.inputCount, item);
|
||||||
this.inputCount++;
|
this.inputCount++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that we only take one item per slot
|
// Check that we only take one item per slot
|
||||||
if (this.inputSlots[sourceSlot]) return false;
|
if (this.inputSlots.has(sourceSlot)) {
|
||||||
|
return false;
|
||||||
this.inputSlots[sourceSlot] = item;
|
}
|
||||||
|
this.inputSlots.set(sourceSlot, item);
|
||||||
this.inputCount++;
|
this.inputCount++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,8 @@ const MAX_QUEUED_CHARGES = 2;
|
|||||||
* Type of a processor implementation
|
* Type of a processor implementation
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* entity: Entity,
|
* entity: Entity,
|
||||||
* items: Array<BaseItem?>,
|
* items: Map<number, BaseItem>,
|
||||||
|
* inputCount: number,
|
||||||
* outItems: Array<ProducedItem>
|
* outItems: Array<ProducedItem>
|
||||||
* }} ProcessorImplementationPayload
|
* }} ProcessorImplementationPayload
|
||||||
*/
|
*/
|
||||||
@ -197,11 +198,11 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
const pinsComp = entity.components.WiredPins;
|
const pinsComp = entity.components.WiredPins;
|
||||||
|
|
||||||
// First slot is the shape, so if it's not there we can't do anything
|
// First slot is the shape, so if it's not there we can't do anything
|
||||||
if (!processorComp.inputSlots[0]) {
|
const shapeItem = /** @type {ShapeItem} */ (processorComp.inputSlots.get(0));
|
||||||
|
if (!shapeItem) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shapeItem = /** @type {ShapeItem} */ (processorComp.inputSlots[0]);
|
|
||||||
const slotStatus = [];
|
const slotStatus = [];
|
||||||
|
|
||||||
// Check which slots are enabled
|
// Check which slots are enabled
|
||||||
@ -226,7 +227,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
// Check if all colors of the enabled slots are there
|
// Check if all colors of the enabled slots are there
|
||||||
for (let i = 0; i < slotStatus.length; ++i) {
|
for (let i = 0; i < slotStatus.length; ++i) {
|
||||||
if (slotStatus[i] && !processorComp.inputSlots[1 + i]) {
|
if (slotStatus[i] && !processorComp.inputSlots.get(1 + i)) {
|
||||||
// A slot which is enabled wasn't enabled. Make sure if there is anything on the quadrant,
|
// A slot which is enabled wasn't enabled. Make sure if there is anything on the quadrant,
|
||||||
// it is not possible to paint, but if there is nothing we can ignore it
|
// it is not possible to paint, but if there is nothing we can ignore it
|
||||||
for (let j = 0; j < 4; ++j) {
|
for (let j = 0; j < 4; ++j) {
|
||||||
@ -268,6 +269,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
entity,
|
entity,
|
||||||
items,
|
items,
|
||||||
outItems,
|
outItems,
|
||||||
|
inputCount: processorComp.inputCount,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Track produced items
|
// Track produced items
|
||||||
@ -290,7 +292,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
remainingTime: timeToProcess,
|
remainingTime: timeToProcess,
|
||||||
});
|
});
|
||||||
|
|
||||||
processorComp.inputSlots.length = 0;
|
processorComp.inputSlots.clear();
|
||||||
processorComp.inputCount = 0;
|
processorComp.inputCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,10 +309,14 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
const nextSlot = processorComp.nextOutputSlot++ % availableSlots;
|
const nextSlot = processorComp.nextOutputSlot++ % availableSlots;
|
||||||
|
|
||||||
for (let i = 0; i < payload.items.length; ++i) {
|
// Hardcoded to 2, to avoid accessing the length
|
||||||
if (!payload.items[i]) continue;
|
for (let i = 0; i < 2; ++i) {
|
||||||
|
const item = payload.items.get(i);
|
||||||
|
if (!item) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
payload.outItems.push({
|
payload.outItems.push({
|
||||||
item: payload.items[i],
|
item,
|
||||||
preferredSlot: (nextSlot + i) % availableSlots,
|
preferredSlot: (nextSlot + i) % availableSlots,
|
||||||
doNotTrack: true,
|
doNotTrack: true,
|
||||||
});
|
});
|
||||||
@ -322,7 +328,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
* @param {ProcessorImplementationPayload} payload
|
* @param {ProcessorImplementationPayload} payload
|
||||||
*/
|
*/
|
||||||
process_CUTTER(payload) {
|
process_CUTTER(payload) {
|
||||||
const inputItem = /** @type {ShapeItem} */ (payload.items[0]);
|
const inputItem = /** @type {ShapeItem} */ (payload.items.get(0));
|
||||||
assert(inputItem instanceof ShapeItem, "Input for cut is not a shape");
|
assert(inputItem instanceof ShapeItem, "Input for cut is not a shape");
|
||||||
const inputDefinition = inputItem.definition;
|
const inputDefinition = inputItem.definition;
|
||||||
|
|
||||||
@ -343,7 +349,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
* @param {ProcessorImplementationPayload} payload
|
* @param {ProcessorImplementationPayload} payload
|
||||||
*/
|
*/
|
||||||
process_CUTTER_QUAD(payload) {
|
process_CUTTER_QUAD(payload) {
|
||||||
const inputItem = /** @type {ShapeItem} */ (payload.items[0]);
|
const inputItem = /** @type {ShapeItem} */ (payload.items.get(0));
|
||||||
assert(inputItem instanceof ShapeItem, "Input for cut is not a shape");
|
assert(inputItem instanceof ShapeItem, "Input for cut is not a shape");
|
||||||
const inputDefinition = inputItem.definition;
|
const inputDefinition = inputItem.definition;
|
||||||
|
|
||||||
@ -364,7 +370,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
* @param {ProcessorImplementationPayload} payload
|
* @param {ProcessorImplementationPayload} payload
|
||||||
*/
|
*/
|
||||||
process_ROTATER(payload) {
|
process_ROTATER(payload) {
|
||||||
const inputItem = /** @type {ShapeItem} */ (payload.items[0]);
|
const inputItem = /** @type {ShapeItem} */ (payload.items.get(0));
|
||||||
assert(inputItem instanceof ShapeItem, "Input for rotation is not a shape");
|
assert(inputItem instanceof ShapeItem, "Input for rotation is not a shape");
|
||||||
const inputDefinition = inputItem.definition;
|
const inputDefinition = inputItem.definition;
|
||||||
|
|
||||||
@ -378,7 +384,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
* @param {ProcessorImplementationPayload} payload
|
* @param {ProcessorImplementationPayload} payload
|
||||||
*/
|
*/
|
||||||
process_ROTATER_CCW(payload) {
|
process_ROTATER_CCW(payload) {
|
||||||
const inputItem = /** @type {ShapeItem} */ (payload.items[0]);
|
const inputItem = /** @type {ShapeItem} */ (payload.items.get(0));
|
||||||
assert(inputItem instanceof ShapeItem, "Input for rotation is not a shape");
|
assert(inputItem instanceof ShapeItem, "Input for rotation is not a shape");
|
||||||
const inputDefinition = inputItem.definition;
|
const inputDefinition = inputItem.definition;
|
||||||
|
|
||||||
@ -392,7 +398,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
* @param {ProcessorImplementationPayload} payload
|
* @param {ProcessorImplementationPayload} payload
|
||||||
*/
|
*/
|
||||||
process_ROTATER_180(payload) {
|
process_ROTATER_180(payload) {
|
||||||
const inputItem = /** @type {ShapeItem} */ (payload.items[0]);
|
const inputItem = /** @type {ShapeItem} */ (payload.items.get(0));
|
||||||
assert(inputItem instanceof ShapeItem, "Input for rotation is not a shape");
|
assert(inputItem instanceof ShapeItem, "Input for rotation is not a shape");
|
||||||
const inputDefinition = inputItem.definition;
|
const inputDefinition = inputItem.definition;
|
||||||
|
|
||||||
@ -406,8 +412,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
* @param {ProcessorImplementationPayload} payload
|
* @param {ProcessorImplementationPayload} payload
|
||||||
*/
|
*/
|
||||||
process_STACKER(payload) {
|
process_STACKER(payload) {
|
||||||
const lowerItem = /** @type {ShapeItem} */ (payload.items[0]);
|
const lowerItem = /** @type {ShapeItem} */ (payload.items.get(0));
|
||||||
const upperItem = /** @type {ShapeItem} */ (payload.items[1]);
|
const upperItem = /** @type {ShapeItem} */ (payload.items.get(1));
|
||||||
|
|
||||||
assert(lowerItem instanceof ShapeItem, "Input for lower stack is not a shape");
|
assert(lowerItem instanceof ShapeItem, "Input for lower stack is not a shape");
|
||||||
assert(upperItem instanceof ShapeItem, "Input for upper stack is not a shape");
|
assert(upperItem instanceof ShapeItem, "Input for upper stack is not a shape");
|
||||||
@ -433,8 +439,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
*/
|
*/
|
||||||
process_MIXER(payload) {
|
process_MIXER(payload) {
|
||||||
// Find both colors and combine them
|
// Find both colors and combine them
|
||||||
const item1 = /** @type {ColorItem} */ (payload.items[0]);
|
const item1 = /** @type {ColorItem} */ (payload.items.get(0));
|
||||||
const item2 = /** @type {ColorItem} */ (payload.items[1]);
|
const item2 = /** @type {ColorItem} */ (payload.items.get(1));
|
||||||
assert(item1 instanceof ColorItem, "Input for color mixer is not a color");
|
assert(item1 instanceof ColorItem, "Input for color mixer is not a color");
|
||||||
assert(item2 instanceof ColorItem, "Input for color mixer is not a color");
|
assert(item2 instanceof ColorItem, "Input for color mixer is not a color");
|
||||||
|
|
||||||
@ -456,8 +462,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
* @param {ProcessorImplementationPayload} payload
|
* @param {ProcessorImplementationPayload} payload
|
||||||
*/
|
*/
|
||||||
process_PAINTER(payload) {
|
process_PAINTER(payload) {
|
||||||
const shapeItem = /** @type {ShapeItem} */ (payload.items[0]);
|
const shapeItem = /** @type {ShapeItem} */ (payload.items.get(0));
|
||||||
const colorItem = /** @type {ColorItem} */ (payload.items[1]);
|
const colorItem = /** @type {ColorItem} */ (payload.items.get(1));
|
||||||
|
|
||||||
const colorizedDefinition = this.root.shapeDefinitionMgr.shapeActionPaintWith(
|
const colorizedDefinition = this.root.shapeDefinitionMgr.shapeActionPaintWith(
|
||||||
shapeItem.definition,
|
shapeItem.definition,
|
||||||
@ -473,9 +479,9 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
* @param {ProcessorImplementationPayload} payload
|
* @param {ProcessorImplementationPayload} payload
|
||||||
*/
|
*/
|
||||||
process_PAINTER_DOUBLE(payload) {
|
process_PAINTER_DOUBLE(payload) {
|
||||||
const shapeItem1 = /** @type {ShapeItem} */ (payload.items[0]);
|
const shapeItem1 = /** @type {ShapeItem} */ (payload.items.get(0));
|
||||||
const shapeItem2 = /** @type {ShapeItem} */ (payload.items[1]);
|
const shapeItem2 = /** @type {ShapeItem} */ (payload.items.get(1));
|
||||||
const colorItem = /** @type {ColorItem} */ (payload.items[2]);
|
const colorItem = /** @type {ColorItem} */ (payload.items.get(2));
|
||||||
|
|
||||||
assert(shapeItem1 instanceof ShapeItem, "Input for painter is not a shape");
|
assert(shapeItem1 instanceof ShapeItem, "Input for painter is not a shape");
|
||||||
assert(shapeItem2 instanceof ShapeItem, "Input for painter is not a shape");
|
assert(shapeItem2 instanceof ShapeItem, "Input for painter is not a shape");
|
||||||
@ -503,14 +509,15 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
* @param {ProcessorImplementationPayload} payload
|
* @param {ProcessorImplementationPayload} payload
|
||||||
*/
|
*/
|
||||||
process_PAINTER_QUAD(payload) {
|
process_PAINTER_QUAD(payload) {
|
||||||
const shapeItem = /** @type {ShapeItem} */ (payload.items[0]);
|
const shapeItem = /** @type {ShapeItem} */ (payload.items.get(0));
|
||||||
assert(shapeItem instanceof ShapeItem, "Input for painter is not a shape");
|
assert(shapeItem instanceof ShapeItem, "Input for painter is not a shape");
|
||||||
|
|
||||||
/** @type {Array<enumColors>} */
|
/** @type {Array<enumColors>} */
|
||||||
const colors = [null, null, null, null];
|
const colors = [null, null, null, null];
|
||||||
for (let i = 0; i < 4; ++i) {
|
for (let i = 0; i < 4; ++i) {
|
||||||
if (payload.items[i + 1]) {
|
const colorItem = /** @type {ColorItem} */ (payload.items.get(i + 1));
|
||||||
colors[i] = /** @type {ColorItem} */ (payload.items[i + 1]).color;
|
if (colorItem) {
|
||||||
|
colors[i] = colorItem.color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,7 +536,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
*/
|
*/
|
||||||
process_READER(payload) {
|
process_READER(payload) {
|
||||||
// Pass through the item
|
// Pass through the item
|
||||||
const item = payload.items[0];
|
const item = payload.items.get(0);
|
||||||
payload.outItems.push({
|
payload.outItems.push({
|
||||||
item,
|
item,
|
||||||
doNotTrack: true,
|
doNotTrack: true,
|
||||||
@ -548,9 +555,12 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
const hubComponent = payload.entity.components.Hub;
|
const hubComponent = payload.entity.components.Hub;
|
||||||
assert(hubComponent, "Hub item processor has no hub component");
|
assert(hubComponent, "Hub item processor has no hub component");
|
||||||
|
|
||||||
for (let i = 0; i < payload.items.length; ++i) {
|
// Hardcoded
|
||||||
if (!payload.items[i]) continue;
|
for (let i = 0; i < payload.inputCount; ++i) {
|
||||||
const item = /** @type {ShapeItem} */ (payload.items[i]);
|
const item = /** @type {ShapeItem} */ (payload.items.get(i));
|
||||||
|
if (!item) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
this.root.hubGoals.handleDefinitionDelivered(item.definition);
|
this.root.hubGoals.handleDefinitionDelivered(item.definition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -560,7 +570,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
*/
|
*/
|
||||||
process_GOAL(payload) {
|
process_GOAL(payload) {
|
||||||
const goalComp = payload.entity.components.GoalAcceptor;
|
const goalComp = payload.entity.components.GoalAcceptor;
|
||||||
const item = payload.items[0];
|
const item = payload.items.get(0);
|
||||||
const now = this.root.time.now();
|
const now = this.root.time.now();
|
||||||
|
|
||||||
if (goalComp.item && !item.equals(goalComp.item)) {
|
if (goalComp.item && !item.equals(goalComp.item)) {
|
||||||
@ -574,7 +584,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
if (this.root.gameMode.getIsEditor()) {
|
if (this.root.gameMode.getIsEditor()) {
|
||||||
// while playing in editor, assign the item
|
// while playing in editor, assign the item
|
||||||
goalComp.item = payload.items[0];
|
goalComp.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
goalComp.lastDelivery = {
|
goalComp.lastDelivery = {
|
||||||
|
Loading…
Reference in New Issue
Block a user