From 6b9a2516d20bd5a31416048de67b824ebc37e30a Mon Sep 17 00:00:00 2001 From: sdenec Date: Tue, 12 Jan 2021 16:33:42 +0100 Subject: [PATCH] 0.4.7 --- changelog.md | 1 + src/scripts/app/settings.js | 110 +++++++++++++++++++++++++++ src/scripts/tidy5e-sheet.js | 29 ++++++- src/templates/settings/settings.html | 32 ++++++++ 4 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 src/templates/settings/settings.html diff --git a/changelog.md b/changelog.md index 363c0ebc..e3f0e5c5 100644 --- a/changelog.md +++ b/changelog.md @@ -16,6 +16,7 @@ Thank you very much! - minor css fix for NPC CR text color - NPC sheets now have a toggle button for the personality infos (now hidden by default) in the biography tab - fix to prevent items sometimes becoming invisible when toggling the item details +- you now can use DAE to set a "custom" formula for data.details.maxSpellPreparation to calculate your available spell preparations thanks @tposney! *Version 0.4.6* - fixed character art popup when pressing enter/return while editing an input field diff --git a/src/scripts/app/settings.js b/src/scripts/app/settings.js index f1f4e6e7..05a68af7 100644 --- a/src/scripts/app/settings.js +++ b/src/scripts/app/settings.js @@ -1,3 +1,113 @@ +export class Tidy5eSettings extends FormApplication { + static init() { + game.settings.registerMenu('tidy5e-sheet', 'menu', { + name: '', + label: 'Sheet Settings', + icon: 'fas fa-scroll', + type: Tidy5eSettings, + restricted: false + }); + +// open a dialogue to reload the window when saving +/* + game.settings.register('tidy5e-sheet', 'world-settings', { + name: 'Settings object for world level markdown editor settings', + type: Object, + default: { + chat: true, + richText: true + }, + config: false, + onChange: () => { + new Dialog({ + content: `

Some settings have changed, that require a refresh of the page to be applied.

`, + buttons: { + yes: { + icon: '', + label: 'Refresh page.', + callback: () => location.reload() + }, + no: { + icon: '', + label: 'I\'ll refresh later.' + } + } + }).render(true); + } + }) +*/ + + game.settings.register('tidy5e-sheet', 'vim-mode', { + name: 'VIM Keybindings', + hint: 'Enable VIM keybindings for the markdown editor. [User Setting]', + scope: 'client', + default: false, + type: Boolean, + restricted: false, + config: true + }); + } + + // settings template + static get defaultOptions() { + return { + ...super.defaultOptions, + template: "modules/tidy5e-sheet/templates/settings/settings.html", + height: "auto", + title: "Tidy5e Sheet - Settings", + width: 600, + classes: ["tidy5e-sheet", "settings"], + tabs: [ + { + navSelector: '.tabs', + contentSelector: 'form', + initial: 'Player Settings' + } + ], + submitOnClose: true + } + } + + static get isRichTextActive() { + const settings = game.settings.get('tidy5e-sheet', 'world-settings'); + return settings.richText; + } + + static get isChatActive() { + const settings = game.settings.get('tidy5e-sheet', 'world-settings'); + return settings.chat; + } + + constructor(object = {}, options) { + super(object, options); + } + + _getHeaderButtons() { + let btns = super._getHeaderButtons(); + btns[0].label = "Save & Close"; + return btns; + } + + getSettingsData() { + return game.settings.get('tidy5e-sheet', 'world-settings'); + } + + getData() { + let data = super.getData(); + data.settings = this.getSettingsData(); + return data; + } + + activateListeners(html) { + super.activateListeners(html); + } + + _updateObject(ev, formData) { + const data = expandObject(formData); + game.settings.set('tidy5e-sheet', 'world-settings', data); + } +} + export const tidy5eSettings = function () { // Classic Item Controls for PC Sheets diff --git a/src/scripts/tidy5e-sheet.js b/src/scripts/tidy5e-sheet.js index 1cf05d31..49d496a1 100644 --- a/src/scripts/tidy5e-sheet.js +++ b/src/scripts/tidy5e-sheet.js @@ -2,6 +2,7 @@ import { DND5E } from "../../../systems/dnd5e/module/config.js"; import ActorSheet5e from "../../../systems/dnd5e/module/actor/sheets/base.js"; import ActorSheet5eCharacter from "../../../systems/dnd5e/module/actor/sheets/character.js"; import { tidy5eSettings } from "./app/settings.js"; +// import { Tidy5eSettings } from './app/settings.js'; import { preloadTidy5eHandlebarsTemplates } from "./app/tidy5e-templates.js"; import { tidy5eListeners } from "./app/listeners.js"; @@ -370,6 +371,30 @@ async function abbreviateCurrency(app,html,data) { }); } +// transform DAE formulas for maxPreparesSpells +function tidyCustomEffect(actor, change) { + if (change.key !== "data.details.maxPreparedSpells") return; + if (change.value?.length > 0) { + let oldValue = getProperty(actor.data, change.key) || 0; + let changeText = change.value.trim(); + let op = "none"; + if (["+","-","/","*","="].includes(changeText[0])) { + op = changeText[0]; + changeText = changeText.slice(1); + } + const value = new Roll(changeText, actor.getRollData()).roll().total; + oldValue = Number.isNumeric(oldValue) ? parseInt(oldValue) : 0; + switch (op) { + case "+": return setProperty(actor.data, change.key, oldValue + value); + case "-": return setProperty(actor.data, change.key, oldValue - value); + case "*": return setProperty(actor.data, change.key, oldValue * value); + case "/": return setProperty(actor.data, change.key, oldValue / value); + case "=": return setProperty(actor.data, change.key, value); + default: return setProperty(actor.data, change.key, value); + } + } +} + // Manage Sheet Options async function setSheetClasses(app, html, data) { let actor = game.actors.entities.find(a => a.data._id === data.actor._id); @@ -436,6 +461,8 @@ async function setSheetClasses(app, html, data) { // Preload tidy5e Handlebars Templates Hooks.once("init", () => { preloadTidy5eHandlebarsTemplates(); + Hooks.on("applyActiveEffect", tidyCustomEffect); + // Tidy5eSettings.init(); }); // Register Tidy5e Sheet and make default character sheet @@ -455,7 +482,7 @@ Hooks.on("renderTidy5eSheet", (app, html, data) => { countAttunedItems(app, html, data); abbreviateCurrency(app,html,data); spellAttackMod(app,html,data); - console.log(data); + // console.log(data); // console.log("Tidy5e Sheet rendered!"); }); diff --git a/src/templates/settings/settings.html b/src/templates/settings/settings.html new file mode 100644 index 00000000..9ef24f4b --- /dev/null +++ b/src/templates/settings/settings.html @@ -0,0 +1,32 @@ +
+ + +
+

General

+ +
+
+

Player Character Sheets

+
+
+

NPC/Vehicle Sheets

+
+
+

GM Sheet Options

+
+
+

Module Info

+
+
\ No newline at end of file