[ts] Fix lints in HeadlessTest

This commit is contained in:
Mario Zechner 2025-07-16 19:02:03 +02:00
parent 75e58c70ce
commit 3927ff25ff
2 changed files with 88 additions and 230 deletions

View File

@ -29,9 +29,7 @@
"copyfiles": "^2.4.1",
"esbuild": "^0.25.6",
"rimraf": "^6.0.1",
"tsx": "^4.19.2",
"typescript": "^5.8.3",
"typescript-formatter": "^7.2.2"
"typescript": "^5.8.3"
}
},
"node_modules/@biomejs/biome": {
@ -1423,20 +1421,6 @@
"node": ">=0.1.90"
}
},
"node_modules/commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"dev": true,
"license": "MIT"
},
"node_modules/commandpost": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/commandpost/-/commandpost-1.4.0.tgz",
"integrity": "sha512-aE2Y4MTFJ870NuB/+2z1cXBhSBBzRydVVjzhFC4gtenEhpnj15yu0qptWGJsO9YGrcPZ3ezX8AWb1VA391MKpQ==",
"dev": true,
"license": "MIT"
},
"node_modules/concat-map": {
"version": "0.0.1",
"dev": true,
@ -1630,22 +1614,6 @@
"dev": true,
"license": "MIT"
},
"node_modules/editorconfig": {
"version": "0.15.3",
"resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.15.3.tgz",
"integrity": "sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g==",
"dev": true,
"license": "MIT",
"dependencies": {
"commander": "^2.19.0",
"lru-cache": "^4.1.5",
"semver": "^5.6.0",
"sigmund": "^1.0.1"
},
"bin": {
"editorconfig": "bin/editorconfig"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"dev": true,
@ -1893,19 +1861,6 @@
"node": ">= 0.4"
}
},
"node_modules/get-tsconfig": {
"version": "4.10.1",
"resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.10.1.tgz",
"integrity": "sha512-auHyJ4AgMz7vgS8Hp3N6HXSmlMdUyhSUrfBF16w153rxtLIEOE+HGqaBppczZvnHLqQJfiHotCYpNhl0lUROFQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"resolve-pkg-maps": "^1.0.0"
},
"funding": {
"url": "https://github.com/privatenumber/get-tsconfig?sponsor=1"
}
},
"node_modules/gifuct-js": {
"version": "2.1.2",
"license": "MIT",
@ -2108,17 +2063,6 @@
"dev": true,
"license": "MIT"
},
"node_modules/lru-cache": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz",
"integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==",
"dev": true,
"license": "ISC",
"dependencies": {
"pseudomap": "^1.0.2",
"yallist": "^2.1.2"
}
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"license": "MIT",
@ -2457,13 +2401,6 @@
"node": ">=0.8.0"
}
},
"node_modules/pseudomap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
"integrity": "sha512-b/YwNhb8lk1Zz2+bXXpS/LK9OisiZZ1SNsSLxN1x2OXVEhW2Ckr/7mWE5vrC1ZTiJlD9g19jWszTmJsB+oEpFQ==",
"dev": true,
"license": "ISC"
},
"node_modules/punycode": {
"version": "1.4.1",
"license": "MIT",
@ -2510,16 +2447,6 @@
"node": ">=0.10.0"
}
},
"node_modules/resolve-pkg-maps": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz",
"integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==",
"dev": true,
"license": "MIT",
"funding": {
"url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1"
}
},
"node_modules/rimraf": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-6.0.1.tgz",
@ -2593,16 +2520,6 @@
"dev": true,
"license": "MIT"
},
"node_modules/semver": {
"version": "5.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz",
"integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==",
"dev": true,
"license": "ISC",
"bin": {
"semver": "bin/semver"
}
},
"node_modules/send": {
"version": "0.18.0",
"dev": true,
@ -2806,13 +2723,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/sigmund": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz",
"integrity": "sha512-fCvEXfh6NWpm+YSuY2bpXb/VIihqWA6hLsgboC+0nl71Q7N7o2eaCW8mJa/NLvQhs6jpd3VZV4UiUQlV6+lc8g==",
"dev": true,
"license": "ISC"
},
"node_modules/signal-exit": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
@ -2974,26 +2884,6 @@
"dev": true,
"license": "0BSD"
},
"node_modules/tsx": {
"version": "4.20.3",
"resolved": "https://registry.npmjs.org/tsx/-/tsx-4.20.3.tgz",
"integrity": "sha512-qjbnuR9Tr+FJOMBqJCW5ehvIo/buZq7vH7qD7JziU98h6l3qGy0a/yPFjwO+y0/T7GFpNgNAvEcPPVfyT8rrPQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"esbuild": "~0.25.0",
"get-tsconfig": "^4.7.5"
},
"bin": {
"tsx": "dist/cli.mjs"
},
"engines": {
"node": ">=18.0.0"
},
"optionalDependencies": {
"fsevents": "~2.3.3"
}
},
"node_modules/typescript": {
"version": "5.8.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz",
@ -3008,26 +2898,6 @@
"node": ">=14.17"
}
},
"node_modules/typescript-formatter": {
"version": "7.2.2",
"resolved": "https://registry.npmjs.org/typescript-formatter/-/typescript-formatter-7.2.2.tgz",
"integrity": "sha512-V7vfI9XArVhriOTYHPzMU2WUnm5IMdu9X/CPxs8mIMGxmTBFpDABlbkBka64PZJ9/xgQeRpK8KzzAG4MPzxBDQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"commandpost": "^1.0.0",
"editorconfig": "^0.15.0"
},
"bin": {
"tsfmt": "bin/tsfmt"
},
"engines": {
"node": ">= 4.2.0"
},
"peerDependencies": {
"typescript": "^2.1.6 || >=2.7.0-dev || >=2.8.0-dev || >=2.9.0-dev || >=3.0.0-dev"
}
},
"node_modules/undici-types": {
"version": "5.26.5",
"dev": true,
@ -3180,13 +3050,6 @@
"node": ">=10"
}
},
"node_modules/yallist": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
"integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==",
"dev": true,
"license": "ISC"
},
"node_modules/yargs": {
"version": "17.7.2",
"dev": true,

View File

@ -38,7 +38,7 @@ import {
Physics,
Skeleton,
SkeletonBinary,
SkeletonData,
type SkeletonData,
SkeletonJson,
TextureAtlas
} from '../src/index.js';
@ -105,105 +105,100 @@ class Printer {
}
}
// Main DebugPrinter class
class DebugPrinter {
static async main (args: string[]): Promise<void> {
if (args.length < 2) {
console.error("Usage: DebugPrinter <skeleton-path> <atlas-path> [animation-name]");
process.exit(1);
}
const skeletonPath = args[0];
const atlasPath = args[1];
const animationName = args.length >= 3 ? args[2] : null;
try {
// Load atlas
const atlasData = await fs.readFile(atlasPath, 'utf8');
const atlas = new TextureAtlas(atlasData);
// Load skeleton data
const skeletonData = await this.loadSkeletonData(skeletonPath, atlas);
// Print skeleton data
const printer = new Printer();
console.log("=== SKELETON DATA ===");
printer.printSkeletonData(skeletonData);
// Create skeleton and animation state
const skeleton = new Skeleton(skeletonData);
const stateData = new AnimationStateData(skeletonData);
const state = new AnimationState(stateData);
skeleton.setupPose();
// Set animation or setup pose
if (animationName) {
// Find and set animation
const animation = skeletonData.findAnimation(animationName);
if (!animation) {
console.error(`Animation not found: ${animationName}`);
process.exit(1);
}
state.setAnimation(0, animationName, true);
// Update and apply
state.update(0.016);
state.apply(skeleton);
}
skeleton.updateWorldTransform(Physics.update);
// Print skeleton state
console.log("\n=== SKELETON STATE ===");
printer.printSkeleton(skeleton);
} catch (error) {
console.error("Error:", error);
process.exit(1);
}
async function main (args: string[]): Promise<void> {
if (args.length < 2) {
console.error("Usage: DebugPrinter <skeleton-path> <atlas-path> [animation-name]");
process.exit(1);
}
private static async loadSkeletonData (skeletonPath: string, atlas: TextureAtlas): Promise<SkeletonData> {
const attachmentLoader = new AtlasAttachmentLoader(atlas);
const ext = path.extname(skeletonPath).toLowerCase();
const skeletonPath = args[0];
const atlasPath = args[1];
const animationName = args.length >= 3 ? args[2] : null;
if (ext === '.json') {
const jsonData = await fs.readFile(skeletonPath, 'utf8');
const json = new SkeletonJson(attachmentLoader);
json.scale = 1;
const skeletonData = json.readSkeletonData(jsonData);
try {
// Load atlas
const atlasData = await fs.readFile(atlasPath, 'utf8');
const atlas = new TextureAtlas(atlasData);
// Set name from filename if not already set
if (!skeletonData.name) {
const basename = path.basename(skeletonPath);
const nameWithoutExt = basename.substring(0, basename.lastIndexOf('.')) || basename;
skeletonData.name = nameWithoutExt;
// Load skeleton data
const skeletonData = await loadSkeletonData(skeletonPath, atlas);
// Print skeleton data
const printer = new Printer();
console.log("=== SKELETON DATA ===");
printer.printSkeletonData(skeletonData);
// Create skeleton and animation state
const skeleton = new Skeleton(skeletonData);
const stateData = new AnimationStateData(skeletonData);
const state = new AnimationState(stateData);
skeleton.setupPose();
// Set animation or setup pose
if (animationName) {
// Find and set animation
const animation = skeletonData.findAnimation(animationName);
if (!animation) {
console.error(`Animation not found: ${animationName}`);
process.exit(1);
}
return skeletonData;
} else if (ext === '.skel') {
const binaryData = await fs.readFile(skeletonPath);
const binary = new SkeletonBinary(attachmentLoader);
binary.scale = 1;
const skeletonData = binary.readSkeletonData(new Uint8Array(binaryData));
// Set name from filename if not already set
if (!skeletonData.name) {
const basename = path.basename(skeletonPath);
const nameWithoutExt = basename.substring(0, basename.lastIndexOf('.')) || basename;
skeletonData.name = nameWithoutExt;
}
return skeletonData;
} else {
throw new Error(`Unsupported skeleton file format: ${ext}`);
state.setAnimation(0, animationName, true);
// Update and apply
state.update(0.016);
state.apply(skeleton);
}
skeleton.updateWorldTransform(Physics.update);
// Print skeleton state
console.log("\n=== SKELETON STATE ===");
printer.printSkeleton(skeleton);
} catch (error) {
console.error("Error:", error);
process.exit(1);
}
}
async function loadSkeletonData (skeletonPath: string, atlas: TextureAtlas): Promise<SkeletonData> {
const attachmentLoader = new AtlasAttachmentLoader(atlas);
const ext = path.extname(skeletonPath).toLowerCase();
if (ext === '.json') {
const jsonData = await fs.readFile(skeletonPath, 'utf8');
const json = new SkeletonJson(attachmentLoader);
json.scale = 1;
const skeletonData = json.readSkeletonData(jsonData);
// Set name from filename if not already set
if (!skeletonData.name) {
const basename = path.basename(skeletonPath);
const nameWithoutExt = basename.substring(0, basename.lastIndexOf('.')) || basename;
skeletonData.name = nameWithoutExt;
}
return skeletonData;
} else if (ext === '.skel') {
const binaryData = await fs.readFile(skeletonPath);
const binary = new SkeletonBinary(attachmentLoader);
binary.scale = 1;
const skeletonData = binary.readSkeletonData(new Uint8Array(binaryData));
// Set name from filename if not already set
if (!skeletonData.name) {
const basename = path.basename(skeletonPath);
const nameWithoutExt = basename.substring(0, basename.lastIndexOf('.')) || basename;
skeletonData.name = nameWithoutExt;
}
return skeletonData;
} else {
throw new Error(`Unsupported skeleton file format: ${ext}`);
}
}
// Run if called directly
if (import.meta.url === `file://${process.argv[1]}`) {
DebugPrinter.main(process.argv.slice(2));
}
export default DebugPrinter;
main(process.argv.slice(2));
}