mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-02-19 06:19:19 +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) {
|
if (newSearchTile) {
|
||||||
// Find new surrounding wire targets
|
// Find new surrounding wire targets
|
||||||
const newTargets = this.findSurroundingWireTargets(
|
const newTargets = this.findSurroundingWireTargets(
|
||||||
@ -369,7 +364,7 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
* @param {Vector} initialTile
|
* @param {Vector} initialTile
|
||||||
* @param {Array<enumDirection>} directions
|
* @param {Array<enumDirection>} directions
|
||||||
* @param {WireNetwork} network
|
* @param {WireNetwork} network
|
||||||
* @param {enumWireVariant} variantMask Only accept connections to this mask
|
* @param {enumWireVariant=} variantMask Only accept connections to this mask
|
||||||
* @returns {Array<any>}
|
* @returns {Array<any>}
|
||||||
*/
|
*/
|
||||||
findSurroundingWireTargets(initialTile, directions, network, variantMask = null) {
|
findSurroundingWireTargets(initialTile, directions, network, variantMask = null) {
|
||||||
@ -391,6 +386,9 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
const offset = enumDirectionToVector[direction];
|
const offset = enumDirectionToVector[direction];
|
||||||
const initialSearchTile = initialTile.add(offset);
|
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
|
// First, find the initial connected entities
|
||||||
const initialContents = this.root.map.getLayersContentsMultipleXY(
|
const initialContents = this.root.map.getLayersContentsMultipleXY(
|
||||||
initialSearchTile.x,
|
initialSearchTile.x,
|
||||||
@ -398,18 +396,17 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Link the initial tile to the initial entities, since it may change
|
// 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 = [];
|
const contents = [];
|
||||||
for (let j = 0; j < initialContents.length; ++j) {
|
for (let j = 0; j < initialContents.length; ++j) {
|
||||||
contents.push({
|
contents.push({
|
||||||
entity: initialContents[j],
|
entity: initialContents[j],
|
||||||
tile: initialSearchTile,
|
tile: initialSearchTile,
|
||||||
dir: offset,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let k = 0; k < contents.length; ++k) {
|
for (let k = 0; k < contents.length; ++k) {
|
||||||
const { entity, tile, dir } = contents[k];
|
const { entity, tile } = contents[k];
|
||||||
const wireComp = entity.components.Wire;
|
const wireComp = entity.components.Wire;
|
||||||
|
|
||||||
// Check for wire
|
// Check for wire
|
||||||
@ -441,17 +438,8 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the direction (inverted) matches
|
// Check if the direction (inverted) matches
|
||||||
// const pinDirection = staticComp.localDirectionToWorld(slot.direction);
|
const pinDirection = staticComp.localDirectionToWorld(slot.direction);
|
||||||
// if (pinDirection !== enumInvertedDirections[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)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,20 +458,14 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
// Check if it's a tunnel, if so, go to the forwarded item
|
// Check if it's a tunnel, if so, go to the forwarded item
|
||||||
const tunnelComp = entity.components.WireTunnel;
|
const tunnelComp = entity.components.WireTunnel;
|
||||||
if (tunnelComp) {
|
if (tunnelComp) {
|
||||||
|
if (visitedTunnels.has(entity.uid)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const staticComp = entity.components.StaticMapEntity;
|
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
|
// Compute where this tunnel connects to
|
||||||
//const forwardedTile = staticComp.origin.add(offset);
|
const forwardedTile = staticComp.origin.add(offset);
|
||||||
VERBOSE_WIRES &&
|
VERBOSE_WIRES &&
|
||||||
logger.log(
|
logger.log(
|
||||||
" Found tunnel",
|
" Found tunnel",
|
||||||
@ -505,7 +487,6 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
contents.push({
|
contents.push({
|
||||||
entity: connectedContents[h],
|
entity: connectedContents[h],
|
||||||
tile: forwardedTile,
|
tile: forwardedTile,
|
||||||
dir: outputDir,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,6 +497,9 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
if (network.tunnels.indexOf(entity) < 0) {
|
if (network.tunnels.indexOf(entity) < 0) {
|
||||||
network.tunnels.push(entity);
|
network.tunnels.push(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remember this tunnel
|
||||||
|
visitedTunnels.add(entity.uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user