Fix item animations not working for belts

This commit is contained in:
tobspr 2020-08-10 20:17:18 +02:00
parent 08a5b9070d
commit f91e677f2e
1 changed files with 16 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import { gItemRegistry } from "../core/global_registries";
import { createLogger } from "../core/logging"; import { createLogger } from "../core/logging";
import { Rectangle } from "../core/rectangle"; import { Rectangle } from "../core/rectangle";
import { epsilonCompare, round4Digits } from "../core/utils"; import { epsilonCompare, round4Digits } from "../core/utils";
import { enumDirection, enumDirectionToVector, Vector } from "../core/vector"; import { enumDirection, enumDirectionToVector, Vector, enumInvertedDirections } from "../core/vector";
import { BasicSerializableObject, types } from "../savegame/serialization"; import { BasicSerializableObject, types } from "../savegame/serialization";
import { BaseItem } from "./base_item"; import { BaseItem } from "./base_item";
import { Entity } from "./entity"; import { Entity } from "./entity";
@ -194,7 +194,7 @@ export class BeltPath extends BasicSerializableObject {
/** /**
* Finds the entity which accepts our items * Finds the entity which accepts our items
* @return {{ entity: Entity, slot: number }} * @return {{ entity: Entity, slot: number, direction?: enumDirection }}
*/ */
computeAcceptingEntityAndSlot() { computeAcceptingEntityAndSlot() {
const lastEntity = this.entityPath[this.entityPath.length - 1]; const lastEntity = this.entityPath[this.entityPath.length - 1];
@ -226,6 +226,7 @@ export class BeltPath extends BasicSerializableObject {
if (ejectSlotWsDirection === beltAcceptingDirection) { if (ejectSlotWsDirection === beltAcceptingDirection) {
return { return {
entity: targetEntity, entity: targetEntity,
direction: null,
slot: 0, slot: 0,
}; };
} }
@ -238,9 +239,10 @@ export class BeltPath extends BasicSerializableObject {
continue; continue;
} }
const ejectingDirection = targetStaticComp.worldDirectionToLocal(ejectSlotWsDirection);
const matchingSlot = targetAcceptorComp.findMatchingSlot( const matchingSlot = targetAcceptorComp.findMatchingSlot(
targetStaticComp.worldToLocalTile(ejectSlotTargetWsTile), targetStaticComp.worldToLocalTile(ejectSlotTargetWsTile),
targetStaticComp.worldDirectionToLocal(ejectSlotWsDirection), ejectingDirection,
lastEntity.layer lastEntity.layer
); );
@ -252,6 +254,7 @@ export class BeltPath extends BasicSerializableObject {
return { return {
entity: targetEntity, entity: targetEntity,
slot: matchingSlot.index, slot: matchingSlot.index,
direction: enumInvertedDirections[ejectingDirection],
}; };
} }
} }
@ -1026,6 +1029,16 @@ export class BeltPath extends BasicSerializableObject {
) )
) { ) {
this.items.pop(); this.items.pop();
// Also trigger animation
const targetAcceptorComp = this.acceptorTarget.entity.components.ItemAcceptor;
if (targetAcceptorComp) {
targetAcceptorComp.onItemAccepted(
this.acceptorTarget.slot,
this.acceptorTarget.direction,
lastItem[_item]
);
}
} }
} }