Skip to content

Commit

Permalink
#18
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 15, 2024
1 parent fc66877 commit 16ab241
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/app/helpers/import/id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IModKit } from '../../../interfaces';
import { id } from '../id';

export function ensureIds(mod: IModKit) {
Object.keys(mod).forEach((modKey) => {
if (modKey === 'meta') return;

mod[modKey as keyof Omit<IModKit, 'meta'>].forEach((data) => {
data._id ??= id();
});
});
}
1 change: 1 addition & 0 deletions src/app/helpers/import/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './id';
14 changes: 14 additions & 0 deletions src/app/helpers/importer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IModKit } from '../../interfaces';
import { ensureIds } from './import';

export function importMod(mod: IModKit): IModKit {
ensureIds(mod);

return mod;
}

export function importExportedMod(mod: IModKit): IModKit {
ensureIds(mod);

return mod;
}
4 changes: 3 additions & 1 deletion src/app/services/electron.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { effect, inject, Injectable, signal } from '@angular/core';

import { IEditorMap, IModKit } from '../../interfaces';
import { importMod } from '../helpers/importer';
import { ModService } from './mod.service';
import { NotifyService } from './notify.service';

Expand Down Expand Up @@ -75,7 +76,8 @@ export class ElectronService {

// import the mod raw from the backup.
window.api.receive('importmod', (mod: IModKit) => {
this.modService.updateMod(mod.meta._backup as IModKit);
const importedMod = importMod(mod.meta._backup as IModKit);
this.modService.updateMod(importedMod);
});

this.send('READY_CHECK');
Expand Down

0 comments on commit 16ab241

Please sign in to comment.