Verdigris wire and lever

This commit is contained in:
2026-10-22 13:43:57 -03:00
parent 0d80e85dec
commit 6af6c52673
24 changed files with 3191 additions and 733 deletions
+40 -32
View File
@@ -1,9 +1,11 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// writes the verdigris wire's look: its pieces as models, and the block's parts, which put each piece on every side a
// wire can lie on, pointing each way that side's directions go (DIRECTIONS in sides.ts). that's a part per side,
// direction and kind of join, too many to keep right by hand. run it after changing anything here or the directions:
// writes the verdigris wire's look: its pieces as models, and the block's parts, which put each piece on every face of
// its cell it can cover, pointing each way that face's directions go (DIRECTIONS in sides.ts). a way out of the cell
// is an arm_ state whose meaning depends on which faces the cell covers (ways_out in joins.ts), so there's a part for
// each of those for every set of faces a cell can cover, too many to keep right by hand. run it after changing
// anything here, the directions or the ways out:
//
// deno run -A tools/verdigris_wire_model.ts
//
@@ -12,6 +14,7 @@
import { model_shape } from "$/common/block_shapes.ts";
import type { ModelElementJson, ModelFace } from "$/common/block_models.ts";
import type { Face } from "$/common/mod_api/shared.ts";
import { can_cover, ways_out } from "$/mods/bworld/scripts/verdigris/joins.ts";
import { DIRECTIONS, FACE_OFFSETS, FACES } from "$/mods/bworld/scripts/verdigris/sides.ts";
const MODELS = "mods/bworld/models";
@@ -23,22 +26,18 @@ const [A, B] = [8 - WIDTH / 2, 8 + WIDTH / 2];
// what's outlined when the wire is pointed at: a plate around its middle, since the pieces are too thin to aim at
const CENTER_SHAPE = [[3, 0, 3, 13, 1, 13]];
const face = { texture: "#wire" };
const wire_face = { texture: "#wire" };
// a floor wire's pieces. the ones that point a way point north. their faces take their texture from where they are,
// so they have no uv
// the pieces of the wire on a cell's floor. the ones that point a way point north. their faces take their texture from
// where they are, so they have no uv
const PIECES: Record<string, ModelElementJson[]> = {
// always there, so the arms meet
center: [{ from: [A, 0, A], to: [B, HEIGHT, B], faces: { top: face } }],
// join 1, straight on: to the edge of its cell
arm: [{ from: [A, 0, 0], to: [B, HEIGHT, A], faces: { top: face } }],
// join 2, over an edge: a little past it, to meet the wire around the corner on the block's other face
edge: [{ from: [A, 0, -HEIGHT], to: [B, HEIGHT, A], faces: { top: face } }],
// join 3, into a corner: then up the face it runs into, to the wire on that face in the cell above
corner: [
{ from: [A, 0, 0], to: [B, HEIGHT, A], faces: { top: face } },
{ from: [A, 0, 0], to: [B, 16, HEIGHT], faces: { south: face } },
],
center: [{ from: [A, 0, A], to: [B, HEIGHT, B], faces: { top: wire_face } }],
// to the edge of its cell, where it meets the wire on the cell's face that way
arm: [{ from: [A, 0, 0], to: [B, HEIGHT, A], faces: { top: wire_face } }],
// a way out of its cell it joins: a little past the edge, so going around the edge of the block it lies on it meets
// the wire on that block's next face, and straight on it meets the next cell's
out: [{ from: [A, 0, -HEIGHT], to: [B, HEIGHT, A], faces: { top: wire_face } }],
};
// the faces a quarter turn clockwise seen from above takes each face to
@@ -62,7 +61,7 @@ function pointing_east(elements: ModelElementJson[]): ModelElementJson[] {
}
const models: Record<string, ModelElementJson[]> = { ...PIECES };
for (const name of ["arm", "edge", "corner"]) models[`${name}_east`] = pointing_east(PIECES[name]);
for (const name of ["arm", "out"]) models[`${name}_east`] = pointing_east(PIECES[name]);
type Vec = readonly [number, number, number];
const cross = (
@@ -75,10 +74,10 @@ function shape_key(boxes: readonly (readonly number[])[]) {
return JSON.stringify(boxes.map((box) => box.map((v) => Math.round(v * 1e6) / 1e6)).sort());
}
// the boxes a floor piece pointing north has on a wire lying on the block toward side, pointing toward direction: turned
// around the middle of the block so down goes to side and north to direction. clamped to the block, like model_shape
function placed(elements: ModelElementJson[], side: Face, direction: Face) {
const down = FACE_OFFSETS[side];
// the boxes a floor piece pointing north has on the wire covering face of its cell, pointing toward direction: turned
// around the middle of the block so down goes to face and north to direction. clamped to the block, like model_shape
function placed(elements: ModelElementJson[], face: Face, direction: Face) {
const down = FACE_OFFSETS[face];
const north = FACE_OFFSETS[direction];
const east = cross(down, north);
const turn = ([x, y, z]: readonly number[]) =>
@@ -91,8 +90,8 @@ function placed(elements: ModelElementJson[], side: Face, direction: Face) {
}
// the model and turns that put a piece there, the piece pointing north if it can, then its copy pointing east
function placement(piece: string, side: Face, direction: Face) {
const wanted = placed(PIECES[piece], side, direction);
function placement(piece: string, face: Face, direction: Face) {
const wanted = placed(PIECES[piece], face, direction);
for (const name of piece === "center" ? [piece] : [piece, `${piece}_east`]) {
for (const x of [0, 90, 180, 270]) {
for (const y of [0, 90, 180, 270]) {
@@ -101,19 +100,28 @@ function placement(piece: string, side: Face, direction: Face) {
}
}
}
throw new Error(`no turn puts the ${piece} on the ${side} pointing ${direction}`);
throw new Error(`no turn puts the ${piece} on the ${face} pointing ${direction}`);
}
const JOINS = [[1, "arm"], [2, "edge"], [3, "corner"]] as const;
const parts: Record<string, unknown>[] = [];
FACES.forEach((side, s) => {
parts.push({ when: `side=${s}`, ...placement("center", side, DIRECTIONS[side][0]), shape: CENTER_SHAPE });
DIRECTIONS[side].forEach((direction, i) => {
for (const [join, piece] of JOINS) {
parts.push({ when: `side=${s},join_${i}=${join}`, ...placement(piece, side, direction) });
}
for (const covered of FACES) {
parts.push({ when: `${covered}=1`, ...placement("center", covered, DIRECTIONS[covered][0]), shape: CENTER_SHAPE });
}
// two faces that meet inside the cell join at their edge
for (const covered of FACES) {
for (const direction of DIRECTIONS[covered]) {
parts.push({ when: `${covered}=1,${direction}=1`, ...placement("arm", covered, direction) });
}
}
// the ways out of the cell it joins, for every set of faces a cell can cover
for (let set = 1; set < 1 << FACES.length; set++) {
const faces = FACES.filter((_, i) => set & (1 << i));
if (!can_cover(faces)) continue;
const covering = FACES.map((covered) => `${covered}=${faces.includes(covered) ? 1 : 0}`).join(",");
ways_out(faces).forEach(([covered, direction], i) => {
parts.push({ when: `${covering},arm_${i}=1`, ...placement("out", covered, direction) });
});
});
}
const written: string[] = [];
const write = (path: string, json: unknown) => {