Skip to content

Commit

Permalink
Take token step toward renaming action items as ability items (foundr…
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam committed Aug 7, 2023
1 parent 4421f5d commit 3dbda65
Show file tree
Hide file tree
Showing 37 changed files with 95 additions and 95 deletions.
45 changes: 22 additions & 23 deletions build/lib/extractor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ActorSourcePF2e } from "@actor/data/index.ts";
import type { NPCAttributesSource, NPCSystemSource } from "@actor/npc/data.ts";
import { isPhysicalData } from "@item/data/helpers.ts";
import { ActionItemSource, ItemSourcePF2e, MeleeSource, SpellSource } from "@item/data/index.ts";
import { ItemSourcePF2e, MeleeSource, SpellSource } from "@item/data/index.ts";
import { itemIsOfType } from "@item/helpers.ts";
import { RuleElementSource } from "@module/rules/index.ts";
import { isObject, sluggify } from "@util/index.ts";
import fs from "fs";
Expand All @@ -12,8 +13,8 @@ import systemJSON from "../../static/system.json" assert { type: "json" };
import templateJSON from "../../static/template.json" assert { type: "json" };
import { CompendiumPack, isActorSource, isItemSource } from "./compendium-pack.ts";
import { PackError, getFilesRecursively } from "./helpers.ts";
import { PackEntry } from "./types.ts";
import { DBFolder, LevelDatabase } from "./level-database.ts";
import { PackEntry } from "./types.ts";

declare global {
interface Global {
Expand Down Expand Up @@ -609,7 +610,7 @@ class PackExtractor {
items = this.#sortSpells(itemGroup);
break;
case "action":
items = this.#sortActions(docSource.name, itemGroup);
items = this.#sortAbilities(docSource.name, itemGroup);
break;
case "lore":
items = Array.from(itemGroup).sort((a, b) => a.name.localeCompare(b.name));
Expand Down Expand Up @@ -733,47 +734,45 @@ class PackExtractor {
}

/** Sorts actions by category, only called for NPCs */
#sortActions(docName: string, actions: Set<ItemSourcePF2e>): ItemSourcePF2e[] {
const notActions: [string, string][] = [
#sortAbilities(docName: string, items: Set<ItemSourcePF2e>): ItemSourcePF2e[] {
const notAbilities: [string, string][] = [
["Innate Spells", "spellcastingEntry"],
["Prepared Spells", "spellcastingEntry"],
["Ritual Spells", "spellcastingEntry"],
["Spontaneous Spells", "spellcastingEntry"],
];
const actionsMap: Map<string, ItemSourcePF2e[]> = new Map([
const abilitiesMap: Map<string, ItemSourcePF2e[]> = new Map([
["interaction", []],
["defensive", []],
["offensive", []],
["other", []],
]);

for (const action of Array.from(actions).sort((a, b) => a.name.localeCompare(b.name))) {
const actionData = action as ActionItemSource;
const notActionMatch = notActions.find((naName) => actionData.name.match(naName[0]));
if (notActionMatch) {
for (const ability of Array.from(items).sort((a, b) => a.name.localeCompare(b.name))) {
const notAbilityMatch = notAbilities.find((naName) => ability.name.match(naName[0]));
if (notAbilityMatch) {
console.log(
`Error in ${docName}: ${notActionMatch[0]} has type action but should be type ${notActionMatch[1]}!`
`Error in ${docName}: ${notAbilityMatch[0]} has type action but should be type ${notAbilityMatch[1]}!`
);
}
if (!actionData.system.category) {
if (!itemIsOfType(ability, "action")) continue;

if (!ability.system.category) {
if (this.emitWarnings) {
console.log(`Warning in ${docName}: Action item '${actionData.name}' has no category defined!`);
console.log(`Warning in ${docName}: Ability item "${ability.name}" has no category defined!`);
}
actionsMap.get("other")!.push(actionData);
abilitiesMap.get("other")!.push(ability);
} else {
let actionCategory: string = actionData.system.category;
if (!actionsMap.has(actionCategory)) {
actionCategory = "other";
}
actionsMap.get(actionCategory)!.push(actionData);
const actionCategory = abilitiesMap.has(ability.system.category) ? ability.system.category : "other";
abilitiesMap.get(actionCategory)!.push(ability);
}
}

const sortedInteractions = this.#sortInteractions(docName, actionsMap.get("interaction")!);
const sortedDefensive = this.#sortDefensiveActions(docName, actionsMap.get("defensive")!);
const sortedOffensive = this.#sortOffensiveActions(docName, actionsMap.get("offensive")!);
const sortedInteractions = this.#sortInteractions(docName, abilitiesMap.get("interaction")!);
const sortedDefensive = this.#sortDefensiveActions(docName, abilitiesMap.get("defensive")!);
const sortedOffensive = this.#sortOffensiveActions(docName, abilitiesMap.get("offensive")!);

return sortedInteractions.concat(sortedDefensive, sortedOffensive, actionsMap.get("other")!);
return sortedInteractions.concat(sortedDefensive, sortedOffensive, abilitiesMap.get("other")!);
}

#sortSpells(spells: Set<ItemSourcePF2e>): SpellSource[] {
Expand Down
2 changes: 1 addition & 1 deletion src/module/actor/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
UnaffectedType,
} from "@actor/types.ts";
import { AbstractEffectPF2e, ArmorPF2e, ContainerPF2e, ItemPF2e, ItemProxyPF2e, PhysicalItemPF2e } from "@item";
import { ActionTrait } from "@item/action/types.ts";
import { ActionTrait } from "@item/ability/types.ts";
import { AfflictionSource } from "@item/affliction/index.ts";
import { ConditionKey, ConditionSlug, ConditionSource, type ConditionPF2e } from "@item/condition/index.ts";
import { PersistentDialog } from "@item/condition/persistent-damage-dialog.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/module/actor/character/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
PhysicalItemPF2e,
WeaponPF2e,
} from "@item";
import { ActionTrait } from "@item/action/types.ts";
import { ActionTrait } from "@item/ability/types.ts";
import { ARMOR_CATEGORIES } from "@item/armor/values.ts";
import { ItemType, PhysicalItemSource } from "@item/data/index.ts";
import { getPropertyRuneStrikeAdjustments, getResilientBonus } from "@item/physical/runes.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/module/actor/creature/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ActorPF2e, CreaturePF2e } from "@actor";
import { createSpellcastingDialog } from "@actor/sheet/spellcasting-dialog.ts";
import { ATTRIBUTE_ABBREVIATIONS, SKILL_DICTIONARY } from "@actor/values.ts";
import { ItemPF2e, SpellPF2e, SpellcastingEntryPF2e } from "@item";
import { ActionCategory, ActionTrait } from "@item/action/index.ts";
import { ActionCategory, ActionTrait } from "@item/ability/index.ts";
import { ActionType } from "@item/data/base.ts";
import { ItemSourcePF2e } from "@item/data/index.ts";
import { ITEM_CARRY_TYPES } from "@item/data/values.ts";
Expand Down
4 changes: 2 additions & 2 deletions src/module/actor/familiar/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CharacterPF2e } from "@actor";
import { CreatureSheetPF2e } from "@actor/creature/sheet.ts";
import { FamiliarPF2e } from "@actor/familiar/index.ts";
import { eventToRollParams } from "@scripts/sheet-util.ts";
import { ActionItemPF2e } from "@item";
import { AbilityItemPF2e } from "@item";
import { CreatureSheetData } from "@actor/creature/index.ts";

/**
Expand Down Expand Up @@ -84,6 +84,6 @@ interface FamiliarSheetData<TActor extends FamiliarPF2e> extends CreatureSheetDa
size: string;
familiarAbilities: {
value: number;
items: ActionItemPF2e[];
items: AbilityItemPF2e[];
};
}
6 changes: 3 additions & 3 deletions src/module/actor/hazard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HazardPF2e } from "@actor";
import { TraitViewData } from "@actor/data/base.ts";
import { ActorSheetDataPF2e } from "@actor/sheet/data-types.ts";
import { SaveType } from "@actor/types.ts";
import { ActionItemPF2e } from "@item";
import { AbilityItemPF2e } from "@item";

interface HazardSheetData extends ActorSheetDataPF2e<HazardPF2e> {
actions: HazardActionSheetData;
Expand All @@ -27,8 +27,8 @@ interface HazardSheetData extends ActorSheetDataPF2e<HazardPF2e> {
}

interface HazardActionSheetData {
reaction: ActionItemPF2e[];
action: ActionItemPF2e[];
reaction: AbilityItemPF2e[];
action: AbilityItemPF2e[];
}

interface HazardSaveSheetData {
Expand Down
4 changes: 2 additions & 2 deletions src/module/actor/npc/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CreatureSheetData } from "@actor/creature/types.ts";
import { HitPointsStatistic, PerceptionData } from "@actor/data/base.ts";
import { MovementType, SaveType, SkillAbbreviation } from "@actor/types.ts";
import { ActionItemPF2e, EffectPF2e, ItemPF2e } from "@item";
import { AbilityItemPF2e, EffectPF2e, ItemPF2e } from "@item";
import { SpellcastingSheetData } from "@item/spellcasting-entry/index.ts";
import { ZeroToFour } from "@module/data.ts";
import { TraitTagifyEntry } from "@module/sheet/helpers.ts";
Expand All @@ -11,7 +11,7 @@ import { NPCPF2e, NPCStrike } from "./index.ts";

interface ActionsDetails {
label: string;
actions: NPCSheetItemData<ActionItemPF2e<NPCPF2e>>[];
actions: NPCSheetItemData<AbilityItemPF2e<NPCPF2e>>[];
}

interface NPCActionSheetData {
Expand Down
16 changes: 9 additions & 7 deletions src/module/actor/vehicle/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ActorSheetPF2e } from "../sheet/base.ts";
import { VehiclePF2e } from "@actor/vehicle/index.ts";
import { ErrorPF2e, getActionIcon, htmlClosest, htmlQuery, htmlQueryAll } from "@util";
import { ActorSheetDataPF2e } from "@actor/sheet/data-types.ts";
import { ActionItemPF2e } from "@item";
import { AbilityItemPF2e } from "@item";

export class VehicleSheetPF2e extends ActorSheetPF2e<VehiclePF2e> {
static override get defaultOptions(): ActorSheetOptions {
Expand Down Expand Up @@ -40,12 +40,14 @@ export class VehicleSheetPF2e extends ActorSheetPF2e<VehiclePF2e> {
const actorData = sheetData.actor;

// Actions
const actions: Record<"action" | "reaction" | "free", { label: string; actions: RawObject<ActionItemPF2e>[] }> =
{
action: { label: game.i18n.localize("PF2E.ActionsActionsHeader"), actions: [] },
reaction: { label: game.i18n.localize("PF2E.ActionsReactionsHeader"), actions: [] },
free: { label: game.i18n.localize("PF2E.ActionsFreeActionsHeader"), actions: [] },
};
const actions: Record<
"action" | "reaction" | "free",
{ label: string; actions: RawObject<AbilityItemPF2e>[] }
> = {
action: { label: game.i18n.localize("PF2E.ActionsActionsHeader"), actions: [] },
reaction: { label: game.i18n.localize("PF2E.ActionsReactionsHeader"), actions: [] },
free: { label: game.i18n.localize("PF2E.ActionsFreeActionsHeader"), actions: [] },
};

// Actions
for (const item of this.actor.itemTypes.action.sort((a, b) => a.sort - b.sort)) {
Expand Down
2 changes: 1 addition & 1 deletion src/module/apps/compendium-browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { KitPF2e, PhysicalItemPF2e } from "@item";
import { ActionCategory, ActionTrait } from "@item/action/index.ts";
import { ActionCategory, ActionTrait } from "@item/ability/index.ts";
import { ActionType } from "@item/data/base.ts";
import { BaseSpellcastingEntry } from "@item/spellcasting-entry/index.ts";
import { UserPF2e } from "@module/user/document.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/module/apps/compendium-browser/tabs/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CreatureTrait } from "@actor/creature/types.ts";
import { HazardTrait } from "@actor/hazard/types.ts";
import { ActionTrait } from "@item/action/index.ts";
import { ActionTrait } from "@item/ability/index.ts";
import { FeatTrait } from "@item/feat/types.ts";
import { PhysicalItemTrait } from "@item/physical/data.ts";
import { SearchResult } from "minisearch";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import {
ItemTraits,
} from "@item/data/base.ts";
import { OneToThree } from "@module/data.ts";
import { ActionTrait } from "./types.ts";
import { ActionCategory, ActionTrait } from "./types.ts";

type ActionItemSource = BaseItemSourcePF2e<"action", ActionSystemSource>;
type AbilityItemSource = BaseItemSourcePF2e<"action", AbilitySystemSource>;

interface ActionTraits extends ItemTraits<ActionTrait> {
interface AbilityTraits extends ItemTraits<ActionTrait> {
rarity?: never;
}

interface ActionSystemSource extends ItemSystemSource {
traits: ActionTraits;
interface AbilitySystemSource extends ItemSystemSource {
traits: AbilityTraits;
actionType: {
value: ActionType;
};
Expand All @@ -36,10 +36,8 @@ interface ActionSystemSource extends ItemSystemSource {
level?: never;
}

interface ActionSystemData extends ActionSystemSource, Omit<ItemSystemData, "level" | "traits"> {
interface AbilitySystemData extends AbilitySystemSource, Omit<ItemSystemData, "level" | "traits"> {
frequency?: Frequency;
}

type ActionCategory = keyof ConfigPF2e["PF2E"]["actionCategories"];

export { ActionCategory, ActionItemSource, ActionSystemData, ActionTraits };
export { AbilityItemSource, AbilitySystemData, AbilityTraits };
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { ActionCost, Frequency } from "@item/data/base.ts";
import { ItemSummaryData } from "@item/data/index.ts";
import { UserPF2e } from "@module/user/index.ts";
import { getActionTypeLabel } from "@util";
import { ActionItemSource, ActionSystemData } from "./data.ts";
import { AbilityItemSource, AbilitySystemData } from "./data.ts";
import { normalizeActionChangeData } from "./helpers.ts";

class ActionItemPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends ItemPF2e<TParent> {
class AbilityItemPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends ItemPF2e<TParent> {
get actionCost(): ActionCost | null {
const actionType = this.system.actionType.value || "passive";
if (actionType === "passive") return null;
Expand Down Expand Up @@ -40,7 +40,7 @@ class ActionItemPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extend
}

override async getChatData(
this: ActionItemPF2e<ActorPF2e>,
this: AbilityItemPF2e<ActorPF2e>,
htmlOptions: EnrichHTMLOptions = {}
): Promise<ItemSummaryData> {
const systemData = this.system;
Expand All @@ -51,7 +51,7 @@ class ActionItemPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extend
}

protected override async _preCreate(
data: PreDocumentId<ActionItemSource>,
data: PreDocumentId<AbilityItemSource>,
options: DocumentModificationContext<TParent>,
user: UserPF2e
): Promise<boolean | void> {
Expand All @@ -75,9 +75,9 @@ class ActionItemPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extend
}
}

interface ActionItemPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends ItemPF2e<TParent> {
readonly _source: ActionItemSource;
system: ActionSystemData;
interface AbilityItemPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends ItemPF2e<TParent> {
readonly _source: AbilityItemSource;
system: AbilitySystemData;
}

export { ActionItemPF2e };
export { AbilityItemPF2e };
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { htmlQuery } from "@util";
import { ActionSystemData } from "./data.ts";
import { AbilitySystemData } from "./data.ts";
import { FrequencySource } from "@item/data/base.ts";
import { ItemPF2e } from "@item";

interface SourceWithActionData {
system: {
actionType: ActionSystemData["actionType"];
actions: ActionSystemData["actions"];
actionType: AbilitySystemData["actionType"];
actions: AbilitySystemData["actions"];
};
}

interface SourceWithFrequencyData {
system: {
frequency?: ActionSystemData["frequency"];
frequency?: AbilitySystemData["frequency"];
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./data.ts";
export { ActionItemPF2e } from "./document.ts";
export { AbilityItemPF2e } from "./document.ts";
export { ActionSheetPF2e } from "./sheet.ts";
export * from "./types.ts";
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ActionItemPF2e } from "@item/action/document.ts";
import { AbilityItemPF2e } from "@item/ability/document.ts";
import { ItemSheetDataPF2e } from "@item/sheet/data-types.ts";
import { ItemSheetPF2e } from "../sheet/base.ts";
import { addSheetFrequencyListeners } from "./helpers.ts";

export class ActionSheetPF2e extends ItemSheetPF2e<ActionItemPF2e> {
export class ActionSheetPF2e extends ItemSheetPF2e<AbilityItemPF2e> {
override async getData(options?: Partial<DocumentSheetOptions>): Promise<ActionSheetData> {
const data = await super.getData(options);

Expand Down Expand Up @@ -38,7 +38,7 @@ export class ActionSheetPF2e extends ItemSheetPF2e<ActionItemPF2e> {
}
}

interface ActionSheetData extends ItemSheetDataPF2e<ActionItemPF2e> {
interface ActionSheetData extends ItemSheetDataPF2e<AbilityItemPF2e> {
categories: ConfigPF2e["PF2E"]["actionCategories"];
actionTypes: ConfigPF2e["PF2E"]["actionTypes"];
actionsNumber: ConfigPF2e["PF2E"]["actionsNumber"];
Expand Down
4 changes: 4 additions & 0 deletions src/module/item/ability/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type ActionCategory = keyof ConfigPF2e["PF2E"]["actionCategories"];
type ActionTrait = keyof ConfigPF2e["PF2E"]["actionTraits"];

export { ActionCategory, ActionTrait };
2 changes: 1 addition & 1 deletion src/module/item/abstract-effect/data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AttributeString } from "@actor/types.ts";
import { ActionTrait } from "@item/action/types.ts";
import { ActionTrait } from "@item/ability/types.ts";
import { ItemSystemData, ItemSystemSource } from "@item/data/base.ts";
import { MagicTradition, SpellTrait } from "@item/spell/index.ts";
import { CheckRoll } from "@system/check/index.ts";
Expand Down
3 changes: 0 additions & 3 deletions src/module/item/action/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/module/item/affliction/sheet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AfflictionPF2e, ConditionPF2e, EffectPF2e, ItemPF2e } from "@item";
import { ActionTrait } from "@item/action/types.ts";
import { ActionTrait } from "@item/ability/types.ts";
import { ItemSheetPF2e } from "@item/sheet/base.ts";
import { ItemSheetDataPF2e } from "@item/sheet/data-types.ts";
import { ConditionManager } from "@system/conditions/index.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/module/item/campaign-feature/document.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActorPF2e, PartyPF2e } from "@actor";
import { FeatGroup } from "@actor/character/feats.ts";
import { ItemPF2e } from "@item";
import { normalizeActionChangeData } from "@item/action/helpers.ts";
import { normalizeActionChangeData } from "@item/ability/helpers.ts";
import { ActionCost, Frequency } from "@item/data/base.ts";
import { UserPF2e } from "@module/user/index.ts";
import { sluggify, tupleHasValue } from "@util";
Expand Down
2 changes: 1 addition & 1 deletion src/module/item/campaign-feature/sheet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addSheetFrequencyListeners } from "@item/action/helpers.ts";
import { addSheetFrequencyListeners } from "@item/ability/helpers.ts";
import { ItemSheetDataPF2e, ItemSheetPF2e } from "@item/sheet/index.ts";
import { htmlQuery } from "@util";
import Tagify from "@yaireo/tagify";
Expand Down
2 changes: 1 addition & 1 deletion src/module/item/data/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CreatureTrait } from "@actor/creature/types.ts";
import { ActionTrait } from "@item/action/types.ts";
import { ActionTrait } from "@item/ability/types.ts";
import { KingmakerTrait } from "@item/campaign-feature/types.ts";
import { NPCAttackTrait } from "@item/melee/data.ts";
import { PhysicalItemTrait } from "@item/physical/data.ts";
Expand Down
Loading

0 comments on commit 3dbda65

Please sign in to comment.