Skip to content

Commit

Permalink
start core work
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 20, 2024
1 parent 1ddba20 commit ef2276d
Show file tree
Hide file tree
Showing 35 changed files with 414 additions and 38 deletions.
8 changes: 8 additions & 0 deletions src/app/helpers/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ICoreContent } from '../../interfaces';
import { id } from './id';

export const defaultCore: () => ICoreContent = () => ({
_id: id(),
name: '',
yaml: '',
});
1 change: 1 addition & 0 deletions src/app/helpers/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function formatMod(modData: IModKit): IModKit {
quests: modData.quests,
recipes: modData.recipes,
spawners: formatSpawners(modData.spawners),
cores: modData.cores,
};

return exported;
Expand Down
10 changes: 7 additions & 3 deletions src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@

} @else {
<div class="root-body">
<div role="tablist" class="tabs tabs-boxed rounded-none">
<div role="tablist" class="tabs tabs-boxed rounded-none flex flex-wrap">

@for(tab of tabOrder; track tab.name; let i = $index) {
<a role="tab" class="tab" [class.tab-disabled]="!electronService.isLoaded()" [class.tab-active]="activeTab() === i"
(click)="changeTab(i)">{{ tab.name
<a role="tab" class="tab flex-1 min-w-[150px]" [class.tab-disabled]="!electronService.isLoaded()"
[class.tab-active]="activeTab() === i" (click)="changeTab(i)">{{ tab.name
}} ({{ tab.count() }})</a>
}

Expand Down Expand Up @@ -118,6 +118,10 @@
<app-quests class="h-full"></app-quests>
}

@case (8) {
<app-cores class="h-full"></app-cores>
}

}
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ export class HomeComponent {
count: computed(() => this.modService.mod().spawners.length),
},
{
name: 'NPC Scripts/Dialogs',
name: 'NPC Scripts',
count: computed(() => this.modService.mod().dialogs.length),
},
{
name: 'Quests',
count: computed(() => this.modService.mod().quests.length),
},
{
name: 'Cores',
count: computed(() => this.modService.mod().cores.length),
},
];

constructor() {
Expand Down
22 changes: 20 additions & 2 deletions src/app/home/home.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { SweetAlert2Module } from '@sweetalert2/ngx-sweetalert2';
import { AgGridModule } from 'ag-grid-angular';
import { NgxFloatUiModule } from 'ngx-float-ui';
import { SharedModule } from '../shared/shared.module';
import { CoresEditorComponent } from '../tabs/cores/cores-editor/cores-editor.component';
import { CoresComponent } from '../tabs/cores/cores.component';
import { DialogsEditorComponent } from '../tabs/dialogs/dialogs-editor/dialogs-editor.component';
import { DialogsComponent } from '../tabs/dialogs/dialogs.component';
import { DroptablesEditorComponent } from '../tabs/droptables/droptables-editor/droptables-editor.component';
Expand All @@ -24,8 +26,12 @@ import { RecipesEditorComponent } from '../tabs/recipes/recipes-editor/recipes-e
import { RecipesComponent } from '../tabs/recipes/recipes.component';
import { SpawnersEditorComponent } from '../tabs/spawners/spawners-editor/spawners-editor.component';
import { SpawnersComponent } from '../tabs/spawners/spawners.component';
import { HomeComponent } from './home.component';
import { StemsEditorComponent } from '../tabs/stems/stems-editor/stems-editor.component';
import { StemsComponent } from '../tabs/stems/stems.component';
import { TraitTreesEditorComponent } from '../tabs/trait-trees/trait-trees-editor/trait-trees-editor.component';
import { TraitTreesComponent } from '../tabs/trait-trees/trait-trees.component';
import { ValidationComponent } from '../validation/validation.component';
import { HomeComponent } from './home.component';

@NgModule({
declarations: [
Expand All @@ -46,6 +52,12 @@ import { ValidationComponent } from '../validation/validation.component';
QuestsEditorComponent,
DialogsEditorComponent,
ValidationComponent,
CoresComponent,
CoresEditorComponent,
TraitTreesComponent,
TraitTreesEditorComponent,
StemsComponent,
StemsEditorComponent,
],
imports: [
CommonModule,
Expand All @@ -58,7 +70,13 @@ import { ValidationComponent } from '../validation/validation.component';
CodeEditorModule,
],
exports: [
ValidationComponent
ValidationComponent,
CoresComponent,
CoresEditorComponent,
TraitTreesComponent,
TraitTreesEditorComponent,
StemsComponent,
StemsEditorComponent,
],
})
export class HomeModule {}
14 changes: 14 additions & 0 deletions src/app/services/mod.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { computed, effect, inject, Injectable, signal } from '@angular/core';
import { isUndefined } from 'lodash';
import { LocalStorageService } from 'ngx-webstorage';
import {
HasIdentification,
Expand Down Expand Up @@ -38,6 +39,7 @@ export function defaultModKit(): IModKit {
quests: [],
recipes: [],
spawners: [],
cores: [],
};
}

Expand All @@ -63,6 +65,7 @@ export class ModService {
const oldModData: IModKit = this.localStorage.retrieve('mod');
if (oldModData) {
ensureIds(oldModData);
this.migrateMod(oldModData);
this.updateMod(oldModData);
}

Expand All @@ -79,6 +82,17 @@ export class ModService {
}

// mod functions
private migrateMod(mod: IModKit) {
const check = defaultModKit();
Object.keys(check).forEach((checkKeyString) => {
const checkKey = checkKeyString as keyof IModKit;

if (!isUndefined(mod[checkKey])) return;

mod[checkKey] = structuredClone(check[checkKey]) as unknown as any;
});
}

public resetMod(): void {
this.updateMod(defaultModKit());
}
Expand Down
18 changes: 18 additions & 0 deletions src/app/tabs/cores/cores-editor/cores-editor.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@let editingData = editing();

<div role="tablist" class="tabs tabs-boxed rounded-none mb-3">

<div class="tab flex flex-row justify-end">
<button class="btn-sm btn btn-warning mr-3" (click)="doBack()">Go Back</button>
<button class="btn-sm btn btn-secondary" [disabled]="!canSave()" (click)="doSave()">Save</button>
</div>

</div>

<div class="flex flex-row gap-2">
<div class="form-column">

<div class="form-row">
</div>
</div>
</div>
Empty file.
17 changes: 17 additions & 0 deletions src/app/tabs/cores/cores-editor/cores-editor.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component, computed, signal } from '@angular/core';
import { ICoreContent } from '../../../../interfaces';
import { EditorBaseComponent } from '../../../shared/components/editor-base/editor-base.component';

@Component({
selector: 'app-cores-editor',
templateUrl: './cores-editor.component.html',
styleUrl: './cores-editor.component.scss',
})
export class CoresEditorComponent extends EditorBaseComponent<ICoreContent> {
public currentItem = signal<ICoreContent | undefined>(undefined);

public canSave = computed(() => {
const data = this.editing();
return data.yaml;
});
}
10 changes: 10 additions & 0 deletions src/app/tabs/cores/cores.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@let editing = isEditing();

<app-editor-view-table [class.hidden]="editing" [dataType]="'core content items'" [tableColumns]="tableColumns"
[tableItems]="tableItems()" (create)="createNew()" (filterChanged)="filterChanged($event)"
[defaultFilterState]="tableFilterState()"></app-editor-view-table>

@if(editing) {
<app-cores-editor class="h-full w-full" [editing]="editingData()" (goBack)="cancelEditing()"
(save)="saveNewData($event)"></app-cores-editor>
}
Empty file.
65 changes: 65 additions & 0 deletions src/app/tabs/cores/cores.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Component, computed } from '@angular/core';
import { ColDef } from 'ag-grid-community';

import { ICoreContent, IModKit } from '../../../interfaces';
import { defaultCore } from '../../helpers/core';
import { CellButtonsComponent } from '../../shared/components/cell-buttons/cell-buttons.component';
import { EditorBaseTableComponent } from '../../shared/components/editor-base-table/editor-base-table.component';
import { HeaderButtonsComponent } from '../../shared/components/header-buttons/header-buttons.component';

type EditingType = ICoreContent;

@Component({
selector: 'app-cores',
templateUrl: './cores.component.html',
styleUrl: './cores.component.scss',
})
export class CoresComponent extends EditorBaseTableComponent<EditingType> {
protected dataKey: keyof Omit<IModKit, 'meta'> = 'drops';

public defaultData = defaultCore;

public tableItems = computed(() => this.modService.mod().cores);
public tableColumns: ColDef[] = [
{
field: 'mapName',
flex: 1,
cellDataType: 'text',
filter: 'agTextColumnFilter',
sort: 'asc',
},
{
field: 'regionName',
flex: 1,
cellDataType: 'text',
filter: 'agTextColumnFilter',
sort: 'asc',
},
{
field: 'isGlobal',
flex: 1,
cellDataType: 'boolean',
sort: 'asc',
},
{
field: '',
width: 200,
sortable: false,
suppressMovable: true,
headerComponent: HeaderButtonsComponent,
headerComponentParams: {
showNewButton: true,
newCallback: () => this.createNew(),
},
cellRenderer: CellButtonsComponent,
cellClass: 'no-adjust',
cellRendererParams: {
showCopyButton: false,
showEditButton: true,
editCallback: (item: EditingType) => this.editExisting(item),
showDeleteButton: true,
deleteCallback: (item: EditingType) => this.deleteData(item),
},
},
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>stems-editor works!</p>
Empty file.
10 changes: 10 additions & 0 deletions src/app/tabs/stems/stems-editor/stems-editor.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-stems-editor',
templateUrl: './stems-editor.component.html',
styleUrl: './stems-editor.component.scss'
})
export class StemsEditorComponent {

}
1 change: 1 addition & 0 deletions src/app/tabs/stems/stems.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>stems works!</p>
Empty file.
10 changes: 10 additions & 0 deletions src/app/tabs/stems/stems.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-stems',
templateUrl: './stems.component.html',
styleUrl: './stems.component.scss'
})
export class StemsComponent {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>trait-trees-editor works!</p>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-trait-trees-editor',
templateUrl: './trait-trees-editor.component.html',
styleUrl: './trait-trees-editor.component.scss'
})
export class TraitTreesEditorComponent {

}
1 change: 1 addition & 0 deletions src/app/tabs/trait-trees/trait-trees.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>trait-trees works!</p>
Empty file.
10 changes: 10 additions & 0 deletions src/app/tabs/trait-trees/trait-trees.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-trait-trees',
templateUrl: './trait-trees.component.html',
styleUrl: './trait-trees.component.scss'
})
export class TraitTreesComponent {

}
6 changes: 6 additions & 0 deletions src/interfaces/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { HasIdentification } from './identified';

export interface ICoreContent extends HasIdentification {
name: string;
yaml: string;
}
Loading

0 comments on commit ef2276d

Please sign in to comment.