mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Fix building placer not showing slots properly
This commit is contained in:
parent
93975df4d5
commit
d2077f5009
@ -93,7 +93,7 @@ export class BeltComponent extends Component {
|
||||
* Returns fake acceptor slot used for matching
|
||||
* @returns {import("./item_ejector").ItemEjectorSlot}
|
||||
*/
|
||||
getFakeEjectorSlots() {
|
||||
getFakeEjectorSlot() {
|
||||
assert(
|
||||
FAKE_BELT_EJECTOR_SLOT_BY_DIRECTION[this.direction],
|
||||
"Invalid belt direction: ",
|
||||
|
@ -90,11 +90,10 @@ export class ItemEjectorComponent extends Component {
|
||||
|
||||
/**
|
||||
* Returns where this slot ejects to
|
||||
* @param {number} index
|
||||
* @param {ItemEjectorSlot} slot
|
||||
* @returns {Vector}
|
||||
*/
|
||||
getSlotTargetLocalTile(index) {
|
||||
const slot = this.slots[index];
|
||||
getSlotTargetLocalTile(slot) {
|
||||
const directionVector = enumDirectionToVector[slot.direction];
|
||||
return slot.pos.add(directionVector);
|
||||
}
|
||||
@ -105,7 +104,7 @@ export class ItemEjectorComponent extends Component {
|
||||
*/
|
||||
anySlotEjectsToLocalTile(tile) {
|
||||
for (let i = 0; i < this.slots.length; ++i) {
|
||||
if (this.getSlotTargetLocalTile(i).equals(tile)) {
|
||||
if (this.getSlotTargetLocalTile(this.slots[i]).equals(tile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import {
|
||||
enumDirectionToVector,
|
||||
enumInvertedDirections,
|
||||
Vector,
|
||||
enumDirection,
|
||||
} from "../../../core/vector";
|
||||
import { T } from "../../../translations";
|
||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||
@ -427,6 +428,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
||||
const acceptorComp = this.fakeEntity.components.ItemAcceptor;
|
||||
const ejectorComp = this.fakeEntity.components.ItemEjector;
|
||||
const staticComp = this.fakeEntity.components.StaticMapEntity;
|
||||
const beltComp = this.fakeEntity.components.Belt;
|
||||
|
||||
const goodArrowSprite = Loader.getSprite("sprites/misc/slot_good_arrow.png");
|
||||
const badArrowSprite = Loader.getSprite("sprites/misc/slot_bad_arrow.png");
|
||||
@ -435,10 +437,26 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
||||
|
||||
const offsetShift = 10;
|
||||
|
||||
let acceptorSlots = [];
|
||||
let ejectorSlots = [];
|
||||
|
||||
if (ejectorComp) {
|
||||
ejectorSlots = ejectorComp.slots.slice();
|
||||
}
|
||||
|
||||
if (acceptorComp) {
|
||||
const slots = acceptorComp.slots;
|
||||
for (let acceptorSlotIndex = 0; acceptorSlotIndex < slots.length; ++acceptorSlotIndex) {
|
||||
const slot = slots[acceptorSlotIndex];
|
||||
acceptorSlots = acceptorComp.slots.slice();
|
||||
}
|
||||
|
||||
if (beltComp) {
|
||||
const fakeEjectorSlot = beltComp.getFakeEjectorSlot();
|
||||
const fakeAcceptorSlot = beltComp.getFakeAcceptorSlot();
|
||||
ejectorSlots.push(fakeEjectorSlot);
|
||||
acceptorSlots.push(fakeAcceptorSlot);
|
||||
}
|
||||
|
||||
for (let acceptorSlotIndex = 0; acceptorSlotIndex < acceptorSlots.length; ++acceptorSlotIndex) {
|
||||
const slot = acceptorSlots[acceptorSlotIndex];
|
||||
|
||||
const acceptorSlotWsTile = staticComp.localTileToWorld(slot.pos);
|
||||
const acceptorSlotWsPos = acceptorSlotWsTile.toWorldSpaceCenterOfTile();
|
||||
@ -459,15 +477,13 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
||||
let isConnected = false;
|
||||
|
||||
// Find all entities which are on that tile
|
||||
const sourceEntities = this.root.map.getLayersContentsMultipleXY(
|
||||
sourceTile.x,
|
||||
sourceTile.y
|
||||
);
|
||||
const sourceEntities = this.root.map.getLayersContentsMultipleXY(sourceTile.x, sourceTile.y);
|
||||
|
||||
// Check for every entity:
|
||||
for (let i = 0; i < sourceEntities.length; ++i) {
|
||||
const sourceEntity = sourceEntities[i];
|
||||
const sourceEjector = sourceEntity.components.ItemEjector;
|
||||
const sourceBeltComp = sourceEntity.components.Belt;
|
||||
const sourceStaticComp = sourceEntity.components.StaticMapEntity;
|
||||
const ejectorAcceptLocalTile = sourceStaticComp.worldToLocalTile(acceptorSlotWsTile);
|
||||
|
||||
@ -476,6 +492,13 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
||||
if (sourceEjector && sourceEjector.anySlotEjectsToLocalTile(ejectorAcceptLocalTile)) {
|
||||
// This one is connected, all good
|
||||
isConnected = true;
|
||||
} else if (
|
||||
sourceBeltComp &&
|
||||
sourceStaticComp.localDirectionToWorld(sourceBeltComp.direction) ===
|
||||
enumInvertedDirections[worldDirection]
|
||||
) {
|
||||
// Belt connected
|
||||
isConnected = true;
|
||||
} else {
|
||||
// This one is blocked
|
||||
isBlocked = true;
|
||||
@ -498,18 +521,14 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
||||
parameters.context.globalAlpha = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ejectorComp) {
|
||||
const slots = ejectorComp.slots;
|
||||
|
||||
// Go over all slots
|
||||
for (let ejectorSlotIndex = 0; ejectorSlotIndex < slots.length; ++ejectorSlotIndex) {
|
||||
const slot = slots[ejectorSlotIndex];
|
||||
for (let ejectorSlotIndex = 0; ejectorSlotIndex < ejectorSlots.length; ++ejectorSlotIndex) {
|
||||
const slot = ejectorSlots[ejectorSlotIndex];
|
||||
|
||||
const ejectorSlotLocalTile = slot.pos.add(enumDirectionToVector[slot.direction]);
|
||||
const ejectorSlotWsTile = staticComp.localTileToWorld(ejectorSlotLocalTile);
|
||||
|
||||
const ejectorSlotWsTile = staticComp.localTileToWorld(
|
||||
ejectorComp.getSlotTargetLocalTile(ejectorSlotIndex)
|
||||
);
|
||||
const ejectorSLotWsPos = ejectorSlotWsTile.toWorldSpaceCenterOfTile();
|
||||
const ejectorSlotWsDirection = staticComp.localDirectionToWorld(slot.direction);
|
||||
|
||||
@ -533,6 +552,9 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
||||
if (destAcceptor && destAcceptor.findMatchingSlot(destLocalTile, destLocalDir)) {
|
||||
// This one is connected, all good
|
||||
isConnected = true;
|
||||
} else if (destEntity.components.Belt && destLocalDir === enumDirection.top) {
|
||||
// Connected to a belt
|
||||
isConnected = true;
|
||||
} else {
|
||||
// This one is blocked
|
||||
isBlocked = true;
|
||||
@ -556,4 +578,3 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ export class GameLogic {
|
||||
}
|
||||
|
||||
if (beltComp) {
|
||||
const fakeEjectorSlot = beltComp.getFakeEjectorSlots();
|
||||
const fakeEjectorSlot = beltComp.getFakeEjectorSlot();
|
||||
const fakeAcceptorSlot = beltComp.getFakeAcceptorSlot();
|
||||
ejectorSlots.push(fakeEjectorSlot);
|
||||
acceptorSlots.push(fakeAcceptorSlot);
|
||||
|
Loading…
Reference in New Issue
Block a user