|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { readFileSync, readdirSync } from "node:fs"; |
| 3 | +import path from "node:path"; |
| 4 | +import { fileURLToPath } from "node:url"; |
| 5 | +import { getToolById } from "../../tools/toolRegistry.js"; |
| 6 | + |
| 7 | +const REPO_ROOT = fileURLToPath(new URL("../..", import.meta.url)); |
| 8 | +const ACTIVE_OBJECT_VECTOR_PATHS = Object.freeze([ |
| 9 | + "games/Asteroids/game", |
| 10 | + "games/Asteroids/entities", |
| 11 | + "games/Asteroids/systems", |
| 12 | + "games/Asteroids/flow", |
| 13 | + "tools/workspace-manager-v2/js", |
| 14 | + "tools/object-vector-studio-v2/js", |
| 15 | + "src/engine/rendering/ObjectVectorRuntimeAssetService.js" |
| 16 | +]); |
| 17 | +const DEPRECATED_VECTOR_MAPS_GUARD = "tools/object-vector-studio-v2/js/services/ObjectVectorStudioV2SchemaService.js"; |
| 18 | + |
| 19 | +function readRepoFile(repoPath) { |
| 20 | + return readFileSync(path.join(REPO_ROOT, repoPath), "utf8"); |
| 21 | +} |
| 22 | + |
| 23 | +function listSourceFiles(repoPath) { |
| 24 | + const absolutePath = path.join(REPO_ROOT, repoPath); |
| 25 | + if (repoPath.endsWith(".js") || repoPath.endsWith(".mjs")) { |
| 26 | + return [repoPath]; |
| 27 | + } |
| 28 | + return readdirSync(absolutePath, { withFileTypes: true }).flatMap((entry) => { |
| 29 | + const childRepoPath = `${repoPath}/${entry.name}`; |
| 30 | + if (entry.isDirectory()) { |
| 31 | + return listSourceFiles(childRepoPath); |
| 32 | + } |
| 33 | + return entry.isFile() && (entry.name.endsWith(".js") || entry.name.endsWith(".mjs")) |
| 34 | + ? [childRepoPath] |
| 35 | + : []; |
| 36 | + }); |
| 37 | +} |
| 38 | + |
| 39 | +function asteroidsObjectVectorPayload() { |
| 40 | + return JSON.parse(readRepoFile("games/Asteroids/game.manifest.json")).tools["object-vector-studio-v2"]; |
| 41 | +} |
| 42 | + |
| 43 | +function objectById(payload, objectId) { |
| 44 | + return payload.objects.find((object) => object.id === objectId); |
| 45 | +} |
| 46 | + |
| 47 | +function maxRadius(points) { |
| 48 | + return Math.max(...points.map((point) => Math.hypot(point.x, point.y))); |
| 49 | +} |
| 50 | + |
| 51 | +export async function run() { |
| 52 | + const activeSourceFiles = ACTIVE_OBJECT_VECTOR_PATHS.flatMap(listSourceFiles); |
| 53 | + const disallowedTerms = [ |
| 54 | + "objectVectorRoles", |
| 55 | + "vector-map-editor", |
| 56 | + "fallback vector map", |
| 57 | + "default vector map", |
| 58 | + "defaultVectorMap" |
| 59 | + ]; |
| 60 | + activeSourceFiles.forEach((repoPath) => { |
| 61 | + const text = readRepoFile(repoPath); |
| 62 | + disallowedTerms.forEach((term) => { |
| 63 | + assert.equal(text.includes(term), false, `${repoPath} must not depend on ${term}.`); |
| 64 | + }); |
| 65 | + if (repoPath !== DEPRECATED_VECTOR_MAPS_GUARD) { |
| 66 | + assert.equal(text.includes("vectorMaps"), false, `${repoPath} must not depend on legacy vectorMaps payload data.`); |
| 67 | + } |
| 68 | + }); |
| 69 | + |
| 70 | + const schemaServiceText = readRepoFile(DEPRECATED_VECTOR_MAPS_GUARD); |
| 71 | + assert.match(schemaServiceText, /root\.vectorMaps is deprecated legacy vector-map data/); |
| 72 | + assert.match(schemaServiceText, /objects\[\]\.tags and root\.objects\[\]\.shapes only/); |
| 73 | + |
| 74 | + const vectorMapEditor = getToolById("vector-map-editor"); |
| 75 | + assert.equal(vectorMapEditor.legacy, true, "Vector Map Editor must be marked legacy in the active registry."); |
| 76 | + assert.match(vectorMapEditor.shortDescription, /^Deprecated:/); |
| 77 | + |
| 78 | + const objectVectorPayload = asteroidsObjectVectorPayload(); |
| 79 | + assert.deepEqual(Object.keys(objectVectorPayload).sort(), ["name", "objects", "toolId", "version"]); |
| 80 | + assert.equal(Object.hasOwn(objectVectorPayload, "vectorMaps"), false); |
| 81 | + |
| 82 | + const ship = objectById(objectVectorPayload, "object.asteroids.ship"); |
| 83 | + const flameLines = ship.shapes.filter((shape) => shape.tool === "line" && shape.style?.stroke === "#FFBE64"); |
| 84 | + assert.equal(flameLines.length, 4, "Asteroids ship flame duplicate line shapes are intentional flicker animation assets."); |
| 85 | + const moveState = ship.states.find((state) => state.id === "move"); |
| 86 | + assert.equal(moveState.frames.length >= 2, true, "Asteroids ship move state must preserve flicker animation frames."); |
| 87 | + |
| 88 | + const largeAsteroid = objectById(objectVectorPayload, "object.asteroids.large-asteroid"); |
| 89 | + const mediumAsteroid = objectById(objectVectorPayload, "object.asteroids.medium-asteroid"); |
| 90 | + const smallAsteroid = objectById(objectVectorPayload, "object.asteroids.small-asteroid"); |
| 91 | + const largeRadius = maxRadius(largeAsteroid.shapes[0].geometry.points); |
| 92 | + const mediumRadius = maxRadius(mediumAsteroid.shapes[0].geometry.points); |
| 93 | + const smallRadius = maxRadius(smallAsteroid.shapes[0].geometry.points); |
| 94 | + assert.equal(largeRadius > mediumRadius && mediumRadius > smallRadius, true, "Asteroids object geometry must preserve arcade-scale large > medium > small proportions."); |
| 95 | +} |
0 commit comments