added type support
This commit is contained in:
1 parent
c8e576d44f
commit
d5362e71b9
11 files changed
+2409
-57
No files matched your search
@@ -10,22 +10,25 @@ export class CharacterSheet extends foundry.applications.sheets.ActorSheetV2 {
|
||||
|
||||
#root: Root | null = null;
|
||||
|
||||
async _prepareContext(_options: unknown) {
|
||||
return { document: this.document };
|
||||
override async _renderHTML(
|
||||
...args: Parameters<foundry.applications.sheets.ActorSheetV2["_renderHTML"]>
|
||||
) {
|
||||
return args[0];
|
||||
}
|
||||
|
||||
async _renderHTML(context: unknown, _options: unknown) {
|
||||
return context;
|
||||
}
|
||||
|
||||
_replaceHTML(_result: unknown, content: HTMLElement, _options: unknown) {
|
||||
override _replaceHTML(
|
||||
...args: Parameters<foundry.applications.sheets.ActorSheetV2["_replaceHTML"]>
|
||||
) {
|
||||
const content = args[1];
|
||||
if (!this.#root) this.#root = createRoot(content);
|
||||
this.#root.render(React.createElement(CharacterSheetApp, { actor: this.document }));
|
||||
}
|
||||
|
||||
async close(options: unknown) {
|
||||
override async close(
|
||||
...args: Parameters<foundry.applications.sheets.ActorSheetV2["close"]>
|
||||
) {
|
||||
this.#root?.unmount();
|
||||
this.#root = null;
|
||||
return super.close(options);
|
||||
return super.close(...args);
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,16 @@ import styles from "./CharacterSheetApp.module.scss";
|
||||
const modifier = (score: number) => Math.floor((score - 10) / 2);
|
||||
const fmtMod = (mod: number) => (mod >= 0 ? `+${mod}` : `${mod}`);
|
||||
|
||||
export function CharacterSheetApp({ actor }: { actor: any }) {
|
||||
export function CharacterSheetApp({ actor }: { actor: Actor.Implementation }) {
|
||||
const system = actor.system;
|
||||
const attrs = system.attributes;
|
||||
|
||||
const updateAttribute = (key: string, value: number) => {
|
||||
actor.update({ [`system.attributes.${key}`]: value });
|
||||
const updateAttribute = (key: "strength" | "agility" | "spirit", value: number) => {
|
||||
actor.update({ system: { attributes: { [key]: value } } });
|
||||
};
|
||||
|
||||
const updateBiography = (value: string) => {
|
||||
actor.update({ "system.biography": value });
|
||||
actor.update({ system: { biography: value } });
|
||||
};
|
||||
|
||||
// derived purely from current doc state — recomputed every render, no local state needed
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import React from "react";
|
||||
import styles from "./ItemSheetApp.module.scss";
|
||||
|
||||
export function ItemSheetApp({ item }: { item: any }) {
|
||||
export function ItemSheetApp({ item }: { item: Item.Implementation }) {
|
||||
const system = item.system;
|
||||
|
||||
const updateQuantity = (value: number) => {
|
||||
item.update({ "system.quantity": value });
|
||||
item.update({ system: { quantity: value } });
|
||||
};
|
||||
|
||||
const updateDescription = (value: string) => {
|
||||
item.update({ "system.description": value });
|
||||
item.update({ system: { description: value } });
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -10,22 +10,25 @@ export class ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
|
||||
|
||||
#root: Root | null = null;
|
||||
|
||||
async _prepareContext(_options: unknown) {
|
||||
return { document: this.document };
|
||||
override async _renderHTML(
|
||||
...args: Parameters<foundry.applications.sheets.ItemSheetV2["_renderHTML"]>
|
||||
) {
|
||||
return args[0];
|
||||
}
|
||||
|
||||
async _renderHTML(context: unknown, _options: unknown) {
|
||||
return context;
|
||||
}
|
||||
|
||||
_replaceHTML(_result: unknown, content: HTMLElement, _options: unknown) {
|
||||
override _replaceHTML(
|
||||
...args: Parameters<foundry.applications.sheets.ItemSheetV2["_replaceHTML"]>
|
||||
) {
|
||||
const content = args[1];
|
||||
if (!this.#root) this.#root = createRoot(content);
|
||||
this.#root.render(React.createElement(ItemSheetApp, { item: this.document }));
|
||||
}
|
||||
|
||||
async close(options: unknown) {
|
||||
override async close(
|
||||
...args: Parameters<foundry.applications.sheets.ItemSheetV2["close"]>
|
||||
) {
|
||||
this.#root?.unmount();
|
||||
this.#root = null;
|
||||
return super.close(options);
|
||||
return super.close(...args);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user