An generic system template for Svelte foundry systems
This system is compatible with v13+ only, as unfortunately v12's ui code was so painful I just did not want to deal with it.
Who might you thank?
The package will (ideally) be available directly via the foundry vtt module installer, under the id MY_SYSTEM_ID.
Alternatively, it can be installed via the manifest url:
https://github.com/MY_GITHUB/MY_SYSTEM_ID/releases/latest/download/system.json
How might people contribute?
Is accomplished by github actions. You must configure
Settings -> Secrets and variables -> Actions -> PACKAGE_TOKEN
to be the one provided by the foundry portal
The project can be built and run locally via the following steps.
- To link the developer build directory to the
npm run buildln -s $(pwd)/dist /path/to/vtt/data/Data/systems/MY_SYSTEM_ID - Perform an initial
npm ciandnpm run buildto populate the dist directory. This will also need to be run to populate any asset files stored in the public directory, if you should ever change those. - As a start to setup, replace all instances of the following strings with appropriate values:
- MY_SYSTEM_ID -> dnd5e, or whatever
- MY_SYSTEM_CONSTS -> DND5E, or whatever
- MY_GITHUB -> whitespine, or whatever
- Then, to run the vite development server, edit
vite.config.jsto match whatever port you are running foundry on on your local machine. While running, all code changes should be hot (or at least lukewarm) reloaded in the vite proxy server.
To add a new actor / item:
- Modify
public/template.jsonto include it in the "Actor"."types" field- For biography and other rich text fields, augment "htmlFields"
- Modify
public/languages/en.jsonto properly name the type in "TYPES" - Add an appropriate new svelte component to
src/components/sheets- This is what will be rendered in the sheet. Do whatever structure you like!
- Add a new sheet class to
src/sheets/ActorSheet.jsorsrc/sheets/ItemSheet.js - Add proper registration of new sheet to
src/sheets/config.js - Add a new model class to
src/modelsextending the appropriate supertype - Add proper model registration of new model to
src/models/config.js
To show a generic svelte component (say, a welcome window, a damage calculator, whatever), you can use the GenericComponentApp in src/apps/generic_app.js, supplying
- The class of the svelte component as the first argument
- Initial props of the svelte component as the second argument This should be fine for most cases that don't need custom toolbar buttons etcetera
To override a sidebar tab
- Add a line to
Hooks.once('init', async function ()insrc/system.mjs- EX:
CONFIG.ui.combat = CustomCombatTracker; - The specific
CONFIG.uiproperty will depend on the tab you are editing
- EX:
- The sidebar tab should slot in automagically
To add a new sidebar tab, e.x. a dedicated region for face cams
- TODO: Polish this more
- Add a new CustomSidebarTab class
export class CustomSidebarTab extends SvelteApplicationMixin(foundry.applications.sidebar.AbstractSidebarTab) {
static DEFAULT_OPTIONS = {
window: {
title: "Whatever"
},
svelte: {
component: CustomSidebarComponent
},
classes: ["MY_SYSTEM_ID"]
}
static tabName = "whatever";
async _prepareContext() {
// Yield some state
return {
"foo": "bar"
};
}
}
export class CustomSidebarTab extends foundry.applications.sidebar.AbstractSidebarTab {
static DEFAULT_OPTIONS = {
window: {
title: "Whatever"
},
svelte: {
component: CustomSidebarComponent
},
classes: ["MY_SYSTEM_ID"]
}
static tabName = "whatever";
async _prepareContext() {
// Yield some state
return {
"foo": "bar"
};
}
}- Add a new custom sidebar class to override the base behavior
class CustomSidebar extends SvelteApplicationMixin(foundry.applications.sidebar.AbstractSidebarTab) {
getData(options={}) {
let base = super.getData(options);
base.tabs.custom = {
tooltip: "foo",
icon: "bar"
}
return base;
}
}- Register it:
CONFIG.ui.sidebar = CustomSidebar
To override combat logic
- Follow above sidebar logic with the following caveats
- Edit
src/system.mjsto no longer commentCONFIG.ui.combat = CustomCombatTracker;
- Edit
- Edit
src/documents/token.jsto not comment out_refreshTurnMarker - In the above, correct logic to properly decide when to / when not to show a turn marker
- Edit
src/documents/combat.jsto include combat rules- The links therein should have most of what you need as examples on how to do this
src/consts.jsadd a new constant to thesocketssub object representing your new socket eventsrc/utils/socket.svelte.jsmodify initSockets to handle your new constant with a special handler
What do you need help with?