initial commit
This commit is contained in:
commit
3cdd4eb0d0
16 files changed
+2080
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
Whitespace-only changes.
Generated
+1732
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "newsystem",
|
||||||
|
"version": "0.8.2",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite build --watch",
|
||||||
|
"build": "vite build"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/react": "^18.3.0",
|
||||||
|
"@types/react-dom": "^18.3.0",
|
||||||
|
"@vitejs/plugin-react": "^4.3.0",
|
||||||
|
"typescript": "^5.6.0",
|
||||||
|
"vite": "^5.4.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"react": "^18.3.0",
|
||||||
|
"react-dom": "^18.3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
"id": "newsystem",
|
||||||
|
"version": "0.8.2",
|
||||||
|
"title": "Newsystem",
|
||||||
|
"url": "",
|
||||||
|
"description": "First edition of Newsystem",
|
||||||
|
"license": "LICENSE.txt",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Nyukhu",
|
||||||
|
"url": "https://foundryvtt.com",
|
||||||
|
"flags": {}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"esmodules": [
|
||||||
|
"dist/system.mjs"
|
||||||
|
],
|
||||||
|
"styles": [
|
||||||
|
"dist/style.css"
|
||||||
|
],
|
||||||
|
"languages": [
|
||||||
|
{
|
||||||
|
"lang": "en",
|
||||||
|
"name": "English",
|
||||||
|
"path": "lang/en.json",
|
||||||
|
"flags": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lang": "fr",
|
||||||
|
"name": "Français",
|
||||||
|
"path": "lang/fr.json",
|
||||||
|
"flags": {}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"documentTypes": {
|
||||||
|
"Actor": {
|
||||||
|
"character": {}
|
||||||
|
},
|
||||||
|
"Item": {
|
||||||
|
"item": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"compatibility": {
|
||||||
|
"minimum": "14",
|
||||||
|
"verified": "14"
|
||||||
|
},
|
||||||
|
"primaryTokenAttribute": "health",
|
||||||
|
"secondaryTokenAttribute": "power",
|
||||||
|
"manifest": "",
|
||||||
|
"download": "",
|
||||||
|
"grid": {
|
||||||
|
"distance": 5,
|
||||||
|
"units": "ft"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"lib": ["ES2022", "DOM"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"isolatedModules": true
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { defineConfig } from "vite";
|
||||||
|
import react from "@vitejs/plugin-react";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react()],
|
||||||
|
define: {
|
||||||
|
"process.env.NODE_ENV": JSON.stringify("production")
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
outDir: "dist",
|
||||||
|
emptyOutDir: true,
|
||||||
|
lib: {
|
||||||
|
entry: "src/system.ts",
|
||||||
|
formats: ["es"],
|
||||||
|
fileName: () => "system.mjs"
|
||||||
|
},
|
||||||
|
rollupOptions: {
|
||||||
|
output: {
|
||||||
|
// single-file bundle, no code-splitting: Foundry loads this one ESM file directly
|
||||||
|
inlineDynamicImports: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in new issue
Block a user