Get the PlayerSheet working and actually saving data, using the data models instead of the template.json

This commit is contained in:
Oliver-Akins 2023-11-29 00:08:19 -07:00
parent 6e3510ddd4
commit 58facf1490
11 changed files with 339 additions and 234 deletions

View file

@ -1 +0,0 @@
export class CharacterActor extends Actor {}

View file

@ -0,0 +1,11 @@
export class PlayerActor extends Actor {
prepareData() {
super.prepareData();
};
prepareDerivedData() {};
_preparePCData() {};
_prepareNPCData() {};
};

View file

@ -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`);
});

View file

@ -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` ];
},
}),
}),
};
};
};

View file

@ -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", () => {});
}
}

View file

@ -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;
};
}

209
template.bak.json Normal file
View file

@ -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"
]
}
}
}

View file

@ -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"
]
}
]
}
}

View file

@ -1,5 +1,8 @@
<select>
{{#each (dotdungeon-array "d4" "d6" "d8" "d10" "d12" "d20")}}
<option value="{{this}}">{{this}}</option>
{{/each}}
<select name="{{fieldToUpdate}}">
{{#select selected}}
<option value="">---</option>
{{#each (dotdungeon-array "d4" "d6" "d8" "d10" "d12" "d20")}}
<option value="{{this}}">{{this}}</option>
{{/each}}
{{/select}}
</select>

View file

@ -2,5 +2,5 @@
<button class="roll-stat" data-stat="{{name}}">
{{localize (concat "dotdungeon.stat." name)}}
</button>
{{> dotdungeon.dice_choice }}
{{> dotdungeon.dice_choice fieldToUpdate=(concat "system.stats." name) selected=value }}
</label>

View file

@ -1,14 +1,15 @@
<form autocomplete="off" class="actor--pc">
{{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