SOURCE / PINNED RELEASE
Made of little things.
Faultline
- Release
- da1ffaa5624c…
- Author-recorded commit
- 60f5f03189db…
- License
- LICENSE
- Author’s source reference
- nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-6932b12c78c
Archive hash verified: 5a2e0492417ec4e7…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
import type { Arena, Box, Vec } from './maps';
const tinted = new Map<string, string>();
function tint(color: string, shade: number) {
const key = color + shade;
let value = tinted.get(key);
if (!value) {
const n = parseInt(color.slice(1), 16);
value =
'rgb(' + [n >> 16, (n >> 8) & 255, n & 255].map((v) => Math.round(v * shade)).join(',') + ')';
tinted.set(key, value);
}
return value;
}
// Orthographic map plate generated from gameplay geometry; no preview asset can go stale.
export function mapPlate(canvas: HTMLCanvasElement, map: Arena) {
const ctx = canvas.getContext('2d');
if (!ctx) return;
const w = canvas.clientWidth,
h = canvas.clientHeight;
if (!w || !h) return;
const dpr = Math.min(2, devicePixelRatio);
canvas.width = w * dpr;
canvas.height = h * dpr;
ctx.scale(dpr, dpr);
const scale = (Math.min(w / 75, h / 43) * 24) / map.size,
cx = w * 0.51,
cy = h * 0.53;
const project = (x: number, y: number, z: number) => [
cx + (x * 0.83 - z * 0.55) * scale,
cy + (x * 0.28 + z * 0.42 - y * 0.86) * scale,
];
function polygon(p: number[][], fill: string, edge?: string) {
ctx!.beginPath();
for (let i = 0; i < p.length; i++) i ? ctx!.lineTo(p[i][0], p[i][1]) : ctx!.moveTo(p[i][0], p[i][1]);
ctx!.closePath();
ctx!.fillStyle = fill;
ctx!.fill();
if (edge) {
ctx!.strokeStyle = edge;
ctx!.lineWidth = 0.45;
ctx!.stroke();
}
}
function drawBox(b: Box) {
if (b.boundary || Math.max(Math.abs(b.x), Math.abs(b.z)) > map.size + 1) return;
if (b.shape === 'pine') {
polygon(
[
[b.x - b.w / 2, b.y, b.z],
[b.x, b.y + b.h, b.z],
[b.x + b.w / 2, b.y, b.z],
].map((v) => project(...(v as Vec))),
b.color,
);
return;
}
const x = b.x - b.w / 2,
X = x + b.w,
z = b.z - b.d / 2,
Z = z + b.d,
y = b.y,
Y = y + b.h;
polygon(
[
[x, y, Z],
[X, y, Z],
[X, Y, Z],
[x, Y, Z],
].map((v) => project(...(v as Vec))),
tint(b.color, 0.7),
);
polygon(
[
[X, y, z],
[X, y, Z],
[X, Y, Z],
[X, Y, z],
].map((v) => project(...(v as Vec))),
tint(b.color, 0.53),
);
polygon(
[
[x, Y, z],
[X, Y, z],
[X, Y, Z],
[x, Y, Z],
].map((v) => project(...(v as Vec))),
tint(b.color, 1.08),
b.h > 0.2 ? '#c5ba9960' : undefined,
);
}
const base = map.boxes[0];
drawBox({ ...base, y: -1.2, h: 1.17, color: '#666e62' });
drawBox(base);
const t = map.terrain;
if (t) {
const node = (x: number, z: number) =>
project(x * t.spacing - t.extent, t.heights[z * t.side + x], z * t.spacing - t.extent);
for (let z = 0; z < t.side - 1; z++)
for (let x = 0; x < t.side - 1; x++) {
const i = z * t.side + x,
h = t.heights[i],
shade = 0.87 + 0.025 * h + 0.06 * (t.heights[i + 1] - h);
polygon([node(x, z), node(x, z + 1), node(x + 1, z)], tint('#84916e', shade));
polygon([node(x + 1, z), node(x, z + 1), node(x + 1, z + 1)], tint('#84916e', shade + 0.015));
}
}
for (let v = -map.size + 4; !t && v < map.size; v += 4) {
for (const line of [
[
[-map.size, v],
[map.size, v],
],
[
[v, -map.size],
[v, map.size],
],
]) {
const [a, b] = line.map(([x, z]) => project(x, 0.001, z));
ctx.beginPath();
ctx.moveTo(a[0], a[1]);
ctx.lineTo(b[0], b[1]);
ctx.lineWidth = 0.5;
ctx.strokeStyle = '#686d5b66';
ctx.stroke();
}
}
for (const b of map.boxes
.slice(1)
.filter((b) => b.solid && !b.roof && b.h > 0.9 && b.w < 30 && b.d < 30)) {
const x = b.x - b.w / 2,
z = b.z - b.d / 2;
polygon(
[
[x, z],
[x + b.w, z],
[x + b.w + b.h * 0.58, z + b.d + b.h * 0.39],
[x + b.h * 0.58, z + b.d + b.h * 0.39],
].map(([x, z]) => project(x, 0, z)),
'#48483d44',
);
}
// Draw top surfaces as a group with their building, after lower trim.
const sorted = map.boxes
.slice(1)
.sort((a, b) => a.x * 0.55 + a.z * 0.83 + a.y * 0.65 - (b.x * 0.55 + b.z * 0.83 + b.y * 0.65));
for (const b of sorted) {
if ((b.w > 40 || b.d > 40) && b.y >= 0 && b.x + b.z >= 20) continue;
if (map.sector === 'NA–03' && b.roof) continue;
drawBox(b);
}
return project;
}
export function gunArt(canvas: HTMLCanvasElement, index: number) {
const ctx = canvas.getContext('2d');
if (!ctx) return;
canvas.width = 660;
canvas.height = 196;
ctx.scale(2, 2);
ctx.strokeStyle = '#bdc3ae';
ctx.lineWidth = 1.05;
ctx.lineJoin = 'round';
function shape(points: number[][], fill = '#55605b') {
ctx!.beginPath();
points.forEach(([x, y], i) => (i ? ctx!.lineTo(x, y) : ctx!.moveTo(x, y)));
ctx!.closePath();
ctx!.fillStyle = fill;
ctx!.fill();
ctx!.stroke();
}
function rect(x: number, y: number, w: number, h: number, fill: string) {
shape(
[
[x, y],
[x + w, y],
[x + w, y + h],
[x, y + h],
],
fill,
);
}
if (index >= 5) {
if (index === 7) {
rect(35, 36, 233, 17, '#646e55');
rect(254, 32, 18, 25, '#414b40');
rect(74, 52, 12, 17, '#53604e');
rect(130, 27, 22, 8, '#6a715a');
} else {
const long = index === 6 ? 25 : 0;
rect(102, 31, 91 + long, 15, '#7a8074');
rect(108, 46, 69, 6, '#4b564d');
shape(
[
[111, 49],
[129, 49],
[122, 73],
[101, 73],
],
'#49534b',
);
rect(179 + long, 28, 4, 3, '#333e35');
}
return;
}
const short = index === 1,
pump = index === 2,
long = index === 3;
const end = short ? 235 : long ? 299 : 276;
const xoff = short ? 23 : long ? -4 : 8;
ctx.translate(xoff, 0);
shape(
[
[24, 40],
[64, 40],
[77, 36],
[86, 39],
[86, 53],
[69, 54],
[49, 64],
[29, 73],
[22, 72],
],
'#61665a',
);
shape(
[
[30, 46],
[61, 45],
[65, 48],
[34, 62],
],
'#303a36',
);
rect(19, 40, 5, 33, '#343f39');
rect(74, 41, 22, 9, '#47514a');
shape(
[
[98, 48],
[116, 50],
[112, 60],
[105, 77],
[96, 75],
[101, 57],
],
'#414b43',
);
if (!pump)
shape(
[
[132, 49],
[149, 51],
[147, 66],
[153, 76],
[141, 80],
[133, 69],
[132, 61],
],
'#606759',
);
shape(
[
[110, 50],
[134, 50],
[130, 62],
[113, 63],
[108, 59],
[111, 57],
[115, 60],
[127, 59],
[129, 54],
[111, 54],
],
'#363e39',
);
rect(86, 35, 72, 16, '#626b5e');
rect(91, 49, 59, 5, '#475047');
rect(97, 39, 23, 4, '#353f39');
rect(155, 35, short ? 40 : 62, 14, '#5b6458');
for (let i = 158; i < (short ? 192 : 212); i += 6) rect(i, 38, 2.2, 6, '#313d36');
rect(short ? 195 : 217, 38, end - (short ? 195 : 217), 5, '#555f54');
rect(end, 36, 15, 9, '#3d4840');
for (let i = 0; i < 3; i++) rect(end + 3 + i * 3, 37, 1, 5, '#72786b');
if (pump) rect(163, 49, 45, 7, '#826f55');
if (long) {
rect(104, 23, 51, 7, '#4d5950');
rect(99, 21, 10, 11, '#60695e');
rect(149, 20, 13, 12, '#566258');
rect(116, 30, 4, 5, '#4c564b');
rect(140, 30, 4, 5, '#4c564b');
} else {
shape(
[
[105, 35],
[108, 25],
[118, 25],
[122, 35],
],
'#414d44',
);
rect(110, 27, 6, 5, '#a1ad8a');
}
rect(88, 32, short ? 103 : 123, 3, '#424b43');
for (let i = 91; i < (short ? 188 : 208); i += 5) rect(i, 31, 2, 2, '#7d8474');
for (const [x, y] of [
[92, 46],
[125, 39],
[150, 46],
]) {
ctx.fillStyle = '#c0bca2';
ctx.fillRect(x, y, 2, 2);
}
}
