mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Make "get adjacent entry" a common method
This commit is contained in:
parent
eaa46ec914
commit
bfa9e98050
@ -8,6 +8,8 @@ import { GameSystem } from "./game_system";
|
|||||||
import { arrayDelete, arrayDeleteValue } from "../core/utils";
|
import { arrayDelete, arrayDeleteValue } from "../core/utils";
|
||||||
import { DrawParameters } from "../core/draw_parameters";
|
import { DrawParameters } from "../core/draw_parameters";
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
|
import { enumDirection, enumDirectionToVector } from "../core/vector";
|
||||||
|
|
||||||
export class GameSystemWithFilter extends GameSystem {
|
export class GameSystemWithFilter extends GameSystem {
|
||||||
/**
|
/**
|
||||||
* Constructs a new game system with the given component filter. It will process
|
* Constructs a new game system with the given component filter. It will process
|
||||||
@ -211,4 +213,21 @@ export class GameSystemWithFilter extends GameSystem {
|
|||||||
arrayDelete(this.allEntities, index);
|
arrayDelete(this.allEntities, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Entity} entity
|
||||||
|
* @param {enumDirection=} direction
|
||||||
|
* @returns {Entity|null}
|
||||||
|
*/
|
||||||
|
getAdjacentEntity(entity, direction = null) {
|
||||||
|
const ejectComp = entity.components.ItemEjector;
|
||||||
|
const staticComp = entity.components.StaticMapEntity;
|
||||||
|
|
||||||
|
const ejectingSlot = ejectComp.slots[0];
|
||||||
|
const ejectingPos = staticComp.localTileToWorld(ejectingSlot.pos);
|
||||||
|
const ejectingDirection = staticComp.localDirectionToWorld(direction || ejectingSlot.direction);
|
||||||
|
const targetTile = ejectingPos.add(enumDirectionToVector[ejectingDirection]);
|
||||||
|
return this.root.map.getTileContent(targetTile, enumLayer.regular);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,16 +66,10 @@ export class MinerSystem extends GameSystemWithFilter {
|
|||||||
tryPerformMinerEject(entity, item) {
|
tryPerformMinerEject(entity, item) {
|
||||||
const minerComp = entity.components.Miner;
|
const minerComp = entity.components.Miner;
|
||||||
const ejectComp = entity.components.ItemEjector;
|
const ejectComp = entity.components.ItemEjector;
|
||||||
const staticComp = entity.components.StaticMapEntity;
|
|
||||||
|
|
||||||
// Check if we are a chained miner
|
// Check if we are a chained miner
|
||||||
if (minerComp.chainable) {
|
if (minerComp.chainable) {
|
||||||
const ejectingSlot = ejectComp.slots[0];
|
const targetContents = this.getAdjacentEntity(entity);
|
||||||
const ejectingPos = staticComp.localTileToWorld(ejectingSlot.pos);
|
|
||||||
const ejectingDirection = staticComp.localDirectionToWorld(ejectingSlot.direction);
|
|
||||||
|
|
||||||
const targetTile = ejectingPos.add(enumDirectionToVector[ejectingDirection]);
|
|
||||||
const targetContents = this.root.map.getTileContent(targetTile, enumLayer.regular);
|
|
||||||
|
|
||||||
// Check if we are connected to another miner and thus do not eject directly
|
// Check if we are connected to another miner and thus do not eject directly
|
||||||
if (targetContents) {
|
if (targetContents) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user