Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start on party sheet v2 #17702

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 1 addition & 7 deletions src/module/actor/party/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as R from "remeda";
import type { DataModelValidationOptions } from "types/foundry/common/abstract/data.d.ts";
import { PartySource, PartySystemData } from "./data.ts";
import { Kingdom } from "./kingdom/model.ts";
import { PartySheetRenderOptions } from "./sheet.ts";
import { PartyCampaign, PartyUpdateOperation } from "./types.ts";

class PartyPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e | null> extends ActorPF2e<TParent> {
Expand Down Expand Up @@ -179,7 +178,7 @@ class PartyPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e | n
/** Re-render the sheet if data preparation is called from the familiar's master */
override reset({ actor = false } = {}): void {
if (actor) {
this._resetAndRerenderDebounced();
this.sheet.render(false);
} else {
super.reset();
}
Expand All @@ -196,11 +195,6 @@ class PartyPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e | n
return campaignStat ?? null;
}

private _resetAndRerenderDebounced = fu.debounce(() => {
super.reset();
this.sheet.render(false, { actor: true } as PartySheetRenderOptions);
}, 50);

/* -------------------------------------------- */
/* Event Handlers */
/* -------------------------------------------- */
Expand Down
Loading
Loading