make wifi_draw.js draw connections correctly, and use tabs instead of spaces

This commit is contained in:
redbirdly 2025-02-22 17:52:47 +08:00 committed by GitHub
parent fe1e9a8963
commit ad14587fbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 66 additions and 66 deletions

View File

@ -7,80 +7,80 @@ let receivers = [];
let transmitters = []; let transmitters = [];
function updateLogicLists() { function updateLogicLists() {
receivers = []; receivers = [];
transmitters = []; transmitters = [];
logicReceivers = []; logicReceivers = [];
logicTransmitters = []; logicTransmitters = [];
for (let i = 0; i < currentPixels.length; i++) { for (let i = 0; i < currentPixels.length; i++) {
const pixel = currentPixels[i]; const pixel = currentPixels[i];
if (pixel.element === "logic_receiver") { if (pixel.element === "logic_receiver") {
logicReceivers.push(pixel); logicReceivers.push(pixel);
} else if (pixel.element === "logic_transmitter") { } else if (pixel.element === "logic_transmitter") {
logicTransmitters.push(pixel); logicTransmitters.push(pixel);
} else if (pixel.element === "receiver") { } else if (pixel.element === "receiver") {
receivers.push(pixel); receivers.push(pixel);
} else if (pixel.element === "transmitter") { } else if (pixel.element === "transmitter") {
transmitters.push(pixel); transmitters.push(pixel);
} }
} }
} }
// Function to draw lines between linked transmitters and receivers // Function to draw lines between linked transmitters and receivers
function drawLinks() { function drawLinks(ctx) {
// Iterate through transmitters and receivers to draw lines for linked channels // Iterate through transmitters and receivers to draw lines for linked channels
for (const transmitter of logicTransmitters) { for (const transmitter of logicTransmitters) {
for (const receiver of logicReceivers) { for (const receiver of logicReceivers) {
if (transmitter.channel === receiver.channel) { if (transmitter.channel === receiver.channel) {
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(transmitter.x * pixelSize + pixelSizeHalf, transmitter.y * pixelSize + pixelSizeHalf); ctx.moveTo(transmitter.x * pixelSize + pixelSizeHalf, transmitter.y * pixelSize + pixelSizeHalf);
ctx.lineTo(receiver.x * pixelSize + pixelSizeHalf, receiver.y * pixelSize + pixelSizeHalf); ctx.lineTo(receiver.x * pixelSize + pixelSizeHalf, receiver.y * pixelSize + pixelSizeHalf);
ctx.strokeStyle = "RGBA(255,255,255,0.2)"; ctx.strokeStyle = "RGBA(255,255,255,0.2)";
const neighbors = [ const neighbors = [
{ x: transmitter.x, y: transmitter.y - 1 }, // Top { x: transmitter.x, y: transmitter.y - 1 }, // Top
{ x: transmitter.x, y: transmitter.y + 1 }, // Bottom { x: transmitter.x, y: transmitter.y + 1 }, // Bottom
{ x: transmitter.x - 1, y: transmitter.y }, // Left { x: transmitter.x - 1, y: transmitter.y }, // Left
{ x: transmitter.x + 1, y: transmitter.y } // Right { x: transmitter.x + 1, y: transmitter.y } // Right
]; ];
let highlight = false; let highlight = false;
for (const neighbor of neighbors) { for (const neighbor of neighbors) {
if ( if (
neighbor.x >= 0 && neighbor.x < width && neighbor.x >= 0 && neighbor.x < width &&
neighbor.y >= 0 && neighbor.y < height neighbor.y >= 0 && neighbor.y < height
) { ) {
const neighborPixel = pixelMap[neighbor.x][neighbor.y]; const neighborPixel = pixelMap[neighbor.x][neighbor.y];
if (neighborPixel && neighborPixel.lstate > 0) { if (neighborPixel && neighborPixel.lstate > 0) {
highlight = true; highlight = true;
break; break;
} }
} }
} }
if (highlight) { if (highlight) {
ctx.strokeStyle = "RGBA(255,200,0,0.4)"; ctx.strokeStyle = "RGBA(255,200,0,0.4)";
} }
ctx.lineWidth = 2; ctx.lineWidth = 2;
ctx.stroke(); ctx.stroke();
} }
} }
} }
// Iterate through transmitters and receivers to draw lines for linked channels // Iterate through transmitters and receivers to draw lines for linked channels
for (const transmitter of transmitters) { for (const transmitter of transmitters) {
for (const receiver of receivers) { for (const receiver of receivers) {
if (transmitter._channel === receiver._channel) { if (transmitter._channel === receiver._channel) {
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(transmitter.x * pixelSize + pixelSizeHalf, transmitter.y * pixelSize + pixelSizeHalf); ctx.moveTo(transmitter.x * pixelSize + pixelSizeHalf, transmitter.y * pixelSize + pixelSizeHalf);
ctx.lineTo(receiver.x * pixelSize + pixelSizeHalf, receiver.y * pixelSize + pixelSizeHalf); ctx.lineTo(receiver.x * pixelSize + pixelSizeHalf, receiver.y * pixelSize + pixelSizeHalf);
ctx.strokeStyle = "RGBA(0,0,255,0.2)"; ctx.strokeStyle = "RGBA(0,0,255,0.2)";
ctx.lineWidth = 2; ctx.lineWidth = 2;
ctx.stroke(); ctx.stroke();
} }
} }
} }
} }
renderPostPixel(updateLogicLists); renderPostPixel(updateLogicLists);