feat: sc2 start

This commit is contained in:
TrèsAbhi committed 2023-12-08 11:36:54 -06:00
1 parent 6b9bf76da2
commit 875abf4d32
1 file changed
+40 -41
+40 -41
View File
@@ -1,4 +1,3 @@
import { writeFileSync } from 'fs';
import { readFile } from 'fs/promises'; import { readFile } from 'fs/promises';
import { range } from 'lodash'; import { range } from 'lodash';
@@ -228,45 +227,36 @@ class SCPGStream {
}); });
} }
console.log(verticesStream.consumeRemaining().length);
return { vertices, indices }; return { vertices, indices };
}); });
// writeFileSync( return polygonGroups.map((group) => ({
// 'test.txt', vertices: group.vertices
// polygonGroups .filter(({ type }) => type === VertexType.VERTEX)
// .map((i) => .map(({ value }) => value),
// i.vertices indices: group.indices,
// .map( }));
// (e) => }
// `${VertexType[e.type].padEnd(16, ' ')} ${e.value
// .map((j) => j.toString(10).padStart(25, ' '))
// .join(' ')}`,
// )
// .join('\n'),
// )
// .join('\n\n'),
// );
// writeFileSync( consumeSC2Header() {
// 'test.json', return {
name: this.consumeAscii(4).value,
version: this.consumeUInt32().value,
nodeCount: this.consumeUInt32().value,
};
}
consumeSC2Descriptor() {
const size = this.consumeUInt32().value;
const fileType = this.consumeUInt32().value;
// ) this.skip(8); // other felids that we don't care about for some reason
writeFileSync( console.log(this.consumeKA());
'test.json', }
JSON.stringify( consumeSC2() {
polygonGroups.map((group) => ({ const header = this.consumeSC2Header();
vertices: group.vertices const versionTags = this.consumeKA();
.filter(({ type }) => type === VertexType.VERTEX) const descriptor = this.consumeSC2Descriptor();
.map(({ value }) => value),
indices: group.indices,
})),
),
);
return polygonGroups;
} }
consumeKAHeader() { consumeKAHeader() {
@@ -297,7 +287,7 @@ class SCPGStream {
throw new TypeError(`Unknown KA type: ${type}`); throw new TypeError(`Unknown KA type: ${type}`);
} }
} }
consumeKAPair() { consumeKAV1Pair() {
const name = this.consumeKAValue().value as string; const name = this.consumeKAValue().value as string;
const value = this.consumeKAValue(); const value = this.consumeKAValue();
@@ -307,16 +297,25 @@ class SCPGStream {
const header = this.consumeKAHeader(); const header = this.consumeKAHeader();
const pairs: Record<string, any> = {}; const pairs: Record<string, any> = {};
for (let index = 0; index < header.count; index++) { if (header.version === 1) {
const { name, value } = this.consumeKAPair(); for (let index = 0; index < header.count; index++) {
pairs[name] = value; const { name, value } = this.consumeKAV1Pair();
} pairs[name] = value;
}
} else if (header.version === 2) {
for (let index = 0; index < header.count; index++) {
const length = this.consumeUInt16().value;
const string = this.consumeAscii(length);
console.log(string.value);
}
} else throw new SyntaxError(`Unknown KA version: ${header.version}`);
return pairs as Type; return pairs as Type;
} }
} }
const stream = new SCPGStream(await readFile('test.scg')); const stream = new SCPGStream(await readFile('test.sc2'));
stream.consumeSCG(); stream.consumeSC2();
// console.log(stream.consumeSCG()); // console.log(stream.consumeSCG());