initial commit

This commit is contained in:
unknown committed 2026-06-22 22:15:23 +02:00
commit 3cdd4eb0d0
16 files changed
+2080

No files matched your search

+31
View File
@@ -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>
);
}
+35
View File
@@ -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>
);
}
+31
View File
@@ -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);
}
}