@gaialabs/core 0.2.7 → 0.2.8

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 CHANGED
@@ -1897,8 +1897,8 @@ var TableEntry = class {
1897
1897
  location;
1898
1898
  object;
1899
1899
  constructor(location) {
1900
- this.location = location ?? void 0;
1901
- if (this.location === void 0) throw new Error("Location is required");
1900
+ if (typeof location !== "number") throw new Error("Location is required");
1901
+ this.location = location;
1902
1902
  }
1903
1903
  };
1904
1904
 
@@ -4431,6 +4431,7 @@ var BlockReader = class {
4431
4431
  * Resolves a single object and its references
4432
4432
  */
4433
4433
  resolveObject(obj, isBranch) {
4434
+ if (obj === void 0 || obj === null) return;
4434
4435
  if (typeof obj === "string") return;
4435
4436
  if (Array.isArray(obj)) {
4436
4437
  for (const o of obj) this.resolveObject(o, isBranch);
@@ -4448,7 +4449,15 @@ var BlockReader = class {
4448
4449
  this.resolveInclude(obj.location, isBranch);
4449
4450
  return;
4450
4451
  }
4451
- if (obj && typeof obj === "object") {
4452
+ if (obj instanceof TableEntry) {
4453
+ this.resolveObject(obj.object, isBranch);
4454
+ return;
4455
+ }
4456
+ if (obj instanceof Op) {
4457
+ this.resolveOperationObject(obj);
4458
+ return;
4459
+ }
4460
+ if (typeof obj === "object") {
4452
4461
  if ("string" in obj && "type" in obj) {
4453
4462
  this._stringReader.resolveString(obj, isBranch);
4454
4463
  return;
@@ -4457,14 +4466,6 @@ var BlockReader = class {
4457
4466
  this.resolveObject(obj.parts, isBranch);
4458
4467
  return;
4459
4468
  }
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
4469
  }
4469
4470
  }
4470
4471
  /**
@@ -4688,7 +4689,7 @@ var RomProcessor = class RomProcessor {
4688
4689
  asmFiles.push(file);
4689
4690
  conditionFiles.push(file.name);
4690
4691
  }
4691
- for (const file of asmFiles) if (!file.parts) {
4692
+ for (const file of asmFiles) {
4692
4693
  const { blocks, includes, reqBank } = new Assembler(this.writer.root, file.textData, conditionFiles).parseAssembly();
4693
4694
  file.parts = blocks;
4694
4695
  file.includes = includes;
@@ -4937,7 +4938,7 @@ var RomWriter = class {
4937
4938
  while (true) if (Array.isArray(currentObj)) {
4938
4939
  for (const obj of currentObj) processObject(obj, parentOp);
4939
4940
  break;
4940
- } else if (this.isTableEntry(currentObj)) {
4941
+ } else if (currentObj instanceof TableEntry) {
4941
4942
  currentObj = currentObj.object;
4942
4943
  continue;
4943
4944
  } else if (currentObj instanceof Op) {
@@ -5257,6 +5258,7 @@ var DbRootUtils = class {
5257
5258
  return acc;
5258
5259
  }, {});
5259
5260
  const extLookup = {};
5261
+ const fileTypeLookup = {};
5260
5262
  const fileTypes = Object.entries(module.fileTypes).reduce((acc, x) => {
5261
5263
  const fileType = x[1];
5262
5264
  const name = x[0];
@@ -5265,11 +5267,35 @@ var DbRootUtils = class {
5265
5267
  name
5266
5268
  });
5267
5269
  extLookup[type.extension] = type;
5270
+ fileTypeLookup[type.type] = type;
5268
5271
  acc[name] = type;
5269
5272
  return acc;
5270
5273
  }, {});
5271
5274
  const cfg = module.config;
5272
5275
  const compression = cfg.compression ? CompressionAlgorithms[cfg.compression]() : void 0;
5276
+ const baseRomChunks = module.baseRomFiles ?? module.supaBaseRomFiles?.map((file) => {
5277
+ const chunkFile = new ChunkFile(file.name, 0, 0, fileTypeLookup[file.type]);
5278
+ if (file.isText) {
5279
+ chunkFile.textData = file.text ?? void 0;
5280
+ chunkFile.size = file.text?.length ?? 0;
5281
+ } else {
5282
+ chunkFile.rawData = file.data;
5283
+ chunkFile.size = file.data?.length ?? 0;
5284
+ }
5285
+ return chunkFile;
5286
+ });
5287
+ const projectChunks = module.projectFiles ?? module.supaProjectFiles?.map((file) => {
5288
+ const chunkFile = new ChunkFile(file.name, 0, 0, fileTypeLookup[file.type]);
5289
+ chunkFile.group = file.module ?? void 0;
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
+ });
5273
5299
  return {
5274
5300
  headers: module.headers.map((h) => new DbHeader(h)),
5275
5301
  mnemonics: module.mnemonics,
@@ -5298,7 +5324,9 @@ var DbRootUtils = class {
5298
5324
  stringDelimiterLookup,
5299
5325
  compression,
5300
5326
  groups: groupLookup,
5301
- scenes: sceneLookup
5327
+ scenes: sceneLookup,
5328
+ baseRomFiles: baseRomChunks,
5329
+ projectFiles: projectChunks
5302
5330
  };
5303
5331
  }
5304
5332
  static async applyFolder(root, folderPath, sourceFiles = []) {
@@ -6822,7 +6850,7 @@ async function fromSupabaseByProject(projectName, branchId) {
6822
6850
  });
6823
6851
  const baseRomBranch = branchData.baseRomBranch;
6824
6852
  const projectFiles = await loadProjectFiles(branchData.id);
6825
- await loadBaseRomFiles(baseRomBranch.id);
6853
+ const baseRomFiles = await loadBaseRomFiles(baseRomBranch.id);
6826
6854
  fileQueryTime = performance.now() - branchStart - branchQueryTime;
6827
6855
  const totalTime = performance.now() - startTime;
6828
6856
  const stats = {
@@ -6833,6 +6861,8 @@ async function fromSupabaseByProject(projectName, branchId) {
6833
6861
  };
6834
6862
  console.log("Project ROM load stats:", stats);
6835
6863
  return {
6864
+ supaProjectFiles: projectFiles,
6865
+ supaBaseRomFiles: baseRomFiles,
6836
6866
  mnemonics: baseRomBranch.gameRomBranch.mnemonics,
6837
6867
  overrides: baseRomBranch.gameRomBranch.overrides,
6838
6868
  rewrites: baseRomBranch.gameRomBranch.rewrites,
@@ -7142,16 +7172,15 @@ var RomGenerator = class {
7142
7172
  sourceData = new Uint8Array();
7143
7173
  constructor(projectName, crc) {
7144
7174
  this.projectName = projectName;
7145
- this.crc = crc ?? 0;
7175
+ this.crc = crc;
7146
7176
  }
7147
7177
  async validateAndDownload(sourceData) {
7148
- if (crc32_buffer(sourceData) === this.crc) {
7149
- const moduleData = await fromSupabaseByProject(this.projectName);
7150
- this.dbRoot = DbRootUtils.fromGameModule(moduleData);
7151
- this.sourceData = sourceData;
7152
- return true;
7153
- }
7154
- return false;
7178
+ const calc = crc32_buffer(sourceData);
7179
+ if (this.crc !== calc) return false;
7180
+ const moduleData = await fromSupabaseByProject(this.projectName);
7181
+ this.dbRoot = DbRootUtils.fromGameModule(moduleData);
7182
+ this.sourceData = sourceData;
7183
+ return true;
7155
7184
  }
7156
7185
  async generateProject(modules, manualFiles, unshiftManualFiles = false) {
7157
7186
  if (!this.dbRoot) throw new Error("Database not initialized");