Shared join module for transport pieces; belt drawing uses it (t67 phase 1)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+2
-2
@@ -116,8 +116,8 @@ function thinPipeColor(x, y, anim) {
|
||||
}
|
||||
PC[0] = r; PC[1] = g; PC[2] = bl;
|
||||
}
|
||||
// a block that is a belt or a filter: they join up into one belt
|
||||
function beltLike(b) { if (b < 0 || b >= NB) return false; const c = blockP[b]; return isBelt(c) || isFilter(c); }
|
||||
// A filter frame opens only where this end has a geometric partner.
|
||||
function beltLike(b, end) { return endJoin(b % BW, (b / BW) | 0, end) >= 0; }
|
||||
// standing trees: the trunk shows its dark bark, so it reads apart from the pale cut wood it drops
|
||||
const TREE_R = new Uint8Array(NMAT), TREE_G = new Uint8Array(NMAT), TREE_B = new Uint8Array(NMAT);
|
||||
for (let m = 0; m < NMAT; m++) { TREE_R[m] = COLR[m]; TREE_G[m] = COLG[m]; TREE_B[m] = COLB[m]; }
|
||||
|
||||
@@ -2,36 +2,17 @@
|
||||
let slopeBeltJoins = new Uint8Array(0), slopeBeltHalo = new Uint8Array(0), beltCaps = new Uint8Array(0);
|
||||
let slopeAcross = 0, slopeAlong = 0, slopeDistance = 0;
|
||||
function slopeBeltConnections(bx, by, code, planned = null) {
|
||||
const grade = beltGrade(code);
|
||||
let joins = 0;
|
||||
for (let end = 0; end < 2; end++) {
|
||||
const side = end ? 1 : -1, nx = bx + side, ny = by + side * grade;
|
||||
const nb = ny * BW + nx, next = planned && planned.get(nb);
|
||||
if (nx >= 0 && nx < BW && ny >= 0 && ny < BH && beltGrade(next ? next[0] : blockP[nb]) === grade) {
|
||||
joins |= 4 << end; continue;
|
||||
}
|
||||
const fy = by + (end ? grade > 0 : grade < 0), fb = fy * BW + nx;
|
||||
if (nx < 0 || nx >= BW || fy < 0 || fy >= BH) continue;
|
||||
const flat = planned && planned.get(fb), c = flat ? flat[0] : blockP[fb], v = flat ? flat[1] : blockV[fb];
|
||||
if (c === BP_BELT || c === BP_FILTER || (c === BP_SCREW && (v === 1 || v === 3))) joins |= 1 << end;
|
||||
const join = endJoin(bx, by, end, planned);
|
||||
if (join < 0) continue;
|
||||
const nb = join >> 1, next = planned && planned.get(nb);
|
||||
joins |= (isSlopeBelt(next ? next[0] : blockP[nb]) ? 4 : 1) << end;
|
||||
}
|
||||
return joins;
|
||||
}
|
||||
function flatBeltCaps(b) {
|
||||
const bx = b % BW, by = (b / BW) | 0;
|
||||
let caps = 0;
|
||||
for (let end = 0; end < 2; end++) {
|
||||
const x = bx + (end ? 1 : -1);
|
||||
let joined = false;
|
||||
if (x >= 0 && x < BW) for (let dy = -1; dy <= 0; dy++) {
|
||||
if (by + dy < 0) continue;
|
||||
const n = (by + dy) * BW + x, c = blockP[n], g = beltGrade(c);
|
||||
if ((!dy && (c === BP_BELT || c === BP_FILTER || (c === BP_SCREW && (blockV[n] === 1 || blockV[n] === 3 || blockV[n] >= 4)))) ||
|
||||
(g && dy === -(end ? g < 0 : g > 0))) joined = true;
|
||||
}
|
||||
if (!joined) caps |= 1 << end;
|
||||
}
|
||||
return caps;
|
||||
function flatBeltCaps(b, planned = null) {
|
||||
return 3 ^ pieceJoins(b % BW, (b / BW) | 0, planned);
|
||||
}
|
||||
function prepareSlopeBelts(x0, y0, x1, y1) {
|
||||
if (slopeBeltJoins.length !== NB) { slopeBeltJoins = new Uint8Array(NB); slopeBeltHalo = new Uint8Array(NB); beltCaps = new Uint8Array(NB); }
|
||||
|
||||
+3
-2
@@ -201,7 +201,7 @@ function drawWorld() {
|
||||
} else if (ly === 3) { // the belt's return run carries on under it, so belts and filters read as one belt
|
||||
const st = ((x - dir * (anim >> 1)) >> 1) & 1;
|
||||
if (m === EMPTY || st) { r = (st ? 92 : 56) * 0.72; g = (st ? 96 : 58) * 0.72; b = (st ? 104 : 66) * 0.72; }
|
||||
} else if ((lx === 0 && !beltLike(fb - 1)) || (lx === 3 && !beltLike(fb + 1))) { if (m === EMPTY || ((x + y) & 1)) { r = 64; g = 66; b = 74; } } // frame only where the line ends
|
||||
} else if ((lx === 0 && !beltLike(fb, 0)) || (lx === 3 && !beltLike(fb, 1))) { if (m === EMPTY || ((x + y) & 1)) { r = 64; g = 66; b = 74; } } // frame only where the line ends
|
||||
else if (m === EMPTY) { // mesh holes, tinted with what falls through them
|
||||
if ((x + y) & 1) { r = 40; g = 42; b = 48; }
|
||||
else if (inv) { r = 58; g = 74; b = 72; } // carry mode: everything else drops
|
||||
@@ -341,6 +341,7 @@ function drawWorld() {
|
||||
else if (isWall(code) && WALL_OF[v]) { const wm = WALL_OF[v]; tr = (COLR[wm] + 90) / 2; tg = (COLG[wm] + 190) / 2; tb = (COLB[wm] + 230) / 2; }
|
||||
const slope = isSlopeBelt(code), diagonal = code === BP_SCREW && v >= 4;
|
||||
const joins = slope ? slopeBeltConnections(gbx, gby, code, ghostBlocks) : diagonal ? diagonalScrewJoins(gbx, gby, v, ghostBlocks) : 0;
|
||||
const caps = code === BP_BELT || code === BP_FILTER ? flatBeltCaps(b, ghostBlocks) : 3;
|
||||
for (let dy = slope ? -9 : diagonal ? -4 : 0; dy < (slope || diagonal ? 8 : BS); dy++) for (let dx = slope ? -5 : diagonal ? -4 : 0; dx < (slope ? 9 : diagonal ? 8 : BS); dx++) {
|
||||
let sd = 0;
|
||||
if (diagonal) {
|
||||
@@ -365,7 +366,7 @@ function drawWorld() {
|
||||
const sx = gbx * BS + dx - vx0, sy = gby * BS + dy - vy0;
|
||||
if (sx < 0 || sy < 0 || sx >= bw || sy >= bh) continue;
|
||||
const k = sy * bw + sx, c = px[k];
|
||||
const edge = slope || diagonal ? sd > -0.8 : dx === 0 || dy === 0 || dx === BS - 1 || dy === BS - 1;
|
||||
const edge = slope || diagonal ? sd > -0.8 : (dx === 0 && (caps & 1)) || dy === 0 || (dx === BS - 1 && (caps & 2)) || dy === BS - 1;
|
||||
const a = edge ? (((dx + dy + pulse) & 3) === 0 ? 0.85 : 0.6) : 0.28;
|
||||
const pr = c & 255, pg = (c >> 8) & 255, pb = (c >> 16) & 255;
|
||||
px[k] = (sm ? 0x04000000 : 0xff000000) | ((pb + (tb - pb) * a) << 16) | ((pg + (tg - pg) * a) << 8) | (pr + (tr - pr) * a);
|
||||
|
||||
Reference in New Issue
Block a user