@gaialabs/core 0.1.5 → 0.1.7

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.d.mts CHANGED
@@ -763,29 +763,19 @@ declare class AssemblerState {
763
763
  }
764
764
 
765
765
  declare class RomGenerator {
766
- private readonly moduleLookup;
767
- private readonly moduleList;
768
- private readonly sourceData;
769
- private readonly patchFiles;
770
- private chunkFiles;
771
- private asmFiles;
772
- private dbRoot;
773
- constructor(modules: string[], sourceData: Uint8Array);
774
- generateProject(projectName: string): Promise<Uint8Array>;
775
- private initializeDatabase;
776
- private initializeChunks;
777
- private writeScriptTexts;
778
- private applyBaseRom;
766
+ readonly projectName?: string;
767
+ crc: number;
768
+ branchId: string;
769
+ dbRoot: DbRoot;
770
+ private sourceData;
771
+ constructor(projectName?: string);
772
+ initialize(): Promise<void>;
773
+ validateAndDownload(sourceData: Uint8Array): Promise<boolean>;
774
+ generateProject(modules: string[], manualFiles?: ChunkFile[]): Promise<Uint8Array>;
779
775
  private applyProjectInit;
780
- private applySelectedModules;
781
776
  private assembleCodeFromText;
782
- private applyCodePatches;
783
- private calculateSizes;
784
- private performLayout;
785
- private rebaseAssemblies;
786
777
  private generateAsmIncludeLookups;
787
- applyPatchFile(chunkFile: ChunkFile): void;
788
- private generateBlockLookup;
778
+ applyPatchFile(chunkFile: ChunkFile, chunkFiles: ChunkFile[], asmFiles: ChunkFile[], patchFiles: ChunkFile[]): void;
789
779
  private writeRom;
790
780
  }
791
781
 
@@ -875,7 +865,7 @@ declare class SpriteMap {
875
865
  * - Compression: QuintetLZ compression algorithm
876
866
  * - Sprites: Sprite animation system
877
867
  */
878
- declare const GAIA_CORE_VERSION = "0.1.5";
868
+ declare const GAIA_CORE_VERSION = "0.1.6";
879
869
  declare const isPlatformBrowser: boolean;
880
870
  declare const isPlatformNode: string | false;
881
871
  declare const isPlatformWebWorker: boolean;
package/dist/index.d.ts CHANGED
@@ -763,29 +763,19 @@ declare class AssemblerState {
763
763
  }
764
764
 
765
765
  declare class RomGenerator {
766
- private readonly moduleLookup;
767
- private readonly moduleList;
768
- private readonly sourceData;
769
- private readonly patchFiles;
770
- private chunkFiles;
771
- private asmFiles;
772
- private dbRoot;
773
- constructor(modules: string[], sourceData: Uint8Array);
774
- generateProject(projectName: string): Promise<Uint8Array>;
775
- private initializeDatabase;
776
- private initializeChunks;
777
- private writeScriptTexts;
778
- private applyBaseRom;
766
+ readonly projectName?: string;
767
+ crc: number;
768
+ branchId: string;
769
+ dbRoot: DbRoot;
770
+ private sourceData;
771
+ constructor(projectName?: string);
772
+ initialize(): Promise<void>;
773
+ validateAndDownload(sourceData: Uint8Array): Promise<boolean>;
774
+ generateProject(modules: string[], manualFiles?: ChunkFile[]): Promise<Uint8Array>;
779
775
  private applyProjectInit;
780
- private applySelectedModules;
781
776
  private assembleCodeFromText;
782
- private applyCodePatches;
783
- private calculateSizes;
784
- private performLayout;
785
- private rebaseAssemblies;
786
777
  private generateAsmIncludeLookups;
787
- applyPatchFile(chunkFile: ChunkFile): void;
788
- private generateBlockLookup;
778
+ applyPatchFile(chunkFile: ChunkFile, chunkFiles: ChunkFile[], asmFiles: ChunkFile[], patchFiles: ChunkFile[]): void;
789
779
  private writeRom;
790
780
  }
791
781
 
@@ -875,7 +865,7 @@ declare class SpriteMap {
875
865
  * - Compression: QuintetLZ compression algorithm
876
866
  * - Sprites: Sprite animation system
877
867
  */
878
- declare const GAIA_CORE_VERSION = "0.1.5";
868
+ declare const GAIA_CORE_VERSION = "0.1.6";
879
869
  declare const isPlatformBrowser: boolean;
880
870
  declare const isPlatformNode: string | false;
881
871
  declare const isPlatformWebWorker: boolean;
package/dist/index.js CHANGED
@@ -3660,88 +3660,72 @@ var Assembler = class {
3660
3660
  }
3661
3661
  };
3662
3662
  var RomGenerator = class {
3663
- constructor(modules, sourceData) {
3664
- this.moduleLookup = /* @__PURE__ */ new Map();
3665
- this.moduleList = ["jp-viper", "title-enhanced"];
3666
- this.patchFiles = [];
3667
- this.chunkFiles = [];
3668
- this.asmFiles = [];
3663
+ constructor(projectName) {
3664
+ this.crc = 0;
3665
+ this.branchId = "";
3666
+ //private chunkFiles: ChunkFile[] = [];
3667
+ //private asmFiles: ChunkFile[] = [];
3669
3668
  this.dbRoot = {};
3670
- this.sourceData = sourceData;
3671
- this.moduleList = modules;
3672
- const crc = shared.crc32_buffer(this.sourceData);
3673
- if (crc !== 473450688) {
3674
- throw new Error("CRC mismatch, please provide the correct ROM");
3675
- }
3676
- }
3677
- async generateProject(projectName) {
3678
- await this.initializeDatabase(projectName);
3679
- const reader = this.initializeChunks();
3680
- this.writeScriptTexts(reader);
3681
- this.applyBaseRom();
3682
- this.applyProjectInit();
3683
- this.applySelectedModules();
3684
- this.assembleCodeFromText();
3685
- this.applyCodePatches();
3686
- this.calculateSizes();
3687
- this.performLayout();
3688
- this.rebaseAssemblies();
3689
- this.generateAsmIncludeLookups();
3690
- const blockLookup = this.generateBlockLookup();
3691
- const outRom = await this.writeRom(blockLookup);
3692
- return outRom;
3693
- }
3694
- //Grab structures from supabase
3695
- async initializeDatabase(projectName) {
3696
- this.dbRoot = await shared.DbRootUtils.fromSupabaseProject({ projectName });
3669
+ this.sourceData = new Uint8Array();
3670
+ this.projectName = projectName;
3671
+ }
3672
+ async initialize() {
3673
+ var projectData = await shared.summaryFromSupabaseByProject(this.projectName);
3674
+ this.crc = projectData.project.baseRom.gameRom.crc;
3675
+ this.branchId = projectData.id;
3676
+ }
3677
+ async validateAndDownload(sourceData) {
3678
+ const calc = shared.crc32_buffer(sourceData);
3679
+ if (calc === this.crc) {
3680
+ this.dbRoot = await shared.DbRootUtils.fromSupabaseProject(this.projectName, this.branchId);
3681
+ this.sourceData = sourceData;
3682
+ return true;
3683
+ }
3684
+ return false;
3697
3685
  }
3698
- //Read graph from rom
3699
- initializeChunks() {
3686
+ async generateProject(modules, manualFiles) {
3687
+ if (!this.dbRoot) throw new Error("Database not initialized");
3688
+ if (!this.sourceData) throw new Error("Source data not initialized");
3700
3689
  const reader = new BlockReader(this.sourceData, this.dbRoot);
3701
- this.chunkFiles = reader.analyzeAndResolve();
3702
- this.asmFiles = this.chunkFiles.filter((b) => b.type === shared.BinType.Assembly);
3703
- return reader;
3704
- }
3705
- //Convert blocks to text
3706
- writeScriptTexts(reader) {
3690
+ const chunkFiles = reader.analyzeAndResolve();
3691
+ const asmFiles = chunkFiles.filter((b) => b.type === shared.BinType.Assembly);
3692
+ const patchFiles = [];
3707
3693
  const writer = new BlockWriter(reader);
3708
- for (const block of this.asmFiles) {
3709
- block.textData = writer.generateAsm(block);
3710
- }
3711
- }
3712
- //Apply base rom files
3713
- applyBaseRom() {
3714
- for (const chunkFile of this.dbRoot.baseRomFiles) {
3715
- this.applyPatchFile(chunkFile);
3716
- }
3694
+ for (const block of asmFiles) block.textData = writer.generateAsm(block);
3695
+ for (const chunkFile of this.dbRoot.baseRomFiles) this.applyPatchFile(chunkFile, chunkFiles, asmFiles, patchFiles);
3696
+ const moduleLookup = this.applyProjectInit(chunkFiles, asmFiles, patchFiles);
3697
+ for (const module of modules) {
3698
+ for (const file of moduleLookup.get(module)) this.applyPatchFile(file, chunkFiles, asmFiles, patchFiles);
3699
+ }
3700
+ for (const file of manualFiles ?? []) this.applyPatchFile(file, chunkFiles, asmFiles, patchFiles);
3701
+ this.assembleCodeFromText(asmFiles);
3702
+ RomProcessor.applyPatches(asmFiles, patchFiles);
3703
+ for (const asm of asmFiles) shared.ChunkFileUtils.calculateSize(asm);
3704
+ const layout = new RomLayout(chunkFiles);
3705
+ layout.organize();
3706
+ for (const file of asmFiles) shared.ChunkFileUtils.rebase(file);
3707
+ this.generateAsmIncludeLookups(asmFiles);
3708
+ const blockLookup = /* @__PURE__ */ new Map();
3709
+ for (const f of chunkFiles) blockLookup.set(f.name.toUpperCase(), f.location);
3710
+ const outRom = await this.writeRom(blockLookup, this.dbRoot.entryPoints, chunkFiles, asmFiles);
3711
+ return outRom;
3717
3712
  }
3718
- applyProjectInit() {
3713
+ applyProjectInit(chunkFiles, asmFiles, patchFiles) {
3714
+ const moduleLookup = /* @__PURE__ */ new Map();
3719
3715
  for (const chunkFile of this.dbRoot.projectFiles) {
3720
3716
  console.log(`Processing patch: ${chunkFile.name}`);
3721
3717
  if (chunkFile.group) {
3722
3718
  let modArray;
3723
- if (!this.moduleLookup.has(chunkFile.group)) {
3724
- this.moduleLookup.set(chunkFile.group, modArray = []);
3725
- } else {
3726
- modArray = this.moduleLookup.get(chunkFile.group);
3727
- }
3719
+ if (!moduleLookup.has(chunkFile.group)) moduleLookup.set(chunkFile.group, modArray = []);
3720
+ else modArray = moduleLookup.get(chunkFile.group);
3728
3721
  modArray.push(chunkFile);
3729
- } else {
3730
- this.applyPatchFile(chunkFile);
3731
- }
3732
- }
3733
- }
3734
- //Apply selected project modules
3735
- applySelectedModules() {
3736
- for (const module of this.moduleList) {
3737
- for (const file of this.moduleLookup.get(module)) {
3738
- this.applyPatchFile(file);
3739
- }
3722
+ } else this.applyPatchFile(chunkFile, chunkFiles, asmFiles, patchFiles);
3740
3723
  }
3724
+ return moduleLookup;
3741
3725
  }
3742
3726
  //Assemble code from script text
3743
- assembleCodeFromText() {
3744
- for (const block of this.asmFiles) {
3727
+ assembleCodeFromText(asmFiles) {
3728
+ for (const block of asmFiles) {
3745
3729
  const assembler = new Assembler(this.dbRoot, block.textData);
3746
3730
  const { blocks, includes, reqBank } = assembler.parseAssembly();
3747
3731
  block.parts = blocks;
@@ -3749,31 +3733,10 @@ var RomGenerator = class {
3749
3733
  block.bank = reqBank ?? void 0;
3750
3734
  }
3751
3735
  }
3752
- //Apply patches
3753
- applyCodePatches() {
3754
- RomProcessor.applyPatches(this.asmFiles, this.patchFiles);
3755
- }
3756
- //Calculate sizes
3757
- calculateSizes() {
3758
- for (const asm of this.chunkFiles) {
3759
- shared.ChunkFileUtils.calculateSize(asm);
3760
- }
3761
- }
3762
- // Assign locations
3763
- performLayout() {
3764
- const layout = new RomLayout(this.chunkFiles);
3765
- layout.organize();
3766
- }
3767
- // Rebase assemblies
3768
- rebaseAssemblies() {
3769
- for (const file of this.asmFiles) {
3770
- shared.ChunkFileUtils.rebase(file);
3771
- }
3772
- }
3773
3736
  // Build include lookup map per asm file
3774
- generateAsmIncludeLookups() {
3775
- for (const f of this.asmFiles) {
3776
- const includeBlocks = this.asmFiles.filter((x) => f.includes?.has(x.name.toUpperCase())).flatMap((x) => x.parts).filter((b) => !!b.label);
3737
+ generateAsmIncludeLookups(asmFiles) {
3738
+ for (const f of asmFiles) {
3739
+ const includeBlocks = asmFiles.filter((x) => f.includes?.has(x.name.toUpperCase())).flatMap((x) => x.parts).filter((b) => !!b.label);
3777
3740
  f.includeLookup = /* @__PURE__ */ new Map();
3778
3741
  for (const b of includeBlocks) {
3779
3742
  if (b.label) f.includeLookup.set(b.label.toUpperCase(), b);
@@ -3783,43 +3746,33 @@ var RomGenerator = class {
3783
3746
  }
3784
3747
  }
3785
3748
  }
3786
- applyPatchFile(chunkFile) {
3749
+ applyPatchFile(chunkFile, chunkFiles, asmFiles, patchFiles) {
3787
3750
  console.log(`Processing patch: ${chunkFile.name}`);
3788
- const existing = this.chunkFiles.find((x) => x.name === chunkFile.name);
3751
+ const existing = chunkFiles.find((x) => x.name === chunkFile.name);
3789
3752
  if (chunkFile.type === shared.BinType.Patch || chunkFile.type === shared.BinType.Assembly) {
3790
3753
  if (existing) {
3791
3754
  existing.textData = chunkFile.textData;
3792
3755
  } else {
3793
3756
  if (chunkFile.type === shared.BinType.Patch) {
3794
- this.patchFiles.push(chunkFile);
3757
+ patchFiles.push(chunkFile);
3795
3758
  }
3796
- this.asmFiles.push(chunkFile);
3797
- this.chunkFiles.push(chunkFile);
3759
+ asmFiles.push(chunkFile);
3760
+ chunkFiles.push(chunkFile);
3798
3761
  }
3799
3762
  } else {
3800
3763
  if (existing) {
3801
3764
  existing.rawData = chunkFile.rawData;
3802
3765
  existing.size = chunkFile.size;
3803
3766
  } else {
3804
- this.chunkFiles.push(chunkFile);
3767
+ chunkFiles.push(chunkFile);
3805
3768
  }
3806
3769
  }
3807
3770
  }
3808
- // Create block lookup for resolving labels to locations
3809
- generateBlockLookup() {
3810
- const blockLookup = /* @__PURE__ */ new Map();
3811
- for (const f of this.chunkFiles) {
3812
- blockLookup.set(f.name.toUpperCase(), f.location);
3813
- }
3814
- return blockLookup;
3815
- }
3816
- async writeRom(blockLookup) {
3817
- const romWriter = new RomWriter(this.dbRoot.entryPoints, "GAIALABS", "01JG ");
3818
- for (const file of this.chunkFiles) {
3819
- await romWriter.writeFile(file, blockLookup);
3820
- }
3771
+ async writeRom(blockLookup, entryPoints, chunkFiles, asmFiles) {
3772
+ const romWriter = new RomWriter(entryPoints, "GAIALABS", "01JG ");
3773
+ for (const file of chunkFiles) await romWriter.writeFile(file, blockLookup);
3821
3774
  romWriter.writeHeader();
3822
- romWriter.writeEntryPoints(this.asmFiles);
3775
+ romWriter.writeEntryPoints(asmFiles);
3823
3776
  romWriter.writeChecksum();
3824
3777
  return romWriter.outBuffer;
3825
3778
  }
@@ -4024,7 +3977,7 @@ var SpriteMap = class _SpriteMap {
4024
3977
  };
4025
3978
 
4026
3979
  // src/index.ts
4027
- var GAIA_CORE_VERSION = "0.1.5";
3980
+ var GAIA_CORE_VERSION = "0.1.6";
4028
3981
  var isPlatformBrowser = typeof window !== "undefined";
4029
3982
  var isPlatformNode = typeof process !== "undefined" && process.versions?.node;
4030
3983
  var isPlatformWebWorker = typeof importScripts !== "undefined";