initial commit
This commit is contained in:
commit
3cdd4eb0d0
16 files changed
+2080
No files matched your search
@@ -0,0 +1,13 @@
|
||||
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 })
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
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 })
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import React from "react";
|
||||
import { createRoot, type Root } from "react-dom/client";
|
||||
import { CharacterSheetApp } from "./components/CharacterSheetApp";
|
||||
|
||||
export class CharacterSheet extends foundry.applications.sheets.ActorSheetV2 {
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ["newsystem", "sheet", "actor"],
|
||||
position: { width: 600, height: 480 }
|
||||
};
|
||||
|
||||
#root: Root | null = null;
|
||||
|
||||
async _prepareContext(_options: unknown) {
|
||||
return { document: this.document };
|
||||
}
|
||||
|
||||
async _renderHTML(context: unknown, _options: unknown) {
|
||||
return context;
|
||||
}
|
||||
|
||||
_replaceHTML(_result: unknown, content: HTMLElement, _options: unknown) {
|
||||
if (!this.#root) this.#root = createRoot(content);
|
||||
this.#root.render(React.createElement(CharacterSheetApp, { actor: this.document }));
|
||||
}
|
||||
|
||||
async close(options: unknown) {
|
||||
this.#root?.unmount();
|
||||
this.#root = null;
|
||||
return super.close(options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import React from "react";
|
||||
|
||||
const modifier = (score: number) => Math.floor((score - 10) / 2);
|
||||
const fmtMod = (mod: number) => (mod >= 0 ? `+${mod}` : `${mod}`);
|
||||
|
||||
export function CharacterSheetApp({ actor }: { actor: any }) {
|
||||
const system = actor.system;
|
||||
const attrs = system.attributes;
|
||||
|
||||
const updateAttribute = (key: string, value: number) => {
|
||||
actor.update({ [`system.attributes.${key}`]: value });
|
||||
};
|
||||
|
||||
const updateBiography = (value: string) => {
|
||||
actor.update({ "system.biography": value });
|
||||
};
|
||||
|
||||
// derived purely from current doc state — recomputed every render, no local state needed
|
||||
const total = attrs.strength + attrs.agility + attrs.spirit;
|
||||
const totalMod = modifier(attrs.strength) + modifier(attrs.agility) + modifier(attrs.spirit);
|
||||
|
||||
return (
|
||||
<div className="newsystem character-sheet">
|
||||
<h1>{actor.name}</h1>
|
||||
<div className="attributes">
|
||||
{(["strength", "agility", "spirit"] as const).map((key) => (
|
||||
<label key={key}>
|
||||
{key}
|
||||
<input
|
||||
type="number"
|
||||
value={attrs[key]}
|
||||
onChange={(e) => updateAttribute(key, Number(e.target.value))}
|
||||
/>
|
||||
<span className="modifier">{fmtMod(modifier(attrs[key]))}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<div className="totals">
|
||||
<span>Total: {total}</span>
|
||||
<span>Total mod: {fmtMod(totalMod)}</span>
|
||||
</div>
|
||||
<label>
|
||||
Biography
|
||||
<textarea
|
||||
defaultValue={system.biography}
|
||||
onBlur={(e) => updateBiography(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import React from "react";
|
||||
|
||||
export function ItemSheetApp({ item }: { item: any }) {
|
||||
const system = item.system;
|
||||
|
||||
const updateQuantity = (value: number) => {
|
||||
item.update({ "system.quantity": value });
|
||||
};
|
||||
|
||||
const updateDescription = (value: string) => {
|
||||
item.update({ "system.description": value });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="newsystem item-sheet">
|
||||
<h1>{item.name}</h1>
|
||||
<label>
|
||||
Quantity
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={system.quantity}
|
||||
onChange={(e) => updateQuantity(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Description
|
||||
<textarea
|
||||
defaultValue={system.description}
|
||||
onBlur={(e) => updateDescription(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import React from "react";
|
||||
import { createRoot, type Root } from "react-dom/client";
|
||||
import { ItemSheetApp } from "./components/ItemSheetApp";
|
||||
|
||||
export class ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ["newsystem", "sheet", "item"],
|
||||
position: { width: 480, height: 360 }
|
||||
};
|
||||
|
||||
#root: Root | null = null;
|
||||
|
||||
async _prepareContext(_options: unknown) {
|
||||
return { document: this.document };
|
||||
}
|
||||
|
||||
async _renderHTML(context: unknown, _options: unknown) {
|
||||
return context;
|
||||
}
|
||||
|
||||
_replaceHTML(_result: unknown, content: HTMLElement, _options: unknown) {
|
||||
if (!this.#root) this.#root = createRoot(content);
|
||||
this.#root.render(React.createElement(ItemSheetApp, { item: this.document }));
|
||||
}
|
||||
|
||||
async close(options: unknown) {
|
||||
this.#root?.unmount();
|
||||
this.#root = null;
|
||||
return super.close(options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
.newsystem.character-sheet,
|
||||
.newsystem.item-sheet {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.newsystem .attributes {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.newsystem label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
font-size: 0.8rem;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.newsystem .modifier {
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.newsystem .totals {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import "./styles/main.css";
|
||||
import { CharacterData } from "./data/character-data";
|
||||
import { ItemData } from "./data/item-data";
|
||||
import { CharacterSheet } from "./sheets/character-sheet";
|
||||
import { ItemSheet } from "./sheets/item-sheet";
|
||||
|
||||
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
|
||||
});
|
||||
});
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// 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;
|
||||
Reference in new issue
Block a user