@gaialabs/core 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +84 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +651 -646
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +651 -646
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +84 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1897,8 +1897,8 @@ var TableEntry = class {
|
|
|
1897
1897
|
location;
|
|
1898
1898
|
object;
|
|
1899
1899
|
constructor(location) {
|
|
1900
|
-
|
|
1901
|
-
|
|
1900
|
+
if (typeof location !== "number") throw new Error("Location is required");
|
|
1901
|
+
this.location = location;
|
|
1902
1902
|
}
|
|
1903
1903
|
};
|
|
1904
1904
|
|
|
@@ -2678,7 +2678,7 @@ var DbStringType = class {
|
|
|
2678
2678
|
}, {});
|
|
2679
2679
|
this.dictionaryLookup = Object.values(this.dictionaries).flatMap((y) => y.entries.map((z, ix) => ({
|
|
2680
2680
|
text: z,
|
|
2681
|
-
id: (y.command ?? 0) | (y.base ?? 0 + ix)
|
|
2681
|
+
id: (y.command ?? 0) << 8 | (y.base ?? 0 + ix)
|
|
2682
2682
|
}))).sort((a, b) => b.text.length - a.text.length);
|
|
2683
2683
|
}
|
|
2684
2684
|
};
|
|
@@ -3354,6 +3354,7 @@ var QuintetLZ = class QuintetLZ {
|
|
|
3354
3354
|
let srcIx = srcPosition ?? 0;
|
|
3355
3355
|
let dstIx = 0;
|
|
3356
3356
|
if (!srcLen) srcLen = srcData.length - srcIx;
|
|
3357
|
+
let endIx = srcIx + srcLen;
|
|
3357
3358
|
const outputBuffer = new Uint8Array(srcLen * 2);
|
|
3358
3359
|
outputBuffer[dstIx++] = srcLen & 255;
|
|
3359
3360
|
outputBuffer[dstIx++] = srcLen >> 8 & 255;
|
|
@@ -3363,28 +3364,38 @@ var QuintetLZ = class QuintetLZ {
|
|
|
3363
3364
|
* @returns Tuple of [startByte, length]
|
|
3364
3365
|
*/
|
|
3365
3366
|
const getCommand = () => {
|
|
3366
|
-
const maxLen = Math.min(
|
|
3367
|
+
const maxLen = Math.min(endIx - srcIx, 17);
|
|
3367
3368
|
if (maxLen < 2) return [0, 0];
|
|
3368
3369
|
let startByte = 0;
|
|
3369
3370
|
let bestLen = 0;
|
|
3370
|
-
let
|
|
3371
|
-
for (let i = 0; i < 256; i++,
|
|
3371
|
+
let baseIndex = offset;
|
|
3372
|
+
for (let i = 0; i < 256; i++, baseIndex = baseIndex + 1 & 255) {
|
|
3372
3373
|
let size = 0;
|
|
3373
|
-
let
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3374
|
+
let currentIndex = baseIndex;
|
|
3375
|
+
let sourceIndex = srcIx;
|
|
3376
|
+
let isEnd = false;
|
|
3377
|
+
while (size < maxLen) {
|
|
3378
|
+
if (isEnd) {
|
|
3379
|
+
if (srcData[sourceIndex++] !== srcData[srcIx + size]) break;
|
|
3380
|
+
} else if (dictionary[currentIndex] !== srcData[sourceIndex++]) break;
|
|
3381
|
+
else {
|
|
3382
|
+
currentIndex = currentIndex + 1 & 255;
|
|
3383
|
+
if (currentIndex === offset) {
|
|
3384
|
+
sourceIndex = srcIx;
|
|
3385
|
+
isEnd = true;
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3377
3388
|
size++;
|
|
3378
3389
|
}
|
|
3379
3390
|
if (size > bestLen) {
|
|
3380
|
-
startByte =
|
|
3391
|
+
startByte = baseIndex;
|
|
3381
3392
|
bestLen = size;
|
|
3382
3393
|
if (bestLen >= maxLen) break;
|
|
3383
3394
|
}
|
|
3384
3395
|
}
|
|
3385
3396
|
return [startByte, bestLen];
|
|
3386
3397
|
};
|
|
3387
|
-
while (srcIx <
|
|
3398
|
+
while (srcIx < endIx) {
|
|
3388
3399
|
const [cmdStart, cmdLen] = getCommand();
|
|
3389
3400
|
if (cmdLen >= 2) {
|
|
3390
3401
|
bitStream.writeBit(false);
|
|
@@ -4431,6 +4442,7 @@ var BlockReader = class {
|
|
|
4431
4442
|
* Resolves a single object and its references
|
|
4432
4443
|
*/
|
|
4433
4444
|
resolveObject(obj, isBranch) {
|
|
4445
|
+
if (obj === void 0 || obj === null) return;
|
|
4434
4446
|
if (typeof obj === "string") return;
|
|
4435
4447
|
if (Array.isArray(obj)) {
|
|
4436
4448
|
for (const o of obj) this.resolveObject(o, isBranch);
|
|
@@ -4448,7 +4460,15 @@ var BlockReader = class {
|
|
|
4448
4460
|
this.resolveInclude(obj.location, isBranch);
|
|
4449
4461
|
return;
|
|
4450
4462
|
}
|
|
4451
|
-
if (obj
|
|
4463
|
+
if (obj instanceof TableEntry) {
|
|
4464
|
+
this.resolveObject(obj.object, isBranch);
|
|
4465
|
+
return;
|
|
4466
|
+
}
|
|
4467
|
+
if (obj instanceof Op) {
|
|
4468
|
+
this.resolveOperationObject(obj);
|
|
4469
|
+
return;
|
|
4470
|
+
}
|
|
4471
|
+
if (typeof obj === "object") {
|
|
4452
4472
|
if ("string" in obj && "type" in obj) {
|
|
4453
4473
|
this._stringReader.resolveString(obj, isBranch);
|
|
4454
4474
|
return;
|
|
@@ -4457,14 +4477,6 @@ var BlockReader = class {
|
|
|
4457
4477
|
this.resolveObject(obj.parts, isBranch);
|
|
4458
4478
|
return;
|
|
4459
4479
|
}
|
|
4460
|
-
if ("location" in obj && "object" in obj) {
|
|
4461
|
-
this.resolveObject(obj.object, isBranch);
|
|
4462
|
-
return;
|
|
4463
|
-
}
|
|
4464
|
-
if ("code" in obj && "operands" in obj) {
|
|
4465
|
-
this.resolveOperationObject(obj);
|
|
4466
|
-
return;
|
|
4467
|
-
}
|
|
4468
4480
|
}
|
|
4469
4481
|
}
|
|
4470
4482
|
/**
|
|
@@ -4574,8 +4586,9 @@ var RomLayout = class RomLayout {
|
|
|
4574
4586
|
this.sfxFiles.unshift(newFile);
|
|
4575
4587
|
file.rawData = file.rawData.slice(0, end);
|
|
4576
4588
|
file.size -= offset;
|
|
4589
|
+
offset = 0;
|
|
4577
4590
|
}
|
|
4578
|
-
remain =
|
|
4591
|
+
remain = RomProcessingConstants.PAGE_SIZE;
|
|
4579
4592
|
break;
|
|
4580
4593
|
} else remain -= file.size;
|
|
4581
4594
|
}
|
|
@@ -4688,7 +4701,7 @@ var RomProcessor = class RomProcessor {
|
|
|
4688
4701
|
asmFiles.push(file);
|
|
4689
4702
|
conditionFiles.push(file.name);
|
|
4690
4703
|
}
|
|
4691
|
-
for (const file of asmFiles)
|
|
4704
|
+
for (const file of asmFiles) {
|
|
4692
4705
|
const { blocks, includes, reqBank } = new Assembler(this.writer.root, file.textData, conditionFiles).parseAssembly();
|
|
4693
4706
|
file.parts = blocks;
|
|
4694
4707
|
file.includes = includes;
|
|
@@ -4937,7 +4950,7 @@ var RomWriter = class {
|
|
|
4937
4950
|
while (true) if (Array.isArray(currentObj)) {
|
|
4938
4951
|
for (const obj of currentObj) processObject(obj, parentOp);
|
|
4939
4952
|
break;
|
|
4940
|
-
} else if (
|
|
4953
|
+
} else if (currentObj instanceof TableEntry) {
|
|
4941
4954
|
currentObj = currentObj.object;
|
|
4942
4955
|
continue;
|
|
4943
4956
|
} else if (currentObj instanceof Op) {
|
|
@@ -5257,6 +5270,7 @@ var DbRootUtils = class {
|
|
|
5257
5270
|
return acc;
|
|
5258
5271
|
}, {});
|
|
5259
5272
|
const extLookup = {};
|
|
5273
|
+
const fileTypeLookup = {};
|
|
5260
5274
|
const fileTypes = Object.entries(module.fileTypes).reduce((acc, x) => {
|
|
5261
5275
|
const fileType = x[1];
|
|
5262
5276
|
const name = x[0];
|
|
@@ -5265,11 +5279,35 @@ var DbRootUtils = class {
|
|
|
5265
5279
|
name
|
|
5266
5280
|
});
|
|
5267
5281
|
extLookup[type.extension] = type;
|
|
5282
|
+
fileTypeLookup[type.type] = type;
|
|
5268
5283
|
acc[name] = type;
|
|
5269
5284
|
return acc;
|
|
5270
5285
|
}, {});
|
|
5271
5286
|
const cfg = module.config;
|
|
5272
5287
|
const compression = cfg.compression ? CompressionAlgorithms[cfg.compression]() : void 0;
|
|
5288
|
+
const baseRomChunks = module.baseRomFiles ?? module.supaBaseRomFiles?.map((file) => {
|
|
5289
|
+
const chunkFile = new ChunkFile(file.name, 0, 0, fileTypeLookup[file.type]);
|
|
5290
|
+
if (file.isText) {
|
|
5291
|
+
chunkFile.textData = file.text ?? void 0;
|
|
5292
|
+
chunkFile.size = file.text?.length ?? 0;
|
|
5293
|
+
} else {
|
|
5294
|
+
chunkFile.rawData = file.data;
|
|
5295
|
+
chunkFile.size = file.data?.length ?? 0;
|
|
5296
|
+
}
|
|
5297
|
+
return chunkFile;
|
|
5298
|
+
});
|
|
5299
|
+
const projectChunks = module.projectFiles ?? module.supaProjectFiles?.map((file) => {
|
|
5300
|
+
const chunkFile = new ChunkFile(file.name, 0, 0, fileTypeLookup[file.type]);
|
|
5301
|
+
chunkFile.group = file.module ?? void 0;
|
|
5302
|
+
if (file.isText) {
|
|
5303
|
+
chunkFile.textData = file.text ?? void 0;
|
|
5304
|
+
chunkFile.size = file.text?.length ?? 0;
|
|
5305
|
+
} else {
|
|
5306
|
+
chunkFile.rawData = file.data;
|
|
5307
|
+
chunkFile.size = file.data?.length ?? 0;
|
|
5308
|
+
}
|
|
5309
|
+
return chunkFile;
|
|
5310
|
+
});
|
|
5273
5311
|
return {
|
|
5274
5312
|
headers: module.headers.map((h) => new DbHeader(h)),
|
|
5275
5313
|
mnemonics: module.mnemonics,
|
|
@@ -5298,7 +5336,9 @@ var DbRootUtils = class {
|
|
|
5298
5336
|
stringDelimiterLookup,
|
|
5299
5337
|
compression,
|
|
5300
5338
|
groups: groupLookup,
|
|
5301
|
-
scenes: sceneLookup
|
|
5339
|
+
scenes: sceneLookup,
|
|
5340
|
+
baseRomFiles: baseRomChunks,
|
|
5341
|
+
projectFiles: projectChunks
|
|
5302
5342
|
};
|
|
5303
5343
|
}
|
|
5304
5344
|
static async applyFolder(root, folderPath, sourceFiles = []) {
|
|
@@ -5597,9 +5637,17 @@ var StringProcessor = class {
|
|
|
5597
5637
|
const cmdLookup = stringType.commands;
|
|
5598
5638
|
let currentLayer = stringType.layers[0];
|
|
5599
5639
|
let lastCmd = null;
|
|
5640
|
+
let fullMatch = false;
|
|
5600
5641
|
for (const entry of dictionary) {
|
|
5601
5642
|
let index;
|
|
5602
|
-
while ((index = str.indexOf(entry.text)) >= 0)
|
|
5643
|
+
while ((index = str.indexOf(entry.text)) >= 0) {
|
|
5644
|
+
if (index === 0 && str.length === entry.text.length) {
|
|
5645
|
+
fullMatch = true;
|
|
5646
|
+
break;
|
|
5647
|
+
}
|
|
5648
|
+
str = str.substring(0, index) + `[${entry.id.toString(16).toUpperCase()}]` + str.substring(index + entry.text.length);
|
|
5649
|
+
}
|
|
5650
|
+
if (fullMatch) break;
|
|
5603
5651
|
}
|
|
5604
5652
|
for (let x = 0; x < str.length; x++) {
|
|
5605
5653
|
const c = str[x];
|
|
@@ -6822,7 +6870,7 @@ async function fromSupabaseByProject(projectName, branchId) {
|
|
|
6822
6870
|
});
|
|
6823
6871
|
const baseRomBranch = branchData.baseRomBranch;
|
|
6824
6872
|
const projectFiles = await loadProjectFiles(branchData.id);
|
|
6825
|
-
await loadBaseRomFiles(baseRomBranch.id);
|
|
6873
|
+
const baseRomFiles = await loadBaseRomFiles(baseRomBranch.id);
|
|
6826
6874
|
fileQueryTime = performance.now() - branchStart - branchQueryTime;
|
|
6827
6875
|
const totalTime = performance.now() - startTime;
|
|
6828
6876
|
const stats = {
|
|
@@ -6833,6 +6881,8 @@ async function fromSupabaseByProject(projectName, branchId) {
|
|
|
6833
6881
|
};
|
|
6834
6882
|
console.log("Project ROM load stats:", stats);
|
|
6835
6883
|
return {
|
|
6884
|
+
supaProjectFiles: projectFiles,
|
|
6885
|
+
supaBaseRomFiles: baseRomFiles,
|
|
6836
6886
|
mnemonics: baseRomBranch.gameRomBranch.mnemonics,
|
|
6837
6887
|
overrides: baseRomBranch.gameRomBranch.overrides,
|
|
6838
6888
|
rewrites: baseRomBranch.gameRomBranch.rewrites,
|
|
@@ -7142,16 +7192,15 @@ var RomGenerator = class {
|
|
|
7142
7192
|
sourceData = new Uint8Array();
|
|
7143
7193
|
constructor(projectName, crc) {
|
|
7144
7194
|
this.projectName = projectName;
|
|
7145
|
-
this.crc = crc
|
|
7195
|
+
this.crc = crc;
|
|
7146
7196
|
}
|
|
7147
7197
|
async validateAndDownload(sourceData) {
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
return false;
|
|
7198
|
+
const calc = crc32_buffer(sourceData);
|
|
7199
|
+
if (this.crc !== calc) return false;
|
|
7200
|
+
const moduleData = await fromSupabaseByProject(this.projectName);
|
|
7201
|
+
this.dbRoot = DbRootUtils.fromGameModule(moduleData);
|
|
7202
|
+
this.sourceData = sourceData;
|
|
7203
|
+
return true;
|
|
7155
7204
|
}
|
|
7156
7205
|
async generateProject(modules, manualFiles, unshiftManualFiles = false) {
|
|
7157
7206
|
if (!this.dbRoot) throw new Error("Database not initialized");
|