1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Implement tryTakeItem in Belt

This commit is contained in:
isaisstillalive 2020-07-03 01:44:31 +09:00
parent 223e0e2615
commit 9ef0e77910
3 changed files with 17 additions and 11 deletions

View File

@ -60,6 +60,7 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
pos: new Vector(0, 0), pos: new Vector(0, 0),
directions: [enumDirection.bottom], directions: [enumDirection.bottom],
layer: this.getLayer(), layer: this.getLayer(),
processor: "Belt",
}, },
], ],
animated: false, animated: false,

View File

@ -4,6 +4,7 @@ import { BeltPath } from "../belt_path";
import { Component } from "../component"; import { Component } from "../component";
import { Entity } from "../entity"; import { Entity } from "../entity";
import { enumLayer } from "../root"; import { enumLayer } from "../root";
import { BaseItem } from "../base_item";
export const curvedBeltLength = /* Math.PI / 4 */ 0.78; export const curvedBeltLength = /* Math.PI / 4 */ 0.78;
@ -118,4 +119,19 @@ export class BeltComponent extends Component {
} }
} }
} }
/**
*
* @param {BaseItem} item
* @param {number} slot
*/
tryTakeItem(item, slot) {
const path = this.assignedPath;
assert(path, "belt has no path");
if (path.tryAcceptItem(item)) {
return true;
}
// Belt can have nothing else
return false;
}
} }

View File

@ -274,17 +274,6 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
const itemLayer = enumItemTypeToLayer[item.getItemType()]; const itemLayer = enumItemTypeToLayer[item.getItemType()];
const beltComp = receiver.components.Belt;
if (beltComp) {
const path = beltComp.assignedPath;
assert(path, "belt has no path");
if (path.tryAcceptItem(item)) {
return true;
}
// Belt can have nothing else
return false;
}
const energyConsumerComp = receiver.components.EnergyConsumer; const energyConsumerComp = receiver.components.EnergyConsumer;
if (energyConsumerComp) { if (energyConsumerComp) {
if (energyConsumerComp.tryAcceptItem(item, slotIndex)) { if (energyConsumerComp.tryAcceptItem(item, slotIndex)) {