feat: final compatibility

This commit is contained in:
TrèsAbhi committed 2023-12-10 17:03:01 -06:00
1 parent dc01eff812
commit d18cf625d0
2 files changed
+27 -47

No files matched your search

+9 -27
View File
@@ -298,43 +298,25 @@ if (allTargets || targets?.includes('tankModels')) {
const nationVehicleId = tank.id;
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<TankParameters>(
`${DATA}/${DOI.tankParameters}/${nation}/${tankIndex}.yaml.dvpl`,
);
const sc2Path = parameters.resourcesPath.blitzModelPath;
// const scgPath = parameters.resourcesPath.blitzModelPath.replace(
// /\.sc2$/,
// '.scg',
// );
const scgPath = parameters.resourcesPath.blitzModelPath.replace(
/\.sc2$/,
'.scg',
);
const sc2Stream = await SCPGStream.fromDVPLFile(
`${DATA}/${DOI['3d']}/${sc2Path}.dvpl`,
);
// const scgStream = await SCPGStream.fromDVPLFile(
// `${DATA}/${DOI['3d']}/${scgPath}.dvpl`,
// );
const scgStream = await SCPGStream.fromDVPLFile(
`${DATA}/${DOI['3d']}/${scgPath}.dvpl`,
);
const sc2Data = sc2Stream.consumeSC2();
// const scgData = scgStream.consumeSCG();
// writeFile(
// `test.json`,
// JSON.stringify(sc2Data, (key, value) =>
// typeof value === 'bigint' ? value.toString() : value,
// ),
// );
const scgData = scgStream.consumeSCG();
}
}),
);
// console.log('Committing tank icons...');
// await commitMultipleFiles(
// 'tresabhi',
// 'blitzkrieg-assets',
// 'main',
// 'tank icons',
// changes,
// true,
// );
}
+18 -20
View File
@@ -123,6 +123,9 @@ export class SCPGStream {
skip(size: number) {
this.index += size;
}
back(size: number) {
this.skip(-size);
}
read(size: number) {
return this.buffer.subarray(this.index, this.index + size);
}
@@ -147,9 +150,6 @@ export class SCPGStream {
consumeAscii(size: number) {
return this.consume(size).toString('ascii');
}
consumeUtf16(size: number) {
return this.consume(size).toString('utf16le');
}
consumeInt8() {
return this.consume(1).readInt8();
@@ -290,12 +290,12 @@ export class SCPGStream {
version: this.consumeUInt32(),
nodeCount: this.consumeUInt32(),
};
const version = this.consumeKA();
const descriptor = this.consumeSC2Descriptor(header.version);
const versionTags = this.consumeKA();
const descriptor = this.consumeSC2Descriptor();
return { header, version, descriptor };
return { header, versionTags, descriptor };
}
consumeSC2Descriptor(version: number) {
consumeSC2Descriptor() {
const size = this.consumeUInt32();
const fileType = this.consumeUInt32();
@@ -309,7 +309,6 @@ export class SCPGStream {
return this.consumeKA();
}
// TODO: change return type
consumeKAValue(
type: KAType = this.consumeUInt8(),
stringTable?: Record<number, string>,
@@ -320,8 +319,13 @@ export class SCPGStream {
case KAType.FILEPATH:
case KAType.STRING: {
const length = this.consumeUInt32();
return this.consumeAscii(length);
if (stringTable) {
const id = this.consumeUInt32();
return stringTable[id];
} else {
const length = this.consumeUInt32();
return this.consumeAscii(length);
}
}
case KAType.BYTE_ARRAY: {
@@ -395,9 +399,7 @@ export class SCPGStream {
case KAType.FASTNAME: {
if (!stringTable) throw new Error('No string table provided');
const index = this.consumeUInt32();
return stringTable[index];
}
@@ -423,14 +425,8 @@ export class SCPGStream {
);
}
}
consumeKAV1Pair(stringTable?: Record<number, string>) {
const name = this.consumeKAValue(undefined, stringTable) as string;
const value = this.consumeKAValue(undefined, stringTable);
return { name, value };
}
consumeKA(stringTable?: Record<number, string>) {
this.consumeAscii(2); // "KA"
this.skip(2); // "KA"
const version = this.consumeUInt16();
const pairs: Record<string, any> = {};
@@ -438,7 +434,9 @@ export class SCPGStream {
const count = this.consumeUInt32();
for (let index = 0; index < count; index++) {
const { name, value } = this.consumeKAV1Pair();
const name = this.consumeKAValue(undefined, stringTable) as string;
const value = this.consumeKAValue(undefined, stringTable);
pairs[name] = value;
}
} else if (version === 0x0002) {