From e5c1cfec970289996b28843ceb84362fdf110113 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Tue, 21 Nov 2023 22:59:22 -0700 Subject: [PATCH] Minimal working example for a character sheet --- dotdungeon.mjs | 10 ------ langs/en-ca.json | 10 +++++- module/documents/CharacterActor.js | 1 + module/dotdungeon.js | 25 +++++++++++++++ module/handlebars.js | 32 +++++++++++++++++++ module/sheets/{pc.mjs => CharacterSheet.js} | 4 +-- system.json | 6 ++-- .../char-sheet-mvp/partials/dice_choice.hbs | 5 +++ .../actors/char-sheet-mvp/partials/stat.hbs | 4 +++ templates/actors/char-sheet-mvp/sheet.hbs | 9 ++++++ templates/actors/character-sheet-mvp.hbs | 16 ---------- 11 files changed, 91 insertions(+), 31 deletions(-) delete mode 100644 dotdungeon.mjs create mode 100644 module/documents/CharacterActor.js create mode 100644 module/dotdungeon.js create mode 100644 module/handlebars.js rename module/sheets/{pc.mjs => CharacterSheet.js} (66%) create mode 100644 templates/actors/char-sheet-mvp/partials/dice_choice.hbs create mode 100644 templates/actors/char-sheet-mvp/partials/stat.hbs create mode 100644 templates/actors/char-sheet-mvp/sheet.hbs delete mode 100644 templates/actors/character-sheet-mvp.hbs diff --git a/dotdungeon.mjs b/dotdungeon.mjs deleted file mode 100644 index 0f19649..0000000 --- a/dotdungeon.mjs +++ /dev/null @@ -1,10 +0,0 @@ -import ActorSheetPC from "./module/sheets/pc.mjs"; - -console.log(`.dungeon | hello from dotdungeon.mjs`) -Hooks.once(`init`, async () => { - Actors.registerSheet("dotdungeon-pug", ActorSheetPC, { - types: ["pc", "pug"], - makeDefault: true, - canBeDefault: true, - }); -}) \ No newline at end of file diff --git a/langs/en-ca.json b/langs/en-ca.json index 9e26dfe..8d620ee 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -1 +1,9 @@ -{} \ No newline at end of file +{ + "stat.title": "Stats", + "stat.build": "Build", + "stat.meta": "Meta", + "stat.presence": "Presence", + "stat.hands": "Hands", + "stat.tilt": "Tilt", + "stat.rng": "RNG" +} \ No newline at end of file diff --git a/module/documents/CharacterActor.js b/module/documents/CharacterActor.js new file mode 100644 index 0000000..a882b43 --- /dev/null +++ b/module/documents/CharacterActor.js @@ -0,0 +1 @@ +export class CharacterActor extends Actor {} \ No newline at end of file diff --git a/module/dotdungeon.js b/module/dotdungeon.js new file mode 100644 index 0000000..7175981 --- /dev/null +++ b/module/dotdungeon.js @@ -0,0 +1,25 @@ +import { CharacterActor } from "./documents/CharacterActor.js"; +import { CharacterSheet } from "./sheets/CharacterSheet.js"; + +import * as hbs from "./handlebars.js"; + +// import diceChoice from "../templates/actors/char-sheet-mvp/partials/dice_choice.hbs?raw"; + +Hooks.once(`init`, async function () { + game.boilerplate = { + CharacterActor, + }; + + Actors.unregisterSheet("core", ActorSheet); + Actors.registerSheet("dotdungeon", CharacterSheet, { makeDefault: true, }); + + + await hbs.registerHandlebarsHelpers(); + await hbs.preloadHandlebarsTemplates() + console.info(`.dungeon | Dot Dungeon has been initialized fully`); +}); + + +Hooks.once(`ready`, function() { + console.info(".dungeon | Ready"); +}); \ No newline at end of file diff --git a/module/handlebars.js b/module/handlebars.js new file mode 100644 index 0000000..3e58ebe --- /dev/null +++ b/module/handlebars.js @@ -0,0 +1,32 @@ +export async function registerHandlebarsHelpers() { + Handlebars.registerHelper({ + "dotdungeon-array": createArray + }); +}; + +export async function preloadHandlebarsTemplates() { + console.groupCollapsed(`.dungeon | Handlebars template loading`) + const pathPrefix = `systems/dotdungeon/templates/`; + const partials = [ + "actors/char-sheet-mvp/partials/dice_choice.hbs", + "actors/char-sheet-mvp/partials/stat.hbs", + ]; + + const paths = {}; + + for ( const partial of partials ) { + console.debug(`Loading partial: ${partial}`); + const path = `${pathPrefix}${partial}`; + paths[path] = path; + paths[`dotdungeon.${path.split("/").pop().replace(".hbs", "")}`] = path; + } + + console.debug(`Loaded ${partials.length} partials`); + console.groupEnd(); + return loadTemplates(paths); +}; + + +function createArray(...args) { + return args.slice(0, -1); +}; \ No newline at end of file diff --git a/module/sheets/pc.mjs b/module/sheets/CharacterSheet.js similarity index 66% rename from module/sheets/pc.mjs rename to module/sheets/CharacterSheet.js index 452b4f7..fa25ddc 100644 --- a/module/sheets/pc.mjs +++ b/module/sheets/CharacterSheet.js @@ -2,13 +2,13 @@ * Extend the basic ActorSheet with some very simple modifications * @extends {ActorSheet} */ -export class ActorSheetPC extends ActorSheet { +export class CharacterSheet extends ActorSheet { static get defaultOptions() { return mergeObject( super.defaultOptions, { classes: ["dotdungeon", "sheet", "actor"], - template: "systems/dotdungeon/templates/actors/character-sheet-mvp.hbs" + template: "systems/dotdungeon/templates/actors/char-sheet-mvp/sheet.hbs" } ); }; diff --git a/system.json b/system.json index cedbcf1..8c8c4a8 100644 --- a/system.json +++ b/system.json @@ -16,9 +16,11 @@ ], "url": "https://github.com/Oliver-Akins/foundry.dungeon", "esmodules": [ - "dotdungeon.mjs" + "module/dotdungeon.js" + ], + "styles": [ + ".css/root.css" ], - "styles": [], "languages": [ { "lang": "en", diff --git a/templates/actors/char-sheet-mvp/partials/dice_choice.hbs b/templates/actors/char-sheet-mvp/partials/dice_choice.hbs new file mode 100644 index 0000000..e5e2fde --- /dev/null +++ b/templates/actors/char-sheet-mvp/partials/dice_choice.hbs @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/templates/actors/char-sheet-mvp/partials/stat.hbs b/templates/actors/char-sheet-mvp/partials/stat.hbs new file mode 100644 index 0000000..284a044 --- /dev/null +++ b/templates/actors/char-sheet-mvp/partials/stat.hbs @@ -0,0 +1,4 @@ +
+ + {{> dotdungeon.dice_choice }} +
\ No newline at end of file diff --git a/templates/actors/char-sheet-mvp/sheet.hbs b/templates/actors/char-sheet-mvp/sheet.hbs new file mode 100644 index 0000000..ba8e291 --- /dev/null +++ b/templates/actors/char-sheet-mvp/sheet.hbs @@ -0,0 +1,9 @@ +
+

{{localize "stat.title"}}

+ {{> dotdungeon.stat stat="build" }} + {{> dotdungeon.stat stat="meta" }} + {{> dotdungeon.stat stat="presence" }} + {{> dotdungeon.stat stat="hands" }} + {{> dotdungeon.stat stat="tilt" }} + {{> dotdungeon.stat stat="rng" }} +
\ No newline at end of file diff --git a/templates/actors/character-sheet-mvp.hbs b/templates/actors/character-sheet-mvp.hbs deleted file mode 100644 index b4c913f..0000000 --- a/templates/actors/character-sheet-mvp.hbs +++ /dev/null @@ -1,16 +0,0 @@ -
- Build: -
- Meta: -
- Presence: -
- Hands: -
- Tilt: -
- RNG: -
-
- Respawns: [ ] [ ] [ ] -
\ No newline at end of file