mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Update systems/item_processor.js to use itemsBySlotMap (works)
This commit is contained in:
parent
bfbce653c6
commit
605dcd208c
@ -31,7 +31,6 @@ const MAX_QUEUED_CHARGES = 2;
|
|||||||
* Type of a processor implementation
|
* Type of a processor implementation
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* entity: Entity,
|
* entity: Entity,
|
||||||
* items: Array<{ item: BaseItem, sourceSlot: number }>,
|
|
||||||
* itemsBySlotMap: Map<number, BaseItem>,
|
* itemsBySlotMap: Map<number, BaseItem>,
|
||||||
* outItems: Array<ProducedItem>
|
* outItems: Array<ProducedItem>
|
||||||
* }} ProcessorImplementationPayload
|
* }} ProcessorImplementationPayload
|
||||||
@ -188,7 +187,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
// DEFAULT
|
// DEFAULT
|
||||||
// By default, we can start processing once all inputs are there
|
// By default, we can start processing once all inputs are there
|
||||||
case null: {
|
case null: {
|
||||||
return processorComp.inputSlots.length >= processorComp.inputsPerCharge;
|
return processorComp.inputSlotsMap.size >= processorComp.inputsPerCharge;
|
||||||
}
|
}
|
||||||
|
|
||||||
// QUAD PAINTER
|
// QUAD PAINTER
|
||||||
@ -254,15 +253,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
const processorComp = entity.components.ItemProcessor;
|
const processorComp = entity.components.ItemProcessor;
|
||||||
|
|
||||||
// First, take items
|
// First, take items
|
||||||
const items = processorComp.inputSlots;
|
|
||||||
processorComp.inputSlots = [];
|
processorComp.inputSlots = [];
|
||||||
|
|
||||||
/** @type {Object<string, BaseItem>} */
|
|
||||||
const itemsBySlot = {};
|
|
||||||
for (let i = 0; i < items.length; ++i) {
|
|
||||||
itemsBySlot[items[i].sourceSlot] = items[i].item;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @type {Map<number, BaseItem>} */
|
/** @type {Map<number, BaseItem>} */
|
||||||
const itemsBySlotMap = new Map();
|
const itemsBySlotMap = new Map();
|
||||||
for (let [key, value] of processorComp.inputSlotsMap.entries()) {
|
for (let [key, value] of processorComp.inputSlotsMap.entries()) {
|
||||||
@ -280,7 +272,6 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
// Call implementation
|
// Call implementation
|
||||||
handler({
|
handler({
|
||||||
entity,
|
entity,
|
||||||
items,
|
|
||||||
itemsBySlotMap,
|
itemsBySlotMap,
|
||||||
outItems,
|
outItems,
|
||||||
});
|
});
|
||||||
@ -319,13 +310,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) {
|
for (let [key, value] of payload.itemsBySlotMap.entries()) {
|
||||||
payload.outItems.push({
|
payload.outItems.push({
|
||||||
item: payload.items[i].item,
|
item: value,
|
||||||
preferredSlot: (nextSlot + i) % availableSlots,
|
preferredSlot: (nextSlot + key) % availableSlots,
|
||||||
doNotTrack: true,
|
doNotTrack: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +325,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].item);
|
const inputItem = /** @type {ShapeItem} */ (payload.itemsBySlotMap.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;
|
||||||
|
|
||||||
@ -354,7 +346,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].item);
|
const inputItem = /** @type {ShapeItem} */ (payload.itemsBySlotMap.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;
|
||||||
|
|
||||||
@ -375,7 +367,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].item);
|
const inputItem = /** @type {ShapeItem} */ (payload.itemsBySlotMap.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;
|
||||||
|
|
||||||
@ -389,7 +381,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].item);
|
const inputItem = /** @type {ShapeItem} */ (payload.itemsBySlotMap.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;
|
||||||
|
|
||||||
@ -403,7 +395,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].item);
|
const inputItem = /** @type {ShapeItem} */ (payload.itemsBySlotMap.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;
|
||||||
|
|
||||||
@ -444,8 +436,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].item);
|
const item1 = /** @type {ColorItem} */ (payload.itemsBySlotMap.get(0));
|
||||||
const item2 = /** @type {ColorItem} */ (payload.items[1].item);
|
const item2 = /** @type {ColorItem} */ (payload.itemsBySlotMap.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");
|
||||||
|
|
||||||
@ -559,8 +551,8 @@ 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) {
|
for (let value of payload.itemsBySlotMap.values()) {
|
||||||
const item = /** @type {ShapeItem} */ (payload.items[i].item);
|
const item = /** @type {ShapeItem} */ (value);
|
||||||
this.root.hubGoals.handleDefinitionDelivered(item.definition);
|
this.root.hubGoals.handleDefinitionDelivered(item.definition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -570,12 +562,12 @@ 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].item;
|
const item = payload.itemsBySlotMap.get(0);
|
||||||
const now = this.root.time.now();
|
const now = this.root.time.now();
|
||||||
|
|
||||||
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].item;
|
goalComp.item = payload.itemsBySlotMap.get(0);
|
||||||
goalComp.deliveryHistory.push({
|
goalComp.deliveryHistory.push({
|
||||||
item,
|
item,
|
||||||
time: now,
|
time: now,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user