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