Skip to content

Commit

Permalink
closes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 13, 2024
1 parent 82090df commit 0d63b9a
Show file tree
Hide file tree
Showing 25 changed files with 562 additions and 224 deletions.
1 change: 1 addition & 0 deletions src/app/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export * from './droptable';
export * from './id';
export * from './item';
export * from './npc';
export * from './quest';
export * from './recipe';
export * from './spawner';
37 changes: 37 additions & 0 deletions src/app/helpers/quest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { IQuest } from '../../interfaces';
import { id } from './id';

export const defaultQuest: () => IQuest = () => ({
_id: id(),

name: '',
desc: '',
giver: '',
isDaily: false,
isRepeatable: false,

messages: {
kill: '',
complete: '',
incomplete: '',
alreadyHas: '',
permComplete: '',
},

requirements: {
type: 'none',

npcIds: [],
killsRequired: 0,

item: '',
fromHands: true,
slot: ['rightHand', 'leftHand'],

countRequired: 0,

itemsRequired: 0,
},

rewards: [], // { type, statName, value }
});
4 changes: 3 additions & 1 deletion src/app/home/home.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { RecipesComponent } from '../tabs/recipes/recipes.component';
import { SpawnersComponent } from '../tabs/spawners/spawners.component';
import { HomeComponent } from './home.component';
import { SpawnersEditorComponent } from '../tabs/spawners/spawners-editor/spawners-editor.component';
import { QuestsEditorComponent } from '../tabs/quests/quests-editor/quests-editor.component';

@NgModule({
declarations: [
Expand All @@ -39,6 +40,7 @@ import { SpawnersEditorComponent } from '../tabs/spawners/spawners-editor/spawne
SpawnersComponent,
NpcsEditorComponent,
SpawnersEditorComponent,
QuestsEditorComponent,
],
imports: [
CommonModule,
Expand All @@ -49,6 +51,6 @@ import { SpawnersEditorComponent } from '../tabs/spawners/spawners-editor/spawne
NgxFloatUiModule,
NgIconsModule,
],
exports: [NpcsEditorComponent, SpawnersEditorComponent],
exports: [NpcsEditorComponent, SpawnersEditorComponent, QuestsEditorComponent],
})
export class HomeModule {}
132 changes: 21 additions & 111 deletions src/app/services/mod.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { computed, effect, inject, Injectable, signal } from '@angular/core';
import { LocalStorageService } from 'ngx-webstorage';
import {
IDroptable,
HasIdentification,
IEditorMap,
IItemDefinition,
IModKit,
INPCDefinition,
IRecipe,
ISpawnerData,
} from '../../interfaces';

export function defaultModKit(): IModKit {
Expand Down Expand Up @@ -182,132 +179,45 @@ export class ModService {
this.updateMod(mod);
}

// item functions
public addItem(item: IItemDefinition) {
const mod = this.mod();
mod.items.push(item);

this.updateMod(mod);
}

public editItem(oldItem: IItemDefinition, newItem: IItemDefinition) {
const mod = this.mod();
const foundItemIdx = mod.items.findIndex((i) => i._id === oldItem._id);
if (foundItemIdx === -1) return;

mod.items[foundItemIdx] = newItem;

this.updateMod(mod);
}

public removeItem(item: IItemDefinition) {
const mod = this.mod();
mod.items = mod.items.filter((i) => i._id !== item._id);

this.updateMod(mod);
}

public findItemByName(itemName: string): IItemDefinition | undefined {
const items = this.availableItems();
return items.find((i) => i.name === itemName);
}

// droptable functions
public addDroptable(item: IDroptable) {
public modAdd<T extends HasIdentification>(
key: keyof Omit<IModKit, 'meta'>,
data: T
) {
const mod = this.mod();
mod.drops.push(item);

const arr = mod[key] as unknown as T[];
arr.push(data);
this.updateMod(mod);
}

public editDroptable(oldItem: IDroptable, newItem: IDroptable) {
public modEdit<T extends HasIdentification>(
key: keyof Omit<IModKit, 'meta'>,
oldData: T,
newData: T
) {
const mod = this.mod();
const foundItemIdx = mod.drops.findIndex((i) => i._id === oldItem._id);
if (foundItemIdx === -1) return;

mod.drops[foundItemIdx] = newItem;
const arr = mod[key] as unknown as T[];

this.updateMod(mod);
}

public removeDroptable(item: IDroptable) {
const mod = this.mod();
mod.drops = mod.drops.filter((i) => i._id !== item._id);

this.updateMod(mod);
}

// recipe functions
public addRecipe(item: IRecipe) {
const mod = this.mod();
mod.recipes.push(item);

this.updateMod(mod);
}

public editRecipe(oldItem: IRecipe, newItem: IRecipe) {
const mod = this.mod();
const foundItemIdx = mod.recipes.findIndex((i) => i._id === oldItem._id);
const foundItemIdx = arr.findIndex((i) => i._id === oldData._id);
if (foundItemIdx === -1) return;

mod.recipes[foundItemIdx] = newItem;
arr[foundItemIdx] = newData;

this.updateMod(mod);
}

public removeRecipe(item: IRecipe) {
public modDelete<T extends HasIdentification>(
key: keyof Omit<IModKit, 'meta'>,
data: T
) {
const mod = this.mod();
mod.recipes = mod.recipes.filter((i) => i._id !== item._id);
const arr = mod[key] as unknown as T[];

this.updateMod(mod);
}

// npc functions
public addNPC(npc: INPCDefinition) {
const mod = this.mod();
mod.npcs.push(npc);

this.updateMod(mod);
}

public editNPC(oldNPC: INPCDefinition, newNPC: INPCDefinition) {
const mod = this.mod();
const foundItemIdx = mod.npcs.findIndex((i) => i._id === oldNPC._id);
if (foundItemIdx === -1) return;

mod.npcs[foundItemIdx] = newNPC;

this.updateMod(mod);
}

public removeNPC(npc: INPCDefinition) {
const mod = this.mod();
mod.npcs = mod.npcs.filter((i) => i._id !== npc._id);

this.updateMod(mod);
}

// spawner functions
public addSpawner(spawner: ISpawnerData) {
const mod = this.mod();
mod.spawners.push(spawner);

this.updateMod(mod);
}

public editSpawner(oldSpawner: ISpawnerData, newSpawner: ISpawnerData) {
const mod = this.mod();
const foundItemIdx = mod.npcs.findIndex((i) => i._id === oldSpawner._id);
if (foundItemIdx === -1) return;

mod.spawners[foundItemIdx] = newSpawner;

this.updateMod(mod);
}

public removeSpawner(spawner: ISpawnerData) {
const mod = this.mod();
mod.spawners = mod.spawners.filter((i) => i._id !== spawner._id);
(mod[key] as unknown as T[]) = arr.filter((i) => i._id !== data._id);

this.updateMod(mod);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Component, inject, signal } from '@angular/core';
import { HasIdentification, IModKit } from '../../../../interfaces';
import { ModService } from '../../../services/mod.service';

@Component({
selector: 'app-editor-base-table',
templateUrl: './editor-base-table.component.html',
styleUrl: './editor-base-table.component.scss',
})
export class EditorBaseTableComponent<T> {
export class EditorBaseTableComponent<T extends HasIdentification> {
protected modService = inject(ModService);

protected dataKey!: keyof Omit<IModKit, 'meta'>;

protected defaultData = () => ({} as T);

public isEditing = signal<boolean>(false);
Expand All @@ -30,11 +33,28 @@ export class EditorBaseTableComponent<T> {
this.isEditing.set(false);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public saveNewData(data: T) {
if (!this.dataKey) {
throw new Error('Set a datakey for this component.');
}

this.isEditing.set(false);

const oldItem = this.oldData();
if (oldItem) {
this.oldData.set(undefined);
this.modService.modEdit<T>(this.dataKey, oldItem, data);
return;
}

this.modService.modAdd<T>(this.dataKey, data);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public deleteData(data: T) {}
public deleteData(data: T) {
if (!this.dataKey) {
throw new Error('Set a datakey for this component.');
}

this.modService.modDelete<T>(this.dataKey, data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="relative">
<ng-select class="form-control" [items]="values" [(ngModel)]="rewardType" placeholder="Select quest reward type..."
(change)="change.emit($event)"></ng-select>

<app-input-floating-label>Quest Reward Type</app-input-floating-label>
</div>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component, model, output } from '@angular/core';
import { QuestRewardType, QuestRewardTypeType } from '../../../../interfaces';

@Component({
selector: 'app-input-questreward',
templateUrl: './input-questreward.component.html',
styleUrl: './input-questreward.component.scss',
})
export class InputQuestrewardComponent {
public rewardType = model.required<QuestRewardTypeType | undefined>();
public change = output<QuestRewardTypeType>();

public values = [...Object.values(QuestRewardType).sort()];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="relative">
<ng-select class="form-control" [items]="values" [(ngModel)]="questType" placeholder="Select quest type..."
(change)="change.emit($event)"></ng-select>

<app-input-floating-label>Quest Type</app-input-floating-label>
</div>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component, model, output } from '@angular/core';
import {
QuestRequirementType,
QuestRequirementTypeType,
} from '../../../../interfaces';

@Component({
selector: 'app-input-questtype',
templateUrl: './input-questtype.component.html',
styleUrl: './input-questtype.component.scss',
})
export class InputQuesttypeComponent {
public questType = model.required<QuestRequirementTypeType | undefined>();
public change = output<QuestRequirementTypeType>();

public values = [...Object.values(QuestRequirementType).sort()];
}
6 changes: 6 additions & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { InputChallengeratingComponent } from './components/input-challengeratin
import { InputItemslotComponent } from './components/input-itemslot/input-itemslot.component';
import { InputSfxComponent } from './components/input-sfx/input-sfx.component';
import { InputNpcComponent } from './components/input-npc/input-npc.component';
import { InputQuesttypeComponent } from './components/input-questtype/input-questtype.component';
import { InputQuestrewardComponent } from './components/input-questreward/input-questreward.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -76,6 +78,8 @@ import { InputNpcComponent } from './components/input-npc/input-npc.component';
InputItemslotComponent,
InputSfxComponent,
InputNpcComponent,
InputQuesttypeComponent,
InputQuestrewardComponent,
],
imports: [
CommonModule,
Expand Down Expand Up @@ -120,6 +124,8 @@ import { InputNpcComponent } from './components/input-npc/input-npc.component';
InputItemslotComponent,
InputSfxComponent,
InputNpcComponent,
InputQuesttypeComponent,
InputQuestrewardComponent,
],
})
export class SharedModule {}
Loading

0 comments on commit 0d63b9a

Please sign in to comment.