mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Define the Component that passes the process in ItemAcceptor
Require migrate
This commit is contained in:
parent
d75fb184a4
commit
e1a47905e8
@ -8,7 +8,8 @@ import { enumLayer } from "../root";
|
|||||||
* pos: Vector,
|
* pos: Vector,
|
||||||
* directions: enumDirection[],
|
* directions: enumDirection[],
|
||||||
* layer: enumLayer,
|
* layer: enumLayer,
|
||||||
* filter?: enumItemType
|
* filter?: enumItemType,
|
||||||
|
* processor?: string
|
||||||
* }} ItemAcceptorSlot */
|
* }} ItemAcceptorSlot */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +24,8 @@ import { enumLayer } from "../root";
|
|||||||
* pos: Vector,
|
* pos: Vector,
|
||||||
* directions: enumDirection[],
|
* directions: enumDirection[],
|
||||||
* layer?: enumLayer,
|
* layer?: enumLayer,
|
||||||
* filter?: enumItemType
|
* filter?: enumItemType,
|
||||||
|
* processor?: string
|
||||||
* }} ItemAcceptorSlotConfig */
|
* }} ItemAcceptorSlotConfig */
|
||||||
|
|
||||||
export class ItemAcceptorComponent extends Component {
|
export class ItemAcceptorComponent extends Component {
|
||||||
@ -41,6 +43,8 @@ export class ItemAcceptorComponent extends Component {
|
|||||||
|
|
||||||
// TODO: MIGRATE
|
// TODO: MIGRATE
|
||||||
layer: types.enum(enumLayer),
|
layer: types.enum(enumLayer),
|
||||||
|
|
||||||
|
processor: types.nullable(types.string),
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
animated: types.bool,
|
animated: types.bool,
|
||||||
@ -125,6 +129,7 @@ export class ItemAcceptorComponent extends Component {
|
|||||||
|
|
||||||
// Which type of item to accept (shape | color | all) @see enumItemType
|
// Which type of item to accept (shape | color | all) @see enumItemType
|
||||||
filter: slot.filter,
|
filter: slot.filter,
|
||||||
|
processor: slot.processor,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -236,7 +236,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to hand over the item
|
// Try to hand over the item
|
||||||
if (this.tryPassOverItem(item, targetEntity, destSlot.index)) {
|
if (this.tryPassOverItem(item, targetEntity, destSlot)) {
|
||||||
// Handover successful, clear slot
|
// Handover successful, clear slot
|
||||||
targetAcceptorComp.onItemAccepted(destSlot.index, destSlot.acceptedDirection, item);
|
targetAcceptorComp.onItemAccepted(destSlot.index, destSlot.acceptedDirection, item);
|
||||||
sourceSlot.item = null;
|
sourceSlot.item = null;
|
||||||
@ -250,12 +250,27 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
*
|
*
|
||||||
* @param {BaseItem} item
|
* @param {BaseItem} item
|
||||||
* @param {Entity} receiver
|
* @param {Entity} receiver
|
||||||
* @param {number} slotIndex
|
* @param {import("../components/item_acceptor").ItemAcceptorLocatedSlot} slot
|
||||||
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
tryPassOverItem(item, receiver, slotIndex) {
|
tryPassOverItem(item, receiver, slot) {
|
||||||
|
const processor = slot.slot.processor;
|
||||||
|
if (processor) {
|
||||||
|
const itemProcessorComp = receiver.components[processor];
|
||||||
|
if (itemProcessorComp) {
|
||||||
|
// Its an item processor ..
|
||||||
|
if (itemProcessorComp.tryTakeItem(item, slot.index)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Item processor can have nothing else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Try figuring out how what to do with the item
|
// Try figuring out how what to do with the item
|
||||||
// TODO: Kinda hacky. How to solve this properly? Don't want to go through inheritance hell.
|
// TODO: Kinda hacky. How to solve this properly? Don't want to go through inheritance hell.
|
||||||
// Also its just a few cases (hope it stays like this .. :x).
|
// Also its just a few cases (hope it stays like this .. :x).
|
||||||
|
const slotIndex = slot.index;
|
||||||
|
|
||||||
const itemLayer = enumItemTypeToLayer[item.getItemType()];
|
const itemLayer = enumItemTypeToLayer[item.getItemType()];
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user