Turn boilerplate into a maintained, documented template

Rename newsystem -> fvtt-ts-react-boilerplate, install fvtt-types for
real typing throughout (DataModelConfig augmentation, typed sheet
overrides), wire up i18n (lang/en.json was an empty directory and
fr.json was empty), add MIT license, eslint/prettier/vitest tooling,
GitHub Actions CI, and extensive docs/ covering the architecture,
adding content, styling, localization, testing, and how to rename
this again for a new system.
This commit is contained in:
unknown committed 2026-06-22 23:21:53 +02:00
1 parent 98a7a2d774
commit 9568be0211
28 files changed
+5383 -58

No files matched your search

+18 -3
View File
@@ -3,9 +3,24 @@ function defineSchema() {
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 })
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
})
})
};
}
+7 -1
View File
@@ -2,7 +2,13 @@ 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 })
quantity: new fields.NumberField({
required: true,
nullable: false,
integer: true,
initial: 1,
min: 0
})
};
}
+3
View File
@@ -0,0 +1,3 @@
// `game` isn't ready until the "ready" hook fires; sheets only render after that,
// so the non-null assertion here is safe and keeps callers from repeating it.
export const localize = (key: string) => game.i18n!.localize(key);
+2 -4
View File
@@ -4,7 +4,7 @@ import { CharacterSheetApp } from "./components/CharacterSheetApp";
export class CharacterSheet extends foundry.applications.sheets.ActorSheetV2 {
static DEFAULT_OPTIONS = {
classes: ["newsystem", "sheet", "actor"],
classes: ["fvtt-ts-react-boilerplate", "sheet", "actor"],
position: { width: 600, height: 480 }
};
@@ -24,9 +24,7 @@ export class CharacterSheet extends foundry.applications.sheets.ActorSheetV2 {
this.#root.render(React.createElement(CharacterSheetApp, { actor: this.document }));
}
override async close(
...args: Parameters<foundry.applications.sheets.ActorSheetV2["close"]>
) {
override async close(...args: Parameters<foundry.applications.sheets.ActorSheetV2["close"]>) {
this.#root?.unmount();
this.#root = null;
return super.close(...args);
@@ -0,0 +1,23 @@
import { describe, expect, it } from "vitest";
import { fmtMod, modifier } from "./CharacterSheetApp.logic";
describe("modifier", () => {
it("matches the d20-style table around the 10 baseline", () => {
expect(modifier(10)).toBe(0);
expect(modifier(11)).toBe(0);
expect(modifier(12)).toBe(1);
expect(modifier(9)).toBe(-1);
expect(modifier(20)).toBe(5);
});
});
describe("fmtMod", () => {
it("prefixes non-negative values with +", () => {
expect(fmtMod(0)).toBe("+0");
expect(fmtMod(3)).toBe("+3");
});
it("leaves negative values as-is", () => {
expect(fmtMod(-2)).toBe("-2");
});
});
@@ -0,0 +1,6 @@
// Pure game-logic helpers, deliberately kept free of any Foundry global.
// Code that touches `actor`/`ChatMessage`/etc. needs a running Foundry instance
// and isn't realistically unit-testable — this is the boundary to keep that out.
export const modifier = (score: number) => Math.floor((score - 10) / 2);
export const fmtMod = (mod: number) => (mod >= 0 ? `+${mod}` : `${mod}`);
@@ -35,4 +35,4 @@
input {
flex: 1;
}
}
}
+13 -13
View File
@@ -1,8 +1,7 @@
import React, { useState } from "react";
import styles from "./CharacterSheetApp.module.scss";
const modifier = (score: number) => Math.floor((score - 10) / 2);
const fmtMod = (mod: number) => (mod >= 0 ? `+${mod}` : `${mod}`);
import { localize } from "../../i18n";
import { modifier, fmtMod } from "./CharacterSheetApp.logic";
export function CharacterSheetApp({ actor }: { actor: Actor.Implementation }) {
const system = actor.system;
@@ -36,7 +35,7 @@ export function CharacterSheetApp({ actor }: { actor: Actor.Implementation }) {
<div className={styles.attributes}>
{(["strength", "agility", "spirit"] as const).map((key) => (
<label className={styles.attributeLabel} key={key}>
{key}
{localize(`BOILERPLATE.Attributes.${key}`)}
<input
type="number"
value={attrs[key]}
@@ -47,27 +46,28 @@ export function CharacterSheetApp({ actor }: { actor: Actor.Implementation }) {
))}
</div>
<div className={styles.totals}>
<span>Total: {total}</span>
<span>Total mod: {fmtMod(totalMod)}</span>
<span>
{localize("BOILERPLATE.Sheet.Total")}: {total}
</span>
<span>
{localize("BOILERPLATE.Sheet.TotalMod")}: {fmtMod(totalMod)}
</span>
</div>
<label className={styles.attributeLabel}>
Biography
<textarea
defaultValue={system.biography}
onBlur={(e) => updateBiography(e.target.value)}
/>
{localize("BOILERPLATE.Sheet.Biography")}
<textarea defaultValue={system.biography} onBlur={(e) => updateBiography(e.target.value)} />
</label>
<div className={styles.chatRow}>
<input
type="text"
placeholder="Say something..."
placeholder={localize("BOILERPLATE.Sheet.ChatPlaceholder")}
value={chatMessage}
onChange={(e) => setChatMessage(e.target.value)}
onKeyDown={(e) => e.key === "Enter" && sendChatMessage()}
/>
<button type="button" onClick={sendChatMessage}>
Send to chat
{localize("BOILERPLATE.Sheet.SendToChat")}
</button>
</div>
</div>
+3 -2
View File
@@ -1,5 +1,6 @@
import React from "react";
import styles from "./ItemSheetApp.module.scss";
import { localize } from "../../i18n";
export function ItemSheetApp({ item }: { item: Item.Implementation }) {
const system = item.system;
@@ -16,7 +17,7 @@ export function ItemSheetApp({ item }: { item: Item.Implementation }) {
<div className={styles.sheet}>
<h1>{item.name}</h1>
<label className={styles.label}>
Quantity
{localize("BOILERPLATE.Item.Quantity")}
<input
type="number"
min={0}
@@ -25,7 +26,7 @@ export function ItemSheetApp({ item }: { item: Item.Implementation }) {
/>
</label>
<label className={styles.label}>
Description
{localize("BOILERPLATE.Item.Description")}
<textarea
defaultValue={system.description}
onBlur={(e) => updateDescription(e.target.value)}
+2 -4
View File
@@ -4,7 +4,7 @@ import { ItemSheetApp } from "./components/ItemSheetApp";
export class ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
static DEFAULT_OPTIONS = {
classes: ["newsystem", "sheet", "item"],
classes: ["fvtt-ts-react-boilerplate", "sheet", "item"],
position: { width: 480, height: 360 }
};
@@ -24,9 +24,7 @@ export class ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
this.#root.render(React.createElement(ItemSheetApp, { item: this.document }));
}
override async close(
...args: Parameters<foundry.applications.sheets.ItemSheetV2["close"]>
) {
override async close(...args: Parameters<foundry.applications.sheets.ItemSheetV2["close"]>) {
this.#root?.unmount();
this.#root = null;
return super.close(...args);
+18 -8
View File
@@ -7,12 +7,22 @@ Hooks.once("init", () => {
CONFIG.Actor.dataModels.character = CharacterData;
CONFIG.Item.dataModels.item = ItemData;
foundry.applications.apps.DocumentSheetConfig.registerSheet(Actor, "newsystem", CharacterSheet, {
types: ["character"],
makeDefault: true
});
foundry.applications.apps.DocumentSheetConfig.registerSheet(Item, "newsystem", ItemSheet, {
types: ["item"],
makeDefault: true
});
foundry.applications.apps.DocumentSheetConfig.registerSheet(
Actor,
"fvtt-ts-react-boilerplate",
CharacterSheet,
{
types: ["character"],
makeDefault: true
}
);
foundry.applications.apps.DocumentSheetConfig.registerSheet(
Item,
"fvtt-ts-react-boilerplate",
ItemSheet,
{
types: ["item"],
makeDefault: true
}
);
});