Skip to content

Commit

Permalink
Merge branch 'armor-sheet' into 'master'
Browse files Browse the repository at this point in the history
Create Armor Sheet

See merge request hooking/foundry-vtt---pathfinder-2e!6170
  • Loading branch information
stwlam committed Nov 26, 2021
2 parents e13932b + 8137d3e commit bc99ea3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 37 deletions.
35 changes: 35 additions & 0 deletions src/module/item/armor/sheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { PhysicalItemSheetPF2e } from "@item/physical/sheet";
import { LocalizePF2e } from "@system/localize";
import { getPropertySlots } from "../runes";
import { ArmorPF2e } from ".";

export class ArmorSheetPF2e extends PhysicalItemSheetPF2e<ArmorPF2e> {
override async getData() {
const sheetData = await super.getData();

// Armor property runes
const totalSlots = getPropertySlots(sheetData.item);
const propertyRuneSlots: Record<`propertyRuneSlots${number}`, boolean> = {};
for (const slot of [1, 2, 3, 4]) {
if (totalSlots >= slot) {
propertyRuneSlots[`propertyRuneSlots${slot}`] = true;
}
}

return {
...sheetData,
armorPotencyRunes: CONFIG.PF2E.armorPotencyRunes,
armorResiliencyRunes: CONFIG.PF2E.armorResiliencyRunes,
armorPropertyRunes: CONFIG.PF2E.armorPropertyRunes,
categories: CONFIG.PF2E.armorTypes,
groups: CONFIG.PF2E.armorGroups,
baseTypes: LocalizePF2e.translations.PF2E.Item.Armor.Base,
bulkTypes: CONFIG.PF2E.bulkTypes,
preciousMaterials: CONFIG.PF2E.preciousMaterials,
preciousMaterialGrades: CONFIG.PF2E.preciousMaterialGrades,
sizes: CONFIG.PF2E.actorSizes,
traits: this.prepareOptions(CONFIG.PF2E.armorTraits, sheetData.item.data.traits, { selectedOnly: true }),
...propertyRuneSlots,
};
}
}
28 changes: 0 additions & 28 deletions src/module/item/sheet/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getPropertySlots } from "../runes";
import { ItemDataPF2e } from "@item/data";
import { LocalizePF2e } from "@system/localize";
import { ItemSheetDataPF2e, SheetOptions, SheetSelections } from "./data-types";
Expand Down Expand Up @@ -133,23 +132,6 @@ export class ItemSheetPF2e<TItem extends ItemPF2e> extends ItemSheet<TItem> {
data.bulkTypes = CONFIG.PF2E.bulkTypes;
data.equipmentTraits = CONFIG.PF2E.equipmentTraits;
data.sizes = CONFIG.PF2E.actorSizes;
} else if (itemData.type === "armor") {
// Armor data
const slots = getPropertySlots(data);
this.assignPropertySlots(data, slots);
data.armorPotencyRunes = CONFIG.PF2E.armorPotencyRunes;
data.armorResiliencyRunes = CONFIG.PF2E.armorResiliencyRunes;
data.armorPropertyRunes = CONFIG.PF2E.armorPropertyRunes;
data.categories = CONFIG.PF2E.armorTypes;
data.groups = CONFIG.PF2E.armorGroups;
data.baseTypes = LocalizePF2e.translations.PF2E.Item.Armor.Base;
data.bulkTypes = CONFIG.PF2E.bulkTypes;
data.preciousMaterials = CONFIG.PF2E.preciousMaterials;
data.preciousMaterialGrades = CONFIG.PF2E.preciousMaterialGrades;
data.sizes = CONFIG.PF2E.actorSizes;

// Armor has derived traits: base traits are shown for editing
data.traits = this.prepareOptions(CONFIG.PF2E.armorTraits, itemData.data.traits, { selectedOnly: true });
} else if (itemData.type === "lore") {
// Lore-specific data
data.proficiencies = CONFIG.PF2E.proficiencyLevels;
Expand Down Expand Up @@ -193,16 +175,6 @@ export class ItemSheetPF2e<TItem extends ItemPF2e> extends ItemSheet<TItem> {
};
}

assignPropertySlots(data: Record<string, boolean>, number: number) {
const slots = [1, 2, 3, 4] as const;

for (const slot of slots) {
if (number >= slot) {
data[`propertyRuneSlots${slot}`] = true;
}
}
}

/** Prepare form options on the item sheet */
protected prepareOptions(
options: Record<string, string>,
Expand Down
21 changes: 12 additions & 9 deletions src/scripts/register-sheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { WeaponSheetPF2e } from "@item/weapon/sheet";
import { EffectSheetPF2e } from "@item/effect/sheet";
import { BookSheetPF2e } from "@item/book/sheet";
import { DeitySheetPF2e } from "@item/deity/sheet";
import { ArmorSheetPF2e } from "@item/armor/sheet";

export function registerSheets() {
const translations = LocalizePF2e.translations.PF2E;
Expand Down Expand Up @@ -95,15 +96,6 @@ export function registerSheets() {
});
}

for (const itemType of PHYSICAL_ITEM_TYPES) {
if (["book", "weapon"].includes(itemType)) continue;
Items.registerSheet("pf2e", PhysicalItemSheetPF2e, {
types: [itemType],
label: game.i18n.format(sheetLabel, { type: localizeType(itemType) }),
makeDefault: true,
});
}

const sheetEntries = [
["action", ActionSheetPF2e],
["ancestry", AncestrySheetPF2e],
Expand All @@ -116,6 +108,7 @@ export function registerSheets() {
["spell", SpellSheetPF2e],
["kit", KitSheetPF2e],
["weapon", WeaponSheetPF2e],
["armor", ArmorSheetPF2e],
] as const;
for (const [type, Sheet] of sheetEntries) {
Items.registerSheet("pf2e", Sheet, {
Expand All @@ -124,4 +117,14 @@ export function registerSheets() {
makeDefault: true,
});
}

// Add any missing physical item sheets
for (const itemType of PHYSICAL_ITEM_TYPES) {
if (sheetEntries.some(([type, _sheet]) => itemType === type)) continue;
Items.registerSheet("pf2e", PhysicalItemSheetPF2e, {
types: [itemType],
label: game.i18n.format(sheetLabel, { type: localizeType(itemType) }),
makeDefault: true,
});
}
}

0 comments on commit bc99ea3

Please sign in to comment.