Skip to content

Commit

Permalink
Start on party sheet v2
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFdez committed Jan 15, 2025
1 parent cc68910 commit b7df6d6
Show file tree
Hide file tree
Showing 18 changed files with 2,278 additions and 51 deletions.
8 changes: 8 additions & 0 deletions src/module/actor/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,14 @@ class ActorPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e | n
return commitData;
}

/**
* Updates a resource. Redirects to special resources if needed.
* Accepts resource slugs in both kebab and dromedary, to handle token updates and direct ones.
*/
async updateResource(_resource: string, _value: number, _options?: { render?: boolean }): Promise<void> {
return; // no-op
}

/** Don't allow the user to create in-development actor types. */
static override createDialog<TDocument extends foundry.abstract.Document>(
this: ConstructorOf<TDocument>,
Expand Down
13 changes: 9 additions & 4 deletions src/module/actor/character/apps/abc-picker/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type { CharacterPF2e } from "@actor";
import type { ABCItemPF2e, DeityPF2e, ItemPF2e } from "@item";
import type { ItemType } from "@item/base/data/index.ts";
import { Rarity } from "@module/data.ts";
import { SvelteApplicationMixin, type SvelteApplicationRenderContext } from "@module/sheet/mixin.svelte.ts";
import {
BaseSvelteState,
SvelteApplicationMixin,
type SvelteApplicationRenderContext,
} from "@module/sheet/mixin.svelte.ts";
import { sluggify } from "@util";
import { UUIDUtils } from "@util/uuid.ts";
import * as R from "remeda";
Expand Down Expand Up @@ -32,8 +36,7 @@ interface ABCItemRef {

interface ABCPickerContext extends SvelteApplicationRenderContext {
actor: CharacterPF2e;
foundryApp: ABCPicker;
state: { prompt: string; itemType: AhBCDType; items: ABCItemRef[] };
state: BaseSvelteState & { prompt: string; itemType: AhBCDType; items: ABCItemRef[] };
}

/** A `Compendium`-like application for presenting A(H)BCD options for a character */
Expand Down Expand Up @@ -116,11 +119,13 @@ class ABCPicker extends SvelteApplicationMixin<
}

protected override async _prepareContext(): Promise<ABCPickerContext> {
const base = await super._prepareContext();
const itemType = this.options.itemType;
return {
...base,
actor: this.options.actor,
foundryApp: this,
state: {
...base.state,
prompt: game.i18n.localize(`PF2E.Actor.Character.ABCPicker.Prompt.${itemType}`),
itemType,
items: await this.#gatherItems(),
Expand Down
13 changes: 10 additions & 3 deletions src/module/actor/character/apps/formula-picker/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { ResourceData } from "@actor/creature/index.ts";
import { AbilityItemPF2e, FeatPF2e, PhysicalItemPF2e } from "@item";
import { ItemType, TraitChatData } from "@item/base/data/index.ts";
import { Rarity } from "@module/data.ts";
import { SvelteApplicationMixin, type SvelteApplicationRenderContext } from "@module/sheet/mixin.svelte.ts";
import {
BaseSvelteState,
SvelteApplicationMixin,
type SvelteApplicationRenderContext,
} from "@module/sheet/mixin.svelte.ts";
import MiniSearch from "minisearch";
import * as R from "remeda";
import { ApplicationConfiguration, ApplicationRenderOptions } from "types/foundry/client-esm/applications/_types.js";
Expand Down Expand Up @@ -81,6 +85,8 @@ class FormulaPicker extends SvelteApplicationMixin<
}

protected override async _prepareContext(): Promise<FormulaPickerContext> {
const base = await super._prepareContext();

const { actor, ability, mode } = this.options;
const formulas = await ability.getValidFormulas();
const sheetData = await ability.getSheetData();
Expand All @@ -102,7 +108,7 @@ class FormulaPicker extends SvelteApplicationMixin<
: game.i18n.localize("PF2E.Actor.Character.Crafting.Action.HintResourceless");

return {
foundryApp: this,
...base,
actor,
ability,
mode: this.options.mode,
Expand All @@ -122,6 +128,7 @@ class FormulaPicker extends SvelteApplicationMixin<
},
searchEngine: this.#searchEngine,
state: {
...base.state,
name: this.options.item?.name ?? ability.label,
resource,
prompt,
Expand Down Expand Up @@ -163,7 +170,7 @@ interface FormulaPickerContext extends SvelteApplicationRenderContext {
onSelect: (uuid: ItemUUID) => void;
onDeselect: (uuid: ItemUUID) => void;
searchEngine: MiniSearch<Pick<PhysicalItemPF2e, "id" | "name">>;
state: {
state: BaseSvelteState & {
name: string;
resource: ResourceData | null;
prompt: string;
Expand Down
10 changes: 5 additions & 5 deletions src/module/actor/creature/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,11 @@ abstract class CreaturePF2e<
return { ...data, slug, label };
}

/**
* Updates a resource. Redirects to special resources if needed.
* Accepts resource slugs in both kebab and dromedary, to handle token updates and direct ones.
*/
async updateResource(resource: string, value: number, { render }: { render?: boolean } = {}): Promise<void> {
override async updateResource(
resource: string,
value: number,
{ render }: { render?: boolean } = {},
): Promise<void> {
const slug = sluggify(resource);
const key = sluggify(resource, { camel: "dromedary" });
if (key === "investiture") return;
Expand Down
Loading

0 comments on commit b7df6d6

Please sign in to comment.