Clean up duplicates and dead code, and fix the + menu check (#85)
game-maker / gate (push) Successful in 3m2s
game-maker / suite (push) Successful in 15m29s

Refactoring round 9 covers everything since round 8 (14972d0): 62
commits with about 29 000 new lines in src, api, tools and tests.
Behaviour is unchanged. The one fix is in a check: e2e 04 counted 25
asset types, and the shader function from #303 makes 26, so the run
of a526e1b failed there.

Duplicate code (jscpd over src, 50 tokens, without the two licence
texts: 35 clones / 289 lines before, 29 / 232 after):

- ShaderPicture (new, viewport/shaderPicture.ts) is the picture a
  camera's shader and a particle field's shader are laid over. It
  keeps the render texture while its size holds and frees the
  replaced one once the shader holds the new one. CameraShade and
  ParticleField.shadeField drew it the same way, line for line.
- CameraShade builds its mesh on the first draw. Before, every redraw
  of a view without a camera shader built a mesh and threw it away.
- emptyHost in inspector/host.ts builds the empty host the Inspector,
  the Variables tab and the Tilemap panel start from.
- paddedQuad(null) is the plain unit quad. symbols.ts and
  shaderPasses.ts each wrote it out by hand.
- In graph/nested.ts, calls of shader functions and On behavior
  nodes are followed by one walk, `reaches`, over ids `namedBy` a
  node type.

Dead code:

- ShaderEditor.colorFieldOf and the getter CurveCanvas.snapping had
  no reader.
- 22 values used only in their own file lose their `export`. Types
  and the node catalogues of shaders and particles stay exported.
- Kept on purpose: PhysicsSystem.holdsJoint is read by tests only,
  but it is their one view of whether a joint holds.
- A pass with stricter lint rules over every file changed since
  round 8 found no bug. PixelArtEditor.started is now readonly.

Comments and docs:

- Ten comments told history ("since #190", "used to", "any more").
  They now describe what is. The bundle is md5-identical before and
  after, and the four e2e files minify to the same bytes.
- README: joint and shader function in the asset list, joints on the
  Physics row, what the Shaders page covers, two CI runners.
- e2e 04 keeps the number of asset types once, as ASSET_TYPE_COUNT.
- screenshot.png in the README is a new picture of the editor
  (3840x2160 instead of 1825x1140), taken by the user.

Tests:
- Gate on melektaus-atx: 229 files, 3514 tests, CHECK EXIT 0
  (+3 for emptyHost, +1 for the unit quad).
- e2e 1-4, 31, 63 on melektaus-atx: ALL PASSED, 195 checks. That is
  the + menu of 04, the field shader of 31 and the camera shader of
  63, both through ShaderPicture.
- No new e2e check, so the sum stays 1728.
- Counter-checks, each put back and compared with cmp: reaches that
  never goes on fails 1 test, listensTo reading the wrong parameter
  fails 1, emptyHost dropping what a panel hands in fails 1, folding
  without a relayout fails 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-10-03 17:38:39 +02:00
1 parent a526e1b40f
commit 808e1eefc2
43 files changed
+314 -224

No files matched your search

+1 -1
View File
@@ -82,7 +82,7 @@ export function colliderRefusal(project: Project, holder: ObjectHolder, target:
* frame's size, so it is scaled up to the sprite, and a sprite stretched out of the frame's
* proportions keeps the box, since an outline cannot be stretched. Anything else: schema defaults.
*/
export function newColliderProps(project: Project, targetAsset: Asset, target: SceneObject): PropertyBag {
function newColliderProps(project: Project, targetAsset: Asset, target: SceneObject): PropertyBag {
if (targetAsset.type !== 'sprite') return {};
const size = spriteSize(project, targetAsset, target);
const frame = textOf(resolveSceneObjectProps(project, targetAsset, target).texture ?? '');
+1 -1
View File
@@ -53,7 +53,7 @@ import { requireVectorArt, requireVectorItem, requireVectorShape } from './requi
* which layer. `edit` is one of the functions of `model/vectorTree.ts`; it hands back new layers, so
* the undo is simply the layers that were there.
*/
export class EditVectorTreeCommand implements Command {
class EditVectorTreeCommand implements Command {
private previous: VectorLayer[] = [];
constructor(
+32 -34
View File
@@ -383,48 +383,46 @@ function functionCallProblem(node: GraphNode, lookup: GraphLookup, ownerId: stri
return null;
}
/** The ids the nodes of one type in that graph name in `param`, picked or not found alike. */
function namedBy(graph: Graph, type: string, param: string): string[] {
return graph.nodes
.filter((n) => n.type === type)
.map((n) => textOf(n.params[param] ?? ''))
.filter((id) => id !== '');
}
/** Whether `from` is `target` or leads to it through `next`, however many steps lie between. */
function reaches(
from: string,
target: string,
next: (id: string) => string[],
seen = new Set<string>(),
): boolean {
if (from === target) return true;
if (seen.has(from)) return false;
seen.add(from);
return next(from).some((id) => reaches(id, target, next, seen));
}
/** The functions the calls in that graph name, picked or not found alike. */
export function calledFunctions(graph: Graph): string[] {
return graph.nodes
.filter((n) => n.type === SHADER_CALL)
.map((n) => textOf(n.params[FUNCTION_PARAM] ?? ''))
.filter((id) => id !== '');
return namedBy(graph, SHADER_CALL, FUNCTION_PARAM);
}
/** Whether `from` is `target` or calls it, however many functions lie between. */
export function callsFunction(
lookup: GraphLookup,
from: string,
target: string,
seen: Set<string> = new Set(),
): boolean {
if (from === target) return true;
if (seen.has(from)) return false;
seen.add(from);
const called = lookup.shaderFunction(from);
return called ? calledFunctions(called.graph).some((id) => callsFunction(lookup, id, target, seen)) : false;
}
/** The behaviors the `On behavior` nodes of that graph name, picked or not found alike. */
export function heardBehaviors(graph: Graph): string[] {
return graph.nodes
.filter((n) => n.type === ON_BEHAVIOR)
.map((n) => textOf(n.params[BEHAVIOR_PARAM] ?? ''))
.filter((id) => id !== '');
export function callsFunction(lookup: GraphLookup, from: string, target: string): boolean {
return reaches(from, target, (id) => {
const called = lookup.shaderFunction(id);
return called ? calledFunctions(called.graph) : [];
});
}
/** Whether `from` is `target` or hears it, however many behaviors lie between. */
export function listensTo(
lookup: GraphLookup,
from: string,
target: string,
seen: Set<string> = new Set(),
): boolean {
if (from === target) return true;
if (seen.has(from)) return false;
seen.add(from);
const program = lookup.behavior(from);
return program ? heardBehaviors(program.graph).some((id) => listensTo(lookup, id, target, seen)) : false;
function listensTo(lookup: GraphLookup, from: string, target: string): boolean {
return reaches(from, target, (id) => {
const program = lookup.behavior(id);
return program ? namedBy(program.graph, ON_BEHAVIOR, BEHAVIOR_PARAM) : [];
});
}
/**
+1 -1
View File
@@ -225,7 +225,7 @@ export function frameSlice(frame: TextureFrame): FrameSlice {
/**
* Writes the slice back, dropping the keys again once they mean nothing: a frame nobody sliced
* reads and saves exactly as it did before #41, so undo of the first slice restores the old shape.
* reads and saves without them, so undo of the first slice restores the old shape.
*/
export function setFrameSlice(frame: TextureFrame, slice: FrameSlice): void {
const border = normalizeBorders(slice.border, frame.w, frame.h);
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* Scaling, turning and mirroring vector art shapes (#291). A transformation is baked into the points:
* the model keeps no matrix, so everything that reads points – combining, the picture a sprite wears,
* a press in the tab – goes on reading them as before. This module says what a shape reads after an
* a press in the tab – reads them as they are. This module says what a shape reads after an
* affine map, how far a selection reaches, and which map a pull on the frame's handles means.
*
* The outline's width is left alone: a line of two pixels is two pixels at every size of its shape.
+2 -2
View File
@@ -73,7 +73,7 @@ const NUMBER_STEP = 0.1;
* direction and the speed of one particle are not the same draw. Mixing `salt` in is what separates
* the nodes; the node's id is hashed into it, so an edit elsewhere in the graph does not reshuffle it.
*/
export function random01(seed: number, salt: number): number {
function random01(seed: number, salt: number): number {
let h = (seed ^ salt) >>> 0;
h = Math.imul(h ^ (h >>> 16), 0x45d9f3b) >>> 0;
h = Math.imul(h ^ (h >>> 16), 0x45d9f3b) >>> 0;
@@ -498,6 +498,6 @@ export function nextParticlePropertyName(taken: ReadonlySet<string>): string {
for (let n = 2; ; n++) if (!taken.has(`value${n}`)) return `value${n}`;
}
export function paramNameOf(params: PropertyBag): string {
function paramNameOf(params: PropertyBag): string {
return textOf(params[PROPERTY_NAME_PARAM] ?? '');
}
+1 -1
View File
@@ -386,7 +386,7 @@ export function isSortProp(key: string): boolean {
* Which cameras see a drawn object (#302). Without a choice of its own it is on its parent's layer,
* so a HUD container on `UI` takes everything in it along.
*/
export const RENDER_LAYER_ROW: FlatDef<'layer'> = {
const RENDER_LAYER_ROW: FlatDef<'layer'> = {
key: RENDER_LAYER_KEY,
label: 'Render layer',
kind: 'layer',
+1 -1
View File
@@ -60,7 +60,7 @@ function num(value: unknown, fallback: unknown): number {
return Number.isFinite(n) ? n : Number(fallback);
}
export function jointTypeOf(props: PropertyBag): JointType {
function jointTypeOf(props: PropertyBag): JointType {
const type = props[JOINT_TYPE_KEY];
return (JOINT_TYPES as readonly unknown[]).includes(type) ? (type as JointType) : 'hinge';
}
+1 -1
View File
@@ -54,7 +54,7 @@ export function shaderParamDefs(graph: Graph): ShaderParamDef[] {
});
}
export function propertyColor(params: PropertyBag): number {
function propertyColor(params: PropertyBag): number {
return colorOf(params[PROPERTY_DEFAULT_PARAM] ?? DEFAULT_PROPERTY_COLOR, DEFAULT_PROPERTY_COLOR);
}
+1 -1
View File
@@ -32,7 +32,7 @@ export type FunctionLookup = GraphLookup['shaderFunction'];
export const NO_FUNCTIONS: FunctionLookup = () => null;
/** A function takes and gives values only: a picture stays the caller's. */
export const FUNCTION_PORT_KINDS = ['number', 'color'] as const;
const FUNCTION_PORT_KINDS = ['number', 'color'] as const;
const DEFAULT_COLOR = 0xffffff;
/** A declared port of a function as the nodes on either side of it see it. */
+3 -3
View File
@@ -135,7 +135,7 @@ export function paddingOf(params: PropertyBag): number {
* How many cells per axis the wearer's quad is cut into (#79) – a setting of the Vertex output node,
* because how fine the grid has to be is the effect's to say. 1 is the plain quad.
*/
export const SUBDIVISIONS_PARAM = 'subdivisions';
const SUBDIVISIONS_PARAM = 'subdivisions';
export const DEFAULT_SUBDIVISIONS = 8;
export const MAX_SUBDIVISIONS = 64;
@@ -289,7 +289,7 @@ export const ShaderOutput: ShaderNodeDef = {
};
/** How large a Pass's picture is, as a share of the wearer's picture per side. */
export const PASS_RESOLUTION_PARAM = 'resolution';
const PASS_RESOLUTION_PARAM = 'resolution';
const PASS_RESOLUTIONS: Record<string, number> = { full: 1, half: 0.5, quarter: 0.25 };
/** Pictures a shader may draw before its Output: each is one more draw of the wearer's picture. */
export const MAX_PASSES = 8;
@@ -395,7 +395,7 @@ export const ShaderSample: ShaderNodeDef = {
},
};
export const MAX_BLUR_RADIUS = 8;
const MAX_BLUR_RADIUS = 8;
const BLUR = 'blur';
const BLUR_KIND_PARAM = 'kind';
const BLUR_DIRECTION_PARAM = 'direction';
+1 -1
View File
@@ -12,7 +12,7 @@ export function closestOnSegment(p: Vec2, a: Vec2, b: Vec2): Vec2 {
return { x: a.x + ab.x * t, y: a.y + ab.y * t };
}
export function lerpVec(a: Vec2, b: Vec2, t: number): Vec2 {
function lerpVec(a: Vec2, b: Vec2, t: number): Vec2 {
return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };
}