Skip to content

Commit

Permalink
closes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 15, 2024
1 parent 0ac5c38 commit b979c7d
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/app/shared/components/input-quest/input-quest.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="relative">
<ng-select class="form-control" [items]="values()" [(ngModel)]="quest" placeholder="Select quest..."
(change)="change.emit($event?.value)" [compareWith]="itemCompare" [searchFn]="search">

<ng-template ng-label-tmp let-item="item">
<div class="relative">
<div class="text-white">
{{ item.value }}
</div>
</div>
</ng-template>

<ng-template ng-option-tmp let-item="item">
<div class="relative">
<div class="text-white">
{{ item.value }}
</div>

<p class="text-white text-sm italic whitespace-break-spaces">{{ item.desc }}</p>
</div>
</ng-template>
</ng-select>

<app-input-floating-label>{{ label() }}</app-input-floating-label>
</div>
Empty file.
55 changes: 55 additions & 0 deletions src/app/shared/components/input-quest/input-quest.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
Component,
computed,
inject,
input,
model,
OnInit,
output,
} from '@angular/core';
import { IQuest } from '../../../../interfaces';
import { ModService } from '../../../services/mod.service';

@Component({
selector: 'app-input-quest',
templateUrl: './input-quest.component.html',
styleUrl: './input-quest.component.scss',
})
export class InputQuestComponent implements OnInit {
private modService = inject(ModService);

public quest = model<IQuest | undefined>();
public defaultValue = input<string>();
public label = input<string>('Quest');
public change = output<string>();

public values = computed(() => {
const mod = this.modService.mod();

return [
...mod.quests.map((q) => ({
value: q.name,
desc: `[${q.giver}] ${q.desc}`,
})),
];
});

ngOnInit() {
const defaultItem = this.defaultValue();
if (defaultItem) {
const foundItem = this.values().find((i) => i.value === defaultItem);
this.quest.set(foundItem as unknown as IQuest);
}
}

public itemCompare(
itemA: { value: string; desc: string },
itemB: { value: string; desc: string }
): boolean {
return itemA.value === itemB.value;
}

public search(term: string, item: { value: string }) {
return item.value.toLowerCase().includes(term.toLowerCase());
}
}
3 changes: 3 additions & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { InputQuestrewardComponent } from './components/input-questreward/input-
import { InputMapnpcComponent } from './components/input-mapnpc/input-mapnpc.component';
import { SpriteWithInlineNameComponent } from './components/sprite-with-inline-name/sprite-with-inline-name.component';
import { InputRecipeComponent } from './components/input-recipe/input-recipe.component';
import { InputQuestComponent } from './components/input-quest/input-quest.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -86,6 +87,7 @@ import { InputRecipeComponent } from './components/input-recipe/input-recipe.com
InputMapnpcComponent,
SpriteWithInlineNameComponent,
InputRecipeComponent,
InputQuestComponent,
],
imports: [
CommonModule,
Expand Down Expand Up @@ -135,6 +137,7 @@ import { InputRecipeComponent } from './components/input-recipe/input-recipe.com
InputMapnpcComponent,
SpriteWithInlineNameComponent,
InputRecipeComponent,
InputQuestComponent,
],
})
export class SharedModule {}
5 changes: 5 additions & 0 deletions src/app/tabs/items/items-editor/items-editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,11 @@
<input [(ngModel)]="editingData.requirements!.level" type="number" min="0" placeholder="Enter required level..."
class="form-input" />
</div>

<div class="form-row">
<app-input-quest (change)="editingData.requirements!.quest = $event"
[defaultValue]="editingData.requirements!.quest" label="Required Quest"></app-input-quest>
</div>
</div>
</div>
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/tabs/items/items-editor/items-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class ItemsEditorComponent
item.useEffect ??= { name: '', potency: 0, duration: 0 };
item.equipEffect ??= { name: '', potency: 0 };
item.breakEffect ??= { name: '', potency: 0 };
item.requirements ??= { baseClass: undefined, level: 0 };
item.requirements ??= { baseClass: undefined, level: 0, quest: undefined };
item.cosmetic ??= { name: '', isPermanent: false };
item.trait ??= { name: '', level: 0 };
item.randomTrait ??= { name: [], level: { min: 0, max: 0 } };
Expand Down Expand Up @@ -348,7 +348,8 @@ export class ItemsEditorComponent
if (
item.requirements &&
!item.requirements.baseClass &&
!item.requirements.level
!item.requirements.level &&
!item.requirements.quest
) {
delete item.requirements;
}
Expand Down

0 comments on commit b979c7d

Please sign in to comment.