Skip to content

Commit

Permalink
closes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 16, 2024
1 parent 1d5be07 commit eaf03a8
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 13 deletions.
23 changes: 14 additions & 9 deletions src/app/shared/components/input-effect/input-effect.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
Component,
computed,
effect,
inject,
input,
model,
OnInit,
output,
} from '@angular/core';
import { ElectronService } from '../../../services/electron.service';
Expand All @@ -15,7 +15,7 @@ import { ModService } from '../../../services/mod.service';
templateUrl: './input-effect.component.html',
styleUrl: './input-effect.component.scss',
})
export class InputEffectComponent implements OnInit {
export class InputEffectComponent {
private electronService = inject(ElectronService);
private modService = inject(ModService);

Expand Down Expand Up @@ -52,14 +52,19 @@ export class InputEffectComponent implements OnInit {

constructor() {
this.electronService.requestJSON('effect-data');
}

ngOnInit() {
const defaultItem = this.defaultValue();
if (defaultItem) {
const foundItem = this.values().find((i) => i.value === defaultItem);
this.effect.set(foundItem as unknown as string);
}
effect(
() => {
this.modService.json();

const defaultItem = this.defaultValue();
if (defaultItem) {
const foundItem = this.values().find((i) => i.value === defaultItem);
this.effect.set(foundItem as unknown as string);
}
},
{ allowSignalWrites: true }
);
}

public itemCompare(
Expand Down
53 changes: 52 additions & 1 deletion src/app/tabs/items/items-editor/items-editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,58 @@
</div>
}

@if(editingData.useEffect!.name === 'Nourishment') {
<div class="form-row">
<app-input-floating-label>Nourishment Tooltip</app-input-floating-label>
<input [(ngModel)]="editingData.useEffect!.extra!.tooltip" type="text" placeholder="Enter tooltip..."
class="form-input" />
</div>

<div class="form-row">
<app-input-floating-label>Nourishment Message</app-input-floating-label>
<input [(ngModel)]="editingData.useEffect!.extra!.message" type="text" placeholder="Enter message..."
class="form-input" />
</div>

<div class="form-row split">
<div class="form-column">
<div class="form-row">
<app-input-stat [(stat)]="currentNourishmentStat"></app-input-stat>
</div>
</div>

<div class="form-column button-column">
<div class="form-row w-full flex justify-end">
<button class="btn btn-accent btn-sm"
[disabled]="!currentNourishmentStat() || doesItemHaveCurrentNourishmentStat()"
(click)="addNourishmentStat(currentNourishmentStat())">
<ng-icon name="heroPlus"></ng-icon>
</button>
</div>
</div>
</div>

@for(stat of nourishmentStatsInOrder(); track $index) {
<div class="form-row split">
<div class="form-column">
<div class="form-row">
<app-input-floating-label>{{ stat }}</app-input-floating-label>
<input [(ngModel)]="editingData.useEffect!.extra!.statChanges![stat]" type="number"
placeholder="Choose value..." class="form-input" />
</div>
</div>

<div class="form-column">
<div class="form-row w-full flex justify-end">
<button class="ml-1 btn btn-error btn-sm" (click)="removeNourishmentStat(stat)">
<ng-icon name="heroMinus"></ng-icon>
</button>
</div>
</div>
</div>
}
}

<hr class="my-4">

<div class="form-row">
Expand Down Expand Up @@ -572,7 +624,6 @@
}

<div class="form-row split">

<div class="form-column">
<div class="form-row">
<app-input-stat [(stat)]="currentEncrustStat"></app-input-stat>
Expand Down
76 changes: 73 additions & 3 deletions src/app/tabs/items/items-editor/items-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class ItemsEditorComponent
public currentItem = signal<IItemDefinition | undefined>(undefined);
public currentStat = signal<StatType>('agi');
public currentEncrustStat = signal<StatType>('agi');
public currentNourishmentStat = signal<StatType>('agi');
public currentTraitTab = signal<TraitSetting>('none');
public currentTrait = signal<string | undefined>(undefined);
public allStatEdits = signal<StatEdit[]>([]);
Expand Down Expand Up @@ -111,6 +112,11 @@ export class ItemsEditorComponent
return isNumber(this.editing().encrustGive?.stats[current]);
});

public doesItemHaveCurrentNourishmentStat = computed(() => {
const current = this.currentNourishmentStat();
return isNumber(this.editing().useEffect?.extra?.statChanges?.[current]);
});

public statsInOrder = computed(() => {
return sortBy(this.allStatEdits(), 'stat');
});
Expand All @@ -120,6 +126,13 @@ export class ItemsEditorComponent
return Object.keys(item.encrustGive?.stats ?? {}).sort() as StatType[];
});

public nourishmentStatsInOrder = computed(() => {
const item = this.editing();
return Object.keys(
item.useEffect?.extra?.statChanges ?? {}
).sort() as StatType[];
});

public extraProps: Signal<(keyof IItemDefinition)[]> = computed(() => {
return (typePropSets[this.editing().itemClass]
?.filter((s) => s !== 'stats')
Expand All @@ -136,16 +149,21 @@ export class ItemsEditorComponent

private resetProps(item: IItemDefinition) {
item.strikeEffect ??= { name: '', potency: 0, duration: 0, chance: 0 };
item.useEffect ??= { name: '', potency: 0, duration: 0 };
item.useEffect ??= {
name: '',
potency: 0,
duration: 0,
};
item.useEffect.extra ??= { tooltip: '', message: '', statChanges: {} };
item.equipEffect ??= { name: '', potency: 0 };
item.breakEffect ??= { name: '', potency: 0 };
item.trapEffect ??= {
name: '',
potency: 0,
uses: 1,
range: 0,
extra: { isPositive: false },
};
item.trapEffect.extra ??= { isPositive: false };

item.requirements ??= { baseClass: undefined, level: 0, quest: undefined };
item.cosmetic ??= { name: '', isPermanent: false };
Expand Down Expand Up @@ -301,7 +319,43 @@ export class ItemsEditorComponent
}

private hasEncrustStat(stat: StatType) {
return this.allStatEdits().find((s) => s.stat === stat);
return this.editing().encrustGive?.stats?.[stat];
}

public addNourishmentStat(stat: StatType, value = 0) {
if (this.hasNourishmentStat(stat)) return;

this.editing.update((s) => {
if (!s.useEffect) return s;

return {
...s,
useEffect: {
...s.useEffect,
extra: {
...s.useEffect.extra,
statChanges: {
...(s.useEffect.extra?.statChanges ?? {}),
[stat]: value,
},
},
},
};
});
}

public removeNourishmentStat(stat: StatType) {
this.editing.update((s) => {
if (!s.encrustGive) return s;

delete s.encrustGive.stats[stat];

return s;
});
}

private hasNourishmentStat(stat: StatType) {
return this.editing().useEffect?.extra?.statChanges?.[stat];
}

private extractStats(item: IItemDefinition) {
Expand Down Expand Up @@ -396,6 +450,22 @@ export class ItemsEditorComponent
delete item.strikeEffect;
}

if (
item.useEffect &&
item.useEffect.extra &&
!item.useEffect.extra.tooltip
) {
delete item.useEffect.extra;
}

if (
item.useEffect &&
item.useEffect.extra &&
!item.useEffect.extra.tooltip
) {
delete item.useEffect.extra;
}

if (item.useEffect && !item.useEffect.name) {
delete item.useEffect;
}
Expand Down

0 comments on commit eaf03a8

Please sign in to comment.