added type support
This commit is contained in:
1 parent
c8e576d44f
commit
d5362e71b9
11 files changed
+2399
-47
No files matched your search
Generated
+2337
File diff suppressed because it is too large.
Load diff
@@ -11,6 +11,7 @@
|
|||||||
"@types/react": "^18.3.0",
|
"@types/react": "^18.3.0",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
"@vitejs/plugin-react": "^4.3.0",
|
"@vitejs/plugin-react": "^4.3.0",
|
||||||
|
"fvtt-types": "^13.346.0-beta.20251209192131",
|
||||||
"sass": "^1.101.0",
|
"sass": "^1.101.0",
|
||||||
"typescript": "^5.6.0",
|
"typescript": "^5.6.0",
|
||||||
"vite": "^5.4.0"
|
"vite": "^5.4.0"
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
export class CharacterData extends foundry.abstract.TypeDataModel {
|
function defineSchema() {
|
||||||
static defineSchema() {
|
|
||||||
const fields = foundry.data.fields;
|
const fields = foundry.data.fields;
|
||||||
return {
|
return {
|
||||||
biography: new fields.HTMLField({ initial: "" }),
|
biography: new fields.HTMLField({ initial: "" }),
|
||||||
attributes: new fields.SchemaField({
|
attributes: new fields.SchemaField({
|
||||||
strength: new fields.NumberField({ required: true, integer: true, initial: 10 }),
|
strength: new fields.NumberField({ required: true, nullable: false, integer: true, initial: 10 }),
|
||||||
agility: new fields.NumberField({ required: true, integer: true, initial: 10 }),
|
agility: new fields.NumberField({ required: true, nullable: false, integer: true, initial: 10 }),
|
||||||
spirit: new fields.NumberField({ required: true, 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;
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
export class ItemData extends foundry.abstract.TypeDataModel {
|
function defineSchema() {
|
||||||
static defineSchema() {
|
|
||||||
const fields = foundry.data.fields;
|
const fields = foundry.data.fields;
|
||||||
return {
|
return {
|
||||||
description: new fields.HTMLField({ initial: "" }),
|
description: new fields.HTMLField({ initial: "" }),
|
||||||
quantity: new fields.NumberField({ required: true, integer: true, initial: 1, min: 0 })
|
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;
|
#root: Root | null = null;
|
||||||
|
|
||||||
async _prepareContext(_options: unknown) {
|
override async _renderHTML(
|
||||||
return { document: this.document };
|
...args: Parameters<foundry.applications.sheets.ActorSheetV2["_renderHTML"]>
|
||||||
|
) {
|
||||||
|
return args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
async _renderHTML(context: unknown, _options: unknown) {
|
override _replaceHTML(
|
||||||
return context;
|
...args: Parameters<foundry.applications.sheets.ActorSheetV2["_replaceHTML"]>
|
||||||
}
|
) {
|
||||||
|
const content = args[1];
|
||||||
_replaceHTML(_result: unknown, content: HTMLElement, _options: unknown) {
|
|
||||||
if (!this.#root) this.#root = createRoot(content);
|
if (!this.#root) this.#root = createRoot(content);
|
||||||
this.#root.render(React.createElement(CharacterSheetApp, { actor: this.document }));
|
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?.unmount();
|
||||||
this.#root = null;
|
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 modifier = (score: number) => Math.floor((score - 10) / 2);
|
||||||
const fmtMod = (mod: number) => (mod >= 0 ? `+${mod}` : `${mod}`);
|
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 system = actor.system;
|
||||||
const attrs = system.attributes;
|
const attrs = system.attributes;
|
||||||
|
|
||||||
const updateAttribute = (key: string, value: number) => {
|
const updateAttribute = (key: "strength" | "agility" | "spirit", value: number) => {
|
||||||
actor.update({ [`system.attributes.${key}`]: value });
|
actor.update({ system: { attributes: { [key]: value } } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateBiography = (value: string) => {
|
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
|
// derived purely from current doc state — recomputed every render, no local state needed
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import styles from "./ItemSheetApp.module.scss";
|
import styles from "./ItemSheetApp.module.scss";
|
||||||
|
|
||||||
export function ItemSheetApp({ item }: { item: any }) {
|
export function ItemSheetApp({ item }: { item: Item.Implementation }) {
|
||||||
const system = item.system;
|
const system = item.system;
|
||||||
|
|
||||||
const updateQuantity = (value: number) => {
|
const updateQuantity = (value: number) => {
|
||||||
item.update({ "system.quantity": value });
|
item.update({ system: { quantity: value } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateDescription = (value: string) => {
|
const updateDescription = (value: string) => {
|
||||||
item.update({ "system.description": value });
|
item.update({ system: { description: value } });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -10,22 +10,25 @@ export class ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
|
|||||||
|
|
||||||
#root: Root | null = null;
|
#root: Root | null = null;
|
||||||
|
|
||||||
async _prepareContext(_options: unknown) {
|
override async _renderHTML(
|
||||||
return { document: this.document };
|
...args: Parameters<foundry.applications.sheets.ItemSheetV2["_renderHTML"]>
|
||||||
|
) {
|
||||||
|
return args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
async _renderHTML(context: unknown, _options: unknown) {
|
override _replaceHTML(
|
||||||
return context;
|
...args: Parameters<foundry.applications.sheets.ItemSheetV2["_replaceHTML"]>
|
||||||
}
|
) {
|
||||||
|
const content = args[1];
|
||||||
_replaceHTML(_result: unknown, content: HTMLElement, _options: unknown) {
|
|
||||||
if (!this.#root) this.#root = createRoot(content);
|
if (!this.#root) this.#root = createRoot(content);
|
||||||
this.#root.render(React.createElement(ItemSheetApp, { item: this.document }));
|
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?.unmount();
|
||||||
this.#root = null;
|
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" {
|
declare module "*.module.scss" {
|
||||||
const classes: { readonly [key: string]: string };
|
const classes: { readonly [key: string]: string };
|
||||||
export default classes;
|
export default classes;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"lib": ["ES2022", "DOM"],
|
"lib": ["ES2022", "DOM"],
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleResolution": "Bundler",
|
"moduleResolution": "Bundler",
|
||||||
|
"types": ["fvtt-types"],
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
|||||||
Reference in new issue
Block a user