From 83e28b4dac71da51ab0ce0b8842e035421b4d6c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sat, 9 Dec 2023 19:05:46 -0600 Subject: [PATCH] feat: move versions x2 --- scripts/buildAssets.ts | 14 +++++++++--- src/core/blitz/SCPGStream.ts | 41 ++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/scripts/buildAssets.ts b/scripts/buildAssets.ts index 21f11b928..c405d9605 100644 --- a/scripts/buildAssets.ts +++ b/scripts/buildAssets.ts @@ -288,7 +288,7 @@ if (allTargets || targets?.includes('tankModels')) { ); await Promise.all( - [nations[0]].map(async (nation) => { + nations.map(async (nation) => { const tanks = await readXMLDVPL( `${DATA}/${DOI.vehicleDefinitions}/${nation}/list.xml.dvpl`, ); @@ -299,7 +299,7 @@ if (allTargets || targets?.includes('tankModels')) { const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1; // if (id !== 817) continue; - console.log(`Building model ${id} @ ${nation}/${tankIndex}`); + // console.log(`Building model ${id} @ ${nation}/${tankIndex}`); const parameters = await readYAMLDVPL( `${DATA}/${DOI.tankParameters}/${nation}/${tankIndex}.yaml.dvpl`, @@ -315,7 +315,7 @@ if (allTargets || targets?.includes('tankModels')) { // const scgStream = await SCPGStream.fromDVPLFile( // `${DATA}/${DOI['3d']}/${scgPath}.dvpl`, // ); - const sc2Data = sc2Stream.consumeSC2(); + // const sc2Data = sc2Stream.consumeSC2(); // const scgData = scgStream.consumeSCG(); // writeFile( @@ -324,6 +324,14 @@ if (allTargets || targets?.includes('tankModels')) { // typeof value === 'bigint' ? value.toString() : value, // ), // ); + + try { + sc2Stream.consumeSC2(); + } catch (error) { + if (!(error as Error).message.startsWith('Unhandled KA version')) { + throw error; + } + } } }), ); diff --git a/src/core/blitz/SCPGStream.ts b/src/core/blitz/SCPGStream.ts index d26e3627f..915349445 100644 --- a/src/core/blitz/SCPGStream.ts +++ b/src/core/blitz/SCPGStream.ts @@ -30,7 +30,7 @@ enum KAType { INT16 = 24, UINT16 = 25, ARRAY = 27, - TRANSFORM = 29, + CUSTOMIZATION_TRANSFORM = 29, } enum VertexType { @@ -305,9 +305,7 @@ export class SCPGStream { return { size, fileType }; } consumeSC2() { - // TODO: HANDLE MORE THAN 1 NODE this.consumeSC2Header(); - return this.consumeKA(); } @@ -323,11 +321,14 @@ export class SCPGStream { type: KAType = this.consumeUInt8(), stringTable?: Record, ): unknown { - switch (type) { - case KAType.INT32: - return this.consumeInt32(); + console.log(KAType[type]); - case (KAType.STRING, KAType.FILEPATH): { + switch (type) { + case KAType.NONE: + return undefined; + + case KAType.FILEPATH: + case KAType.STRING: { const length = this.consumeUInt32(); return this.consumeAscii(length); } @@ -377,13 +378,6 @@ export class SCPGStream { case KAType.BOOLEAN: return this.consumeBoolean(); - case KAType.AABBOX3: { - const minimum = this.consumeVector3(); - const maximum = this.consumeVector3(); - - return { minimum, maximum }; - } - case KAType.VECTOR2: return this.consumeVector2(); case KAType.VECTOR3: @@ -391,6 +385,9 @@ export class SCPGStream { case KAType.VECTOR4: return this.consumeVector4(); + case KAType.COLOR: + return this.consumeVector4(); // as RGBA + case KAType.MATRIX2: return this.consumeMatrix2(); case KAType.MATRIX3: @@ -398,6 +395,13 @@ export class SCPGStream { case KAType.MATRIX4: return this.consumeMatrix4(); + case KAType.AABBOX3: { + const minimum = this.consumeVector3(); + const maximum = this.consumeVector3(); + + return { minimum, maximum }; + } + case KAType.FASTNAME: { if (!stringTable) throw new Error('No string table provided'); @@ -406,7 +410,7 @@ export class SCPGStream { return stringTable[index]; } - case KAType.TRANSFORM: { + case KAType.CUSTOMIZATION_TRANSFORM: { if (!stringTable) throw new Error('No string table provided'); const position = this.consumeVector3(); @@ -417,9 +421,6 @@ export class SCPGStream { return { position, scale, rotation, UNCONFIRMED_inset }; } - case KAType.NONE: - return undefined; - default: throw new TypeError( `Unhandled KA type: ${type} (${KAType[type] ?? 'unknown type'})`, @@ -432,7 +433,7 @@ export class SCPGStream { return { name, value }; } - consumeKA(stringTable?: Record) { + consumeKA(stringTable?: Record) { const header = this.consumeKAHeader(); const pairs: Record = {}; @@ -481,7 +482,7 @@ export class SCPGStream { pairs[key] = value; } } - } else throw new SyntaxError(`Unhandled KA version: ${header.version}`); + } else throw new RangeError(`Unhandled KA version: ${header.version}`); return pairs; }