added type support
This commit is contained in:
1 parent
c8e576d44f
commit
d5362e71b9
11 files changed
+2409
-57
No files matched your search
+17
-12
@@ -1,13 +1,18 @@
|
||||
export class CharacterData extends foundry.abstract.TypeDataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
biography: new fields.HTMLField({ initial: "" }),
|
||||
attributes: new fields.SchemaField({
|
||||
strength: new fields.NumberField({ required: true, integer: true, initial: 10 }),
|
||||
agility: new fields.NumberField({ required: true, integer: true, initial: 10 }),
|
||||
spirit: new fields.NumberField({ required: true, integer: true, initial: 10 })
|
||||
})
|
||||
};
|
||||
}
|
||||
function defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
biography: new fields.HTMLField({ initial: "" }),
|
||||
attributes: new fields.SchemaField({
|
||||
strength: new fields.NumberField({ required: true, nullable: false, integer: true, initial: 10 }),
|
||||
agility: new fields.NumberField({ required: true, nullable: false, integer: true, initial: 10 }),
|
||||
spirit: new fields.NumberField({ required: true, nullable: false, integer: true, initial: 10 })
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
export class CharacterData extends foundry.abstract.TypeDataModel<
|
||||
ReturnType<typeof defineSchema>,
|
||||
Actor.Implementation
|
||||
> {
|
||||
static defineSchema = defineSchema;
|
||||
}
|
||||
+13
-8
@@ -1,9 +1,14 @@
|
||||
export class ItemData extends foundry.abstract.TypeDataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
description: new fields.HTMLField({ initial: "" }),
|
||||
quantity: new fields.NumberField({ required: true, integer: true, initial: 1, min: 0 })
|
||||
};
|
||||
}
|
||||
function defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
description: new fields.HTMLField({ initial: "" }),
|
||||
quantity: new fields.NumberField({ required: true, nullable: false, integer: true, initial: 1, min: 0 })
|
||||
};
|
||||
}
|
||||
|
||||
export class ItemData extends foundry.abstract.TypeDataModel<
|
||||
ReturnType<typeof defineSchema>,
|
||||
Item.Implementation
|
||||
> {
|
||||
static defineSchema = defineSchema;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
import type { CharacterData } from "../data/character-data";
|
||||
import type { ItemData } from "../data/item-data";
|
||||
|
||||
declare module "fvtt-types/configuration" {
|
||||
interface DataModelConfig {
|
||||
Actor: { character: typeof CharacterData };
|
||||
Item: { item: typeof ItemData };
|
||||
}
|
||||
}
|
||||
Vendored
-12
@@ -1,15 +1,3 @@
|
||||
// Minimal ambient declarations for the Foundry V14 globals used by this boilerplate.
|
||||
// Intentionally untyped (any) — swap for a real Foundry types package once one tracks V14.
|
||||
declare const Hooks: {
|
||||
once(hook: string, callback: (...args: any[]) => void): void;
|
||||
on(hook: string, callback: (...args: any[]) => void): void;
|
||||
};
|
||||
declare const CONFIG: any;
|
||||
declare const game: any;
|
||||
declare const foundry: any;
|
||||
declare const Actor: any;
|
||||
declare const Item: any;
|
||||
|
||||
declare module "*.module.scss" {
|
||||
const classes: { readonly [key: string]: string };
|
||||
export default classes;
|
||||
|
||||
Reference in new issue
Block a user