Skip to content

Commit

Permalink
closes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 17, 2024
1 parent 6dbc76f commit e42d539
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/app/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export const typePropDefaults: Record<
Bottle: { ounces: 1 },
Food: { ounces: 1 },
Gem: {},
Book: { bookPages: [], bookItemFilter: '', bookFindablePages: '' },
Book: { bookPages: [], bookItemFilter: '', bookFindablePages: 0 },
Trap: { trapUses: 1 },
Twig: { type: 'Staff' },
};
Expand Down
22 changes: 13 additions & 9 deletions src/app/helpers/schemas/_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@ export const isPartialSkillObjectFailure = isPartialObjectOfFailure<Skill>(
Object.values(Skill)
);

export const isPartialEquipmentObject = isPartialObjectOf<ItemSlot>(
Object.values(ItemSlot)
);
export const isPartialEquipmentObject = isPartialObjectOf<ItemSlot>([
'weapon',
'armor',
...Object.values(ItemSlot),
] as ItemSlot[]);
export const isPartialEquipmentObjectFailure =
isPartialObjectOfFailure<ItemSlot>(Object.values(ItemSlot));
isPartialObjectOfFailure<ItemSlot>([
'weapon',
'armor',
...Object.values(ItemSlot),
] as ItemSlot[]);

export const isPartialReputationObject = isPartialObjectOf<Allegiance>(
Object.values(Allegiance)
Expand All @@ -107,7 +113,9 @@ export const isPartialReputationObjectFailure =
isPartialObjectOfFailure<Allegiance>(Object.values(Allegiance));

export function isItemSlot(val: any): boolean {
return Object.values(ItemSlot).includes(val as ItemSlot);
return (
['weapon', 'armor', ...Object.values(ItemSlot)] as ItemSlot[]
).includes(val as ItemSlot);
}

export function isTraitObject(val: any): boolean {
Expand Down Expand Up @@ -204,10 +212,6 @@ export function isEffect(eff: any): boolean {
return eff.name && isNumber(eff.potency);
}

export function isEncrust(enc: any): boolean {
return !!(enc.stats || enc.equipEffect || enc.strikeEffect);
}

export function isBookPage(val: any): boolean {
return val.id === '' && isString(val.text);
}
Expand Down
19 changes: 17 additions & 2 deletions src/app/helpers/schemas/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
isBookPage,
isCosmetic,
isEffect,
isEncrust,
isIntegerBetween,
isItemSlot,
isObjectWithSome,
isObjectWithSomeFailure,
isPartialStatObject,
isPartialStatObjectFailure,
isRandomStatObject,
Expand Down Expand Up @@ -81,7 +83,20 @@ export const itemSchema: Schema = [
['breakEffect.name', false, isString],
['breakEffect.potency', false, isInteger],

['encrustGive', false, isEncrust],
[
'encrustGive',
false,
isObjectWithSome(['slots', 'stats', 'strikeEffect']),
isObjectWithSomeFailure(['slots', 'stats', 'strikeEffect']),
],
['encrustGive.slots', false, isArrayOf(isItemSlot)],
['encrustGive.stats', false, isPartialStatObject, isPartialStatObjectFailure],
['encrustGive.strikeEffect', false, isEffect],
['encrustGive.strikeEffect.name', false, isString],
['encrustGive.strikeEffect.potency', false, isInteger],
['encrustGive.strikeEffect.chance', false, isIntegerBetween(0, 100)],
['encrustGive.strikeEffect.duration', false, isInteger],
['encrustGive.strikeEffect.range', false, isIntegerBetween(0, 5)],

['tier', false, isInteger],
['destroyOnDrop', false, isBoolean],
Expand Down
27 changes: 27 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 @@ -319,6 +319,33 @@
</div>
}

@case('bookPages') {
<div class="form-row">
<button class="btn btn-accent btn-sm w-full" (click)="addBookPage()">
Add book page
</button>
</div>

@for(item of editingData.bookPages; track item) {
<div class="form-row split">
<div class="form-column">
<div class="form-row">
<app-input-floating-label>Page Text</app-input-floating-label>
<input [(ngModel)]="item.text" type="text" placeholder="Enter page text..." class="form-input" />
</div>
</div>

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

@default {
{{ prop }} ({{ propTypes[prop] }}) has no editor.
}
Expand Down
20 changes: 20 additions & 0 deletions src/app/tabs/items/items-editor/items-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ export class ItemsEditorComponent
chance: 0,
};

item.bookPages ??= [];

this.editing.set(item);
}

Expand Down Expand Up @@ -505,6 +507,10 @@ export class ItemsEditorComponent
delete item.encrustGive;
}
}

if (!item.bookPages?.length) {
delete item.bookPages;
}
}

changeTraitTab(newTraitSetting: TraitSetting) {
Expand Down Expand Up @@ -549,6 +555,20 @@ export class ItemsEditorComponent
this.editing.set(item);
}

public addBookPage() {
const item = this.editing();
item.bookPages?.push({ id: '', text: '' });

this.editing.set(item);
}

public removeBookPage(index: number) {
const item = this.editing();
item.bookPages?.splice(index, 1);

this.editing.set(item);
}

public doSave() {
const item = this.editing();
this.assignStats(item);
Expand Down

0 comments on commit e42d539

Please sign in to comment.