generated from maximegris/angular-electron
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
96 additions
and
325 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/app/shared/components/edit-statobject/edit-statobject.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@let stats = statObject(); | ||
|
||
<div class="form-row split"> | ||
<div class="form-column"> | ||
<div class="form-row"> | ||
<app-input-stat [(stat)]="currentStat" [allowCore]="allowCore()"></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]="!currentStat() || doesObjectHaveCurrentStat()" | ||
(click)="addStat(currentStat())"> | ||
<ng-icon name="heroPlus"></ng-icon> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
@for(stat of statsInOrder(); 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)]="stats[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)="removeStat(stat)"> | ||
<ng-icon name="heroMinus"></ng-icon> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
} |
Empty file.
48 changes: 48 additions & 0 deletions
48
src/app/shared/components/edit-statobject/edit-statobject.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Component, computed, input, model, signal } from '@angular/core'; | ||
import { isNumber } from 'lodash'; | ||
import { StatType } from '../../../../interfaces'; | ||
|
||
@Component({ | ||
selector: 'app-edit-statobject', | ||
templateUrl: './edit-statobject.component.html', | ||
styleUrl: './edit-statobject.component.scss', | ||
}) | ||
export class EditStatobjectComponent { | ||
public statObject = model.required<Partial<Record<StatType, number>>>(); | ||
public allowCore = input<boolean>(true); | ||
|
||
public currentStat = signal<StatType>('agi'); | ||
|
||
public statsInOrder = computed(() => { | ||
const stats = this.statObject() ?? {}; | ||
return Object.keys(stats).sort() as StatType[]; | ||
}); | ||
|
||
public doesObjectHaveCurrentStat = computed(() => { | ||
const current = this.currentStat(); | ||
return isNumber(this.statObject()?.[current]); | ||
}); | ||
|
||
addStat(stat: StatType, value = 0) { | ||
if (this.hasStat(stat)) return; | ||
|
||
this.statObject.update((editing) => { | ||
return { | ||
...editing, | ||
[stat]: value, | ||
}; | ||
}); | ||
} | ||
|
||
removeStat(stat: StatType) { | ||
this.statObject.update((s) => { | ||
delete s[stat]; | ||
|
||
return structuredClone(s); | ||
}); | ||
} | ||
|
||
hasStat(stat: StatType) { | ||
return this.statObject()?.[stat]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.