mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-02-18 22:09:20 +00:00
Update wire.js
This commit is contained in:
parent
047e99a673
commit
f69687a647
@ -316,11 +316,6 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
}
|
||||
}
|
||||
|
||||
const tunnelComp = nextEntity.components.WireTunnel;
|
||||
if (tunnelComp) {
|
||||
//const outputDir = tunnelComp.GetOutputDirection(staticComp, offset);
|
||||
}
|
||||
|
||||
if (newSearchTile) {
|
||||
// Find new surrounding wire targets
|
||||
const newTargets = this.findSurroundingWireTargets(
|
||||
@ -369,7 +364,7 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
* @param {Vector} initialTile
|
||||
* @param {Array<enumDirection>} directions
|
||||
* @param {WireNetwork} network
|
||||
* @param {enumWireVariant} variantMask Only accept connections to this mask
|
||||
* @param {enumWireVariant=} variantMask Only accept connections to this mask
|
||||
* @returns {Array<any>}
|
||||
*/
|
||||
findSurroundingWireTargets(initialTile, directions, network, variantMask = null) {
|
||||
@ -391,6 +386,9 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
const offset = enumDirectionToVector[direction];
|
||||
const initialSearchTile = initialTile.add(offset);
|
||||
|
||||
// Store which tunnels we already visited to avoid infinite loops
|
||||
const visitedTunnels = new Set();
|
||||
|
||||
// First, find the initial connected entities
|
||||
const initialContents = this.root.map.getLayersContentsMultipleXY(
|
||||
initialSearchTile.x,
|
||||
@ -398,18 +396,17 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
);
|
||||
|
||||
// Link the initial tile to the initial entities, since it may change
|
||||
/** @type {Array<{entity: Entity, tile: Vector, dir: Vector}>} */
|
||||
/** @type {Array<{entity: Entity, tile: Vector}>} */
|
||||
const contents = [];
|
||||
for (let j = 0; j < initialContents.length; ++j) {
|
||||
contents.push({
|
||||
entity: initialContents[j],
|
||||
tile: initialSearchTile,
|
||||
dir: offset,
|
||||
});
|
||||
}
|
||||
|
||||
for (let k = 0; k < contents.length; ++k) {
|
||||
const { entity, tile, dir } = contents[k];
|
||||
const { entity, tile } = contents[k];
|
||||
const wireComp = entity.components.Wire;
|
||||
|
||||
// Check for wire
|
||||
@ -441,17 +438,8 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
// Check if the direction (inverted) matches
|
||||
// const pinDirection = staticComp.localDirectionToWorld(slot.direction);
|
||||
// if (pinDirection !== enumInvertedDirections[direction]) {
|
||||
// continue;
|
||||
// }
|
||||
// /**
|
||||
// * @type {Vector}
|
||||
// */
|
||||
const worldDir = staticComp.localDirectionToWorld(slot.direction);
|
||||
const invDir = enumInvertedDirections[worldDir];
|
||||
const pinDirection = enumDirectionToVector[invDir];
|
||||
if (!pinDirection.equals(dir)) {
|
||||
const pinDirection = staticComp.localDirectionToWorld(slot.direction);
|
||||
if (pinDirection !== enumInvertedDirections[direction]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -470,20 +458,14 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
// Check if it's a tunnel, if so, go to the forwarded item
|
||||
const tunnelComp = entity.components.WireTunnel;
|
||||
if (tunnelComp) {
|
||||
if (visitedTunnels.has(entity.uid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
|
||||
//const localDir = staticComp.worldToLocalTile(tile.sub(offset));
|
||||
//staticComp.localDirectionToWorld();
|
||||
const outputDir = tunnelComp.GetOutputDirection(staticComp, dir);
|
||||
if (!outputDir) {
|
||||
continue;
|
||||
}
|
||||
const forwardedTile = staticComp.origin.add(outputDir);
|
||||
|
||||
//TODO: Alter to Allow for different tunnel Types
|
||||
// Compute where this tunnel connects to
|
||||
//const forwardedTile = staticComp.origin.add(offset);
|
||||
const forwardedTile = staticComp.origin.add(offset);
|
||||
VERBOSE_WIRES &&
|
||||
logger.log(
|
||||
" Found tunnel",
|
||||
@ -505,7 +487,6 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
contents.push({
|
||||
entity: connectedContents[h],
|
||||
tile: forwardedTile,
|
||||
dir: outputDir,
|
||||
});
|
||||
}
|
||||
|
||||
@ -516,6 +497,9 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
if (network.tunnels.indexOf(entity) < 0) {
|
||||
network.tunnels.push(entity);
|
||||
}
|
||||
|
||||
// Remember this tunnel
|
||||
visitedTunnels.add(entity.uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user