From 58facf14908d49fe371f7127dd93c6e714e759ca Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Wed, 29 Nov 2023 00:08:19 -0700 Subject: [PATCH] Get the PlayerSheet working and actually saving data, using the data models instead of the template.json --- module/documents/CharacterActor.js | 1 - module/documents/PlayerActor.js | 11 + module/dotdungeon.js | 19 +- module/models/PlayerData.js | 57 +++++ module/sheets/CharacterSheet.js | 26 --- module/sheets/PlayerSheet.mjs | 36 +++ template.bak.json | 209 ++++++++++++++++++ template.json | 194 +--------------- .../char-sheet-mvp/partials/dice_choice.hbs | 11 +- .../actors/char-sheet-mvp/partials/stat.hbs | 2 +- templates/actors/char-sheet-mvp/sheet.hbs | 7 +- 11 files changed, 339 insertions(+), 234 deletions(-) delete mode 100644 module/documents/CharacterActor.js create mode 100644 module/documents/PlayerActor.js create mode 100644 module/models/PlayerData.js delete mode 100644 module/sheets/CharacterSheet.js create mode 100644 module/sheets/PlayerSheet.mjs create mode 100644 template.bak.json diff --git a/module/documents/CharacterActor.js b/module/documents/CharacterActor.js deleted file mode 100644 index a882b43..0000000 --- a/module/documents/CharacterActor.js +++ /dev/null @@ -1 +0,0 @@ -export class CharacterActor extends Actor {} \ No newline at end of file diff --git a/module/documents/PlayerActor.js b/module/documents/PlayerActor.js new file mode 100644 index 0000000..e338b89 --- /dev/null +++ b/module/documents/PlayerActor.js @@ -0,0 +1,11 @@ +export class PlayerActor extends Actor { + prepareData() { + super.prepareData(); + }; + + prepareDerivedData() {}; + + _preparePCData() {}; + + _prepareNPCData() {}; +}; \ No newline at end of file diff --git a/module/dotdungeon.js b/module/dotdungeon.js index 09a1990..eb933c7 100644 --- a/module/dotdungeon.js +++ b/module/dotdungeon.js @@ -1,6 +1,7 @@ // Class imports -import { CharacterActor } from "./documents/CharacterActor.js"; -import { CharacterSheet } from "./sheets/CharacterSheet.js"; +import { PlayerActor } from "./documents/PlayerActor.js"; +import { PlayerSheet } from "./sheets/PlayerSheet.mjs"; +import { PlayerData } from "./models/PlayerData.js"; // Utility imports import * as hbs from "./handlebars.js"; @@ -9,17 +10,19 @@ import * as hbs from "./handlebars.js"; import "./hooks/hotReload.js"; -Hooks.once(`init`, async () => { +Hooks.once(`init`, () => { + console.log(`.dungeon | Init hook started`) game.boilerplate = { - CharacterActor, + PlayerActor, }; + CONFIG.Actor.systemDataModels.player = PlayerData; Actors.unregisterSheet("core", ActorSheet); - Actors.registerSheet("dotdungeon", CharacterSheet, { makeDefault: true, }); + // Actors.registerSheet("dotdungeon", CharacterSheet, { makeDefault: true, }); + Actors.registerSheet("dotdungeon.player", PlayerSheet, { makeDefault: true }); - - await hbs.registerHandlebarsHelpers(); - await hbs.preloadHandlebarsTemplates() + hbs.registerHandlebarsHelpers(); + hbs.preloadHandlebarsTemplates(); console.info(`.dungeon | Dot Dungeon has been initialized fully`); }); diff --git a/module/models/PlayerData.js b/module/models/PlayerData.js new file mode 100644 index 0000000..8e9d3f6 --- /dev/null +++ b/module/models/PlayerData.js @@ -0,0 +1,57 @@ +export class PlayerData extends foundry.abstract.DataModel { + static defineSchema() { + const fields = foundry.data.fields; + return { + stats: new fields.SchemaField({ + build: new fields.StringField({ + blank: true, + trim: true, + options(...args) { + console.log(`build args`, args); + return [ `d4`, `d6`, `d8`, `d10`, `d12`, `d20` ]; + }, + }), + meta: new fields.StringField({ + blank: true, + trim: true, + options(...args) { + console.log(args); + return [ `d4`, `d6`, `d8`, `d10`, `d12`, `d20` ]; + }, + }), + presence: new fields.StringField({ + blank: true, + trim: true, + options(...args) { + console.log(args); + return [ `d4`, `d6`, `d8`, `d10`, `d12`, `d20` ]; + }, + }), + hands: new fields.StringField({ + blank: true, + trim: true, + options(...args) { + console.log(args); + return [ `d4`, `d6`, `d8`, `d10`, `d12`, `d20` ]; + }, + }), + tilt: new fields.StringField({ + blank: true, + trim: true, + options(...args) { + console.log(args); + return [ `d4`, `d6`, `d8`, `d10`, `d12`, `d20` ]; + }, + }), + rng: new fields.StringField({ + blank: true, + trim: true, + options(...args) { + console.log(args); + return [ `d4`, `d6`, `d8`, `d10`, `d12`, `d20` ]; + }, + }), + }), + }; + }; +}; \ No newline at end of file diff --git a/module/sheets/CharacterSheet.js b/module/sheets/CharacterSheet.js deleted file mode 100644 index d4e69d2..0000000 --- a/module/sheets/CharacterSheet.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Extend the basic ActorSheet with some very simple modifications - * @extends {ActorSheet} - */ -export class CharacterSheet extends ActorSheet { - static get defaultOptions() { - let opts = mergeObject( - super.defaultOptions, - { - template: "systems/dotdungeon/templates/actors/char-sheet-mvp/sheet.hbs" - } - ); - opts.classes.push("dotdungeon"); - return opts; - }; - - activateListeners(html) { - super.activateListeners(html); - - if (!this.isEditable) return; - console.debug(`.dungeon | Adding event listeners for Actor${this.id}`) - - // Modal openings - html.find(`button.stat-prompt`).on("click", () => {}); - } -} \ No newline at end of file diff --git a/module/sheets/PlayerSheet.mjs b/module/sheets/PlayerSheet.mjs new file mode 100644 index 0000000..26e01cd --- /dev/null +++ b/module/sheets/PlayerSheet.mjs @@ -0,0 +1,36 @@ +export class PlayerSheet extends ActorSheet { + static get defaultOptions() { + let opts = mergeObject( + super.defaultOptions, + { + template: "systems/dotdungeon/templates/actors/char-sheet-mvp/sheet.hbs" + } + ); + opts.classes.push("dotdungeon"); + return opts; + }; + + activateListeners(html) { + super.activateListeners(html); + + if (!this.isEditable) return; + console.debug(`.dungeon | Adding event listeners for Actor: ${this.id}`); + + // Modal openings + // html.find(`button.stat-prompt`).on("click", () => {}); + }; + + getData() { + const ctx = super.getData(); + const actor = this.actor.toObject(false); + + ctx.system = actor.system; + ctx.flags = actor.flags; + + console.group(`PlayerSheet.getData`); + console.log(`ctx`, ctx); + console.log(`actor`, actor); + console.groupEnd(); + return ctx; + }; +} \ No newline at end of file diff --git a/template.bak.json b/template.bak.json new file mode 100644 index 0000000..7a0b395 --- /dev/null +++ b/template.bak.json @@ -0,0 +1,209 @@ +{ + "Actor": { + "types": [ + "npc", + "pc", + "mob" + ], + "templates": { + "common": { + "bytes": { + "value": 0, + "min": 0 + } + }, + "sync":{ + "value": 100, + "max": 100, + "min": 0 + } + }, + "NPC": { + "templates": [ + "common" + ] + }, + "PC": { + "templates": [ + "common", + "sync" + ], + "stats": { + "build": "", + "meta": "", + "presence": "", + "hands": "", + "tilt": "", + "rng": "" + }, + "skills": { + "build": { + "defense": "untrained", + "magic": "untrained", + "melee": "untrained", + "platforming": "untrained", + "strength": "untrained" + }, + "meta": { + "alchemy": "untrained", + "arcanum": "untrained", + "dreams": "untrained", + "lore": "untrained", + "navigation": "untrained" + }, + "presence": { + "animalHandling": "untrained", + "perception": "untrained", + "sneak": "untrained", + "speech": "untrained", + "vibes": "untrained" + }, + "hands": { + "accuracy": "untrained", + "crafting": "untrained", + "engineering": "untrained", + "explosives": "untrained", + "piloting": "untrained" + } + }, + "aspect": { + "name": "", + "description": "" + }, + "roles": [ + { + "name": "", + "description": "" + }, + { + "name": "", + "description": "" + }, + { + "name": "", + "description": "" + }, + { + "name": "", + "description": "" + } + ], + "weapon": { + "name": "", + "damage": "", + "quivers": { + "value": 0, + "min": 0, + "max": 5 + }, + "mags": { + "value": 0, + "min": 0, + "max": 5 + }, + "cells": { + "value": 0, + "min": 0, + "max": 5 + } + }, + "inventory": { + "backpack": [], + "bytes": { + "value": 0, + "min": 0 + }, + "supplies": { + "value": 0, + "min": 0, + "max": 5 + }, + "materials": { + "value": 0, + "min": 0, + "max": 5 + }, + "pet": {}, + "transport": {}, + "spells": {} + } + }, + "Mob": { + "templates": [] + } + }, + "Item": { + "types": [ + "weapon", + "armour", + "equipment", + "foil", + "pet", + "transportation", + "structure", + "service", + "legendaryItem", + "spell" + ], + "templates": { + "common": { + "name": "", + "rarity": "simple", + "cost": { + "min": 0, + "value": 0 + } + } + }, + "weapon": { + "templates": [ + "common" + ] + }, + "Armor": { + "templates": [ + "common" + ] + }, + "Equipment": { + "templates": [ + "common" + ] + }, + "foil": { + "templates": [ + "common" + ] + }, + "pet": { + "templates": [ + "common" + ] + }, + "transportation": { + "templates": [ + "common" + ] + }, + "structure": { + "templates": [ + "common" + ] + }, + "service": { + "templates": [ + "common" + ] + }, + "legendaryItem": { + "templates": [ + "common" + ] + }, + "spell": { + "templates": [ + "common" + ] + } + } +} \ No newline at end of file diff --git a/template.json b/template.json index e2c44a2..c72924f 100644 --- a/template.json +++ b/template.json @@ -1,136 +1,8 @@ { "Actor": { "types": [ - "NPC", - "PC", - "Mob" - ], - "templates": { - "common": { - "bytes": { - "value": 0, - "min": 0 - } - }, - "sync":{ - "value": 100, - "max": 100, - "min": 0 - } - }, - "NPC": { - "templates": [ - "common" - ] - }, - "PC": { - "templates": [ - "common", - "sync" - ], - "stats": { - "build": "", - "meta": "", - "presence": "", - "hands": "", - "tilt": "", - "rng": "" - }, - "skills": { - "build": { - "defense": "untrained", - "magic": "untrained", - "melee": "untrained", - "platforming": "untrained", - "strength": "untrained" - }, - "meta": { - "alchemy": "untrained", - "arcanum": "untrained", - "dreams": "untrained", - "lore": "untrained", - "navigation": "untrained" - }, - "presence": { - "animalHandling": "untrained", - "perception": "untrained", - "sneak": "untrained", - "speech": "untrained", - "vibes": "untrained" - }, - "hands": { - "accuracy": "untrained", - "crafting": "untrained", - "engineering": "untrained", - "explosives": "untrained", - "piloting": "untrained" - } - }, - "aspect": { - "name": "", - "description": "" - }, - "roles": [ - { - "name": "", - "description": "" - }, - { - "name": "", - "description": "" - }, - { - "name": "", - "description": "" - }, - { - "name": "", - "description": "" - } - ], - "weapon": { - "name": "", - "damage": "", - "quivers": { - "value": 0, - "min": 0, - "max": 5 - }, - "mags": { - "value": 0, - "min": 0, - "max": 5 - }, - "cells": { - "value": 0, - "min": 0, - "max": 5 - } - }, - "inventory": { - "backpack": [], - "bytes": { - "value": 0, - "min": 0 - }, - "supplies": { - "value": 0, - "min": 0, - "max": 5 - }, - "materials": { - "value": 0, - "min": 0, - "max": 5 - }, - "pet": {}, - "transport": {}, - "spells": {} - } - }, - "Mob": { - "templates": [] - } + "player" + ] }, "Item": { "types": [ @@ -144,66 +16,6 @@ "service", "legendaryItem", "spell" - ], - "templates": { - "common": { - "name": "", - "rarity": "simple", - "cost": { - "min": 0, - "value": 0 - } - } - }, - "weapon": { - "templates": [ - "common" - ] - }, - "Armor": { - "templates": [ - "common" - ] - }, - "Equipment": { - "templates": [ - "common" - ] - }, - "foil": { - "templates": [ - "common" - ] - }, - "pet": { - "templates": [ - "common" - ] - }, - "transportation": { - "templates": [ - "common" - ] - }, - "structure": { - "templates": [ - "common" - ] - }, - "service": { - "templates": [ - "common" - ] - }, - "legendaryItem": { - "templates": [ - "common" - ] - }, - "spell": { - "templates": [ - "common" - ] - } + ] } } \ No newline at end of file diff --git a/templates/actors/char-sheet-mvp/partials/dice_choice.hbs b/templates/actors/char-sheet-mvp/partials/dice_choice.hbs index e5e2fde..4c73c9c 100644 --- a/templates/actors/char-sheet-mvp/partials/dice_choice.hbs +++ b/templates/actors/char-sheet-mvp/partials/dice_choice.hbs @@ -1,5 +1,8 @@ - + {{#select selected}} + + {{#each (dotdungeon-array "d4" "d6" "d8" "d10" "d12" "d20")}} + + {{/each}} + {{/select}} \ 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 index 98acd0b..ad29f6f 100644 --- a/templates/actors/char-sheet-mvp/partials/stat.hbs +++ b/templates/actors/char-sheet-mvp/partials/stat.hbs @@ -2,5 +2,5 @@ - {{> dotdungeon.dice_choice }} + {{> dotdungeon.dice_choice fieldToUpdate=(concat "system.stats." name) selected=value }} \ No newline at end of file diff --git a/templates/actors/char-sheet-mvp/sheet.hbs b/templates/actors/char-sheet-mvp/sheet.hbs index e71bb4b..ecfaefa 100644 --- a/templates/actors/char-sheet-mvp/sheet.hbs +++ b/templates/actors/char-sheet-mvp/sheet.hbs @@ -1,14 +1,15 @@
+ {{log system}} {{#> dotdungeon.panel class="avatar" title="dotdungeon.panel.avatar"}} Avatar Content {{/ dotdungeon.panel}} {{#> dotdungeon.panel class="stats" title="dotdungeon.panel.statistics"}} - {{#each (dotdungeon-array "build" "meta" "presence" "hands" "tilt" "rng")}} - {{> dotdungeon.stat name=this}} + {{#each system.stats }} + {{> dotdungeon.stat name=@key value=this}} {{/each}} {{/ dotdungeon.panel}} {{#> dotdungeon.panel class="skills" title="dotdungeon.panel.skills"}} - {{> dotdungeon.skills }} + Skills {{/ dotdungeon.panel}} {{#> dotdungeon.panel class="backpack" title="dotdungeon.panel.backpack"}} Backpack