diff --git a/CHANGELOG.md b/CHANGELOG.md index f490f4c..a3fea39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Changelog +## 2.5.1.0 +- Fixed an issue with a setting not loading correctly. +- Moved settings related to death into its own category. +- Aggregated the four "Only show estimations to" settings into a single setting. + ## 2.5.0.4 - Added support to Star Wars FFG. diff --git a/lang/en.json b/lang/en.json index 121e04c..3169721 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1,21 +1,16 @@ { "healthEstimate": { "core": { - "onlyGM": { - "name": "GM only", - "hint": "Only show estimations to GM." - }, - "onlyNotGM": { - "name": "Players only", - "hint": "Only show estimations to players." - }, - "onlyNPCs": { - "name": "NPCs only", - "hint": "Only show estimations for NPCs, but not for player characters. This setting only affects players." - }, - "onlyPCs": { - "name": "PCs only", - "hint": "Only show estimations for PCs, but not for non-player characters. This setting only affects players." + "showDescription": { + "name": "Show Estimates", + "hint": "Show estimates to the selected users.", + "choices": { + "all": "All", + "GM": "Only to GM", + "Players": "Only to Players", + "NPC": "Only to Players (NPC estimates only)", + "PC": "Only to Players (PC estimates only)" + } }, "stateNames": { "name": "Stages", diff --git a/lang/pt-BR.json b/lang/pt-BR.json index 8b42688..0904be4 100644 --- a/lang/pt-BR.json +++ b/lang/pt-BR.json @@ -1,21 +1,16 @@ { "healthEstimate": { "core": { - "onlyGM": { - "name": "Apenas o Mestre", - "hint": "Mostra os descritores somente ao Mestre." - }, - "onlyNotGM": { - "name": "Apenas os jogadores", - "hint": "Mostra os descritores somente aos jogadores." - }, - "onlyNPCs": { - "name": "Apenas NPCs", - "hint": "Mostra os descritores somente dos NPCs. Esta configuração afeta apenas aos jogadores." - }, - "onlyPCs": { - "name": "Apenas PJs", - "hint": "Mostra os descritores somente dos PJs. Esta configuração afeta apenas aos jogadores." + "showDescription": { + "name": "Mostrar Estimativas", + "hint": "Mostra as estimativas para os usuários selecionados.", + "choices": { + "all": "Todos", + "GM": "Apenas para o Mestre", + "Players": "Apenas para Jogadores", + "NPC": "Apenas para Jogadores (Apenas estiamtivas de NPC)", + "PC": "Apenas para Jogadores (Apenas estiamtivas de PJ)" + } }, "stateNames": { "name": "Estágios", @@ -35,7 +30,7 @@ }, "deathStateName": { "name": "Descritor de morte", - "hint": "O descritor mostrado quando o personagem está morto. A guia Compendium possui uma macro para marcar um token (ou vários) como morto.", + "hint": "O descritor mostrado quando o personagem está morto. A aba Pacotes de Compêndio possui uma macro para marcar tokens como mortos.", "default": "Morto" }, "deathMarker": { diff --git a/module.json b/module.json index 5019172..9ab690e 100644 --- a/module.json +++ b/module.json @@ -2,7 +2,7 @@ "name": "healthEstimate", "title": "Health Estimate 2", "description": "Gives players ability to see approximate health status of a token", - "version": "2.5.0.4", + "version": "2.5.1.0", "author": "MClemente, Shylight", "scripts": [ "./lib/chroma.min.js", diff --git a/module/deathSettings.js b/module/deathSettings.js new file mode 100644 index 0000000..63e97e4 --- /dev/null +++ b/module/deathSettings.js @@ -0,0 +1,57 @@ +import {sGet, sSet, settingData} from './utils.js' +import {updateSettings} from './logic.js' + +export class HealthEstimateDeathSettings extends FormApplication { + + constructor (object, options = {}) { + super(object, options) + this.gradFn = new Function() + this.gradColors = [] + } + + /** + * Default Options for this FormApplication + */ + static get defaultOptions () { + return mergeObject(super.defaultOptions, { + id : 'healthestimate-death-form', + title : 'Health Estimate Death Settings', + template : './modules/healthEstimate/templates/deathSettings.hbs', + classes : ['sheet'], + width : 640, + height : "auto", + closeOnSubmit: true + }) + } + + getData (options) { + + function prepSetting (key) { + let data = settingData(`core.${key}`) + return { + value: sGet(`core.${key}`), + name : data.name, + hint : data.hint + } + } + + return { + deathState : prepSetting('deathState'), + deathStateName : prepSetting('deathStateName'), + NPCsJustDie : prepSetting('NPCsJustDie'), + deathMarker : prepSetting('deathMarker'), + } + } + + /** + * Executes on form submission + * @param {Event} e - the form submission event + * @param {Object} d - the form data + */ + async _updateObject(e,d) { + const iterableSettings = Object.keys(d); + for (let key of iterableSettings) { + sSet(`core.${key}`, d[key]); + } + } +} \ No newline at end of file diff --git a/module/settings.js b/module/settings.js index ef99d80..dd9a901 100644 --- a/module/settings.js +++ b/module/settings.js @@ -1,7 +1,8 @@ import {t} from './utils.js' -import {systemSpecificSettings, updateBreakSettings} from './systemSpecifics.js' +import {updateBreakSettings} from './systemSpecifics.js' import {updateSettings} from './logic.js' import {HealthEstimateStyleSettings} from './styleSettings.js' +import {HealthEstimateDeathSettings} from './deathSettings.js' /** * Shorthand for addSetting. @@ -44,73 +45,81 @@ export const registerSettings = function () { type: HealthEstimateStyleSettings, restricted: true }) - + game.settings.registerMenu('healthEstimate', 'deathSettings', { + name: 'Death Settings', + label: 'Death Settings', + icon: 'fas fa-skull', + type: HealthEstimateDeathSettings, + restricted: true + }) /* Settings for the main settings menu */ - addSetting('core.onlyGM', { - type: Boolean, - default: false, + addSetting('core.showDescription', { + type: Number, + default: 0, + choices: { + 0 : t('core.showDescription.choices.all'), + 1 : t('core.showDescription.choices.GM'), + 2 : t('core.showDescription.choices.Players'), + 3 : t('core.showDescription.choices.NPC'), + 4 : t('core.showDescription.choices.PC') + }, onChange: () => { updateBreakSettings() } }) - addSetting('core.onlyNotGM', { - type: Boolean, - default: false, - onChange: () => { - updateBreakSettings() + addSetting('core.stateNames', { + type: String, + default: t('core.stateNames.default').join(', '), + onChange: s => { + updateSettings() } }) - addSetting('core.onlyNPCs', { + addSetting('core.perfectionism', { type: Boolean, default: false, - onChange: () => { - updateBreakSettings() + onChange: s => { + updateSettings() } }) - addSetting('core.onlyPCs', { + addSetting('core.outputChat', { type: Boolean, default: false, - onChange: () => { - updateBreakSettings() + onChange: s => { + updateSettings() } }) - addSetting('core.stateNames', { - type: String, - default: t('core.stateNames.default').join(', '), - onChange: s => { + + /* Settings for the death menu */ + addMenuSetting('core.deathState', { + 'type' : Boolean, + 'default': false, + onChange : s => { updateSettings() } }) - addSetting('core.deathStateName', { + addMenuSetting('core.deathStateName', { type: String, default: t('core.deathStateName.default'), onChange: s => { updateSettings() } }) - addSetting('core.NPCsJustDie', { + addMenuSetting('core.NPCsJustDie', { type: Boolean, default: true, onChange: s => { updateSettings() } }) - addSetting('core.perfectionism', { - type: Boolean, - default: false, - onChange: s => { - updateSettings() - } - }) - addSetting('core.outputChat', { - type: Boolean, - default: false, + addMenuSetting('core.deathMarker', { + type : String, + default : 'icons/svg/skull.svg', onChange: s => { updateSettings() } }) - + /* Settings for the custom menu */ addMenuSetting('core.menuSettings.useColor', { diff --git a/module/styleSettings.js b/module/styleSettings.js index 31b0777..e728386 100644 --- a/module/styleSettings.js +++ b/module/styleSettings.js @@ -5,7 +5,7 @@ export class HealthEstimateStyleSettings extends FormApplication { constructor (object, options = {}) { super(object, options) - this.gradFn = new Function() + this.gradFn = new Function() this.gradColors = [] Hooks.once('renderHealthEstimateStyleSettings', this.initHooks.bind(this)) Hooks.once('closeHealthEstimateStyleSettings', () => { @@ -18,30 +18,30 @@ export class HealthEstimateStyleSettings extends FormApplication { */ static get defaultOptions () { return mergeObject(super.defaultOptions, { - id : 'healthestimate-style-form', - title : 'Health Estimate Style Settings', - template : './modules/healthEstimate/templates/settings.hbs', - classes : ['sheet'], - width : 640, - height : 480, + id : 'healthestimate-style-form', + title : 'Health Estimate Style Settings', + template : './modules/healthEstimate/templates/settings.hbs', + classes : ['sheet'], + width : 640, + height : "auto", closeOnSubmit: true }) } getData (options) { function prepSelection (key, param = false) { - const path = `core.menuSettings.${key}` - let data = settingData(path) + const path = `core.menuSettings.${key}` + let data = settingData(path) let current = '' - let result = { + let result = { select: [], - name : data.name, - hint : data.hint + name : data.name, + hint : data.hint } if (param) { let currentObject = sGet(path) - current = currentObject[param] + current = currentObject[param] // for (let [k, v] of Object.entries((currentObject))) { // result[k] = v // } @@ -52,8 +52,8 @@ export class HealthEstimateStyleSettings extends FormApplication { for (let [k, v] of Object.entries(data.choices)) { result.select.push({ - key : k, - value : v, + key : k, + value : v, selected: k === current }) } @@ -62,7 +62,7 @@ export class HealthEstimateStyleSettings extends FormApplication { function prepSetting (key) { const path = `core.menuSettings.${key}` - let data = settingData(path) + let data = settingData(path) return { value: sGet(path), name : data.name, @@ -71,43 +71,43 @@ export class HealthEstimateStyleSettings extends FormApplication { } return { - useColor : prepSetting('useColor'), - smoothGradient : prepSetting('smoothGradient'), - deadColor : prepSetting('deadColor'), - fontSize : prepSetting('fontSize'), + useColor : prepSetting('useColor'), + smoothGradient : prepSetting('smoothGradient'), + deadColor : prepSetting('deadColor'), + fontSize : prepSetting('fontSize'), positionAdjustment: prepSetting('positionAdjustment'), - position : prepSelection('position'), - mode : prepSelection('mode'), - outline : prepSelection('outline', 'mode') + position : prepSelection('position'), + mode : prepSelection('mode'), + outline : prepSelection('outline', 'mode') } } initHooks () { const gradientPositions = game.settings.get(`healthEstimate`, `core.menuSettings.gradient`) - const mode = document.getElementById(`mode`) + const mode = document.getElementById(`mode`) - this.deadColor = document.getElementById('deadColor') + this.deadColor = document.getElementById('deadColor') this.deadColor.value = sGet('core.menuSettings.deadColor') - this.deadOutline = sGet('core.variables.deadOutline') + this.deadOutline = sGet('core.variables.deadOutline') - // this.deadColor = sGet('core.menuSettings.deadColor') - this.outlineMode = document.getElementById('outlineMode') - this.outlineIntensity = document.getElementById('outlineIntensity') - this.fontSize = document.getElementById('fontSize') - this.textPosition = document.getElementById('position') + // this.deadColor = sGet('core.menuSettings.deadColor') + this.outlineMode = document.getElementById('outlineMode') + this.outlineIntensity = document.getElementById('outlineIntensity') + this.fontSize = document.getElementById('fontSize') + this.textPosition = document.getElementById('position') this.positionAdjustment = document.getElementById('positionAdjustment') - this.smoothGradient = document.getElementById('smoothGradient') - this.gradEx = document.getElementById('gradientExampleHE') + this.smoothGradient = document.getElementById('smoothGradient') + this.gradEx = document.getElementById('gradientExampleHE') this.gp = new Grapick({ - el : '#gradientControlsHE', + el : '#gradientControlsHE', colorEl: '' }) this.gp.setColorPicker(handler => { const el = handler.getEl().querySelector('#colorpicker') $(el).spectrum({ - color : handler.getColor(), + color : handler.getColor(), showAlpha: true, change (color) { handler.setColor(color.toRgbString()) @@ -124,7 +124,7 @@ export class HealthEstimateStyleSettings extends FormApplication { $(this.deadColor).spectrum({ // color: sGet('core.menuSettings.deadColor'), preferredFormat: 'hex', - move : function (color) { + move : function (color) { this.deadColor.value = color.toHexString() this.updateSample() }.bind(this), @@ -158,7 +158,7 @@ export class HealthEstimateStyleSettings extends FormApplication { } updateGradientFunction () { - const mode = document.getElementById(`mode`).value + const mode = document.getElementById(`mode`).value const colorHandler = mode === 'bez' ? `bezier(colors).scale()` : `scale(colors).mode('${mode}')` this.gradFn = new Function( @@ -171,7 +171,7 @@ export class HealthEstimateStyleSettings extends FormApplication { } updateOutlineFunction () { const outlineHandler = this.outlineMode.value - const outlineAmount = this.outlineIntensity.value + const outlineAmount = this.outlineIntensity.value this.outlFn = new Function( 'color=false', @@ -188,13 +188,13 @@ export class HealthEstimateStyleSettings extends FormApplication { } updateGradient () { - const colors = this.gp.handlers.map(a => a.color) + const colors = this.gp.handlers.map(a => a.color) const colorPositions = this.gp.handlers.map(a => Math.round(a.position) / 100) - this.gradLength = this.smoothGradient.checked ? 100 : sGet('core.stateNames').split(/[,;]\s*/).length - const width = 100 / this.gradLength - this.gradColors = this.gradFn(this.gradLength, colors, colorPositions) - this.outlColors = this.outlFn() - let gradString = '' + this.gradLength = this.smoothGradient.checked ? 100 : sGet('core.stateNames').split(/[,;]\s*/).length + const width = 100 / this.gradLength + this.gradColors = this.gradFn(this.gradLength, colors, colorPositions) + this.outlColors = this.outlFn() + let gradString = '' for (let i = 0; i < this.gradLength; i++) { gradString += @@ -211,7 +211,7 @@ export class HealthEstimateStyleSettings extends FormApplication { } updateSample () { - const sample = document.getElementById('healthEstimateSample') + const sample = document.getElementById('healthEstimateSample') const sampleItems = sample.children[0].children this.deadOutline = this.outlFn(this.deadColor.value) @@ -223,7 +223,7 @@ export class HealthEstimateStyleSettings extends FormApplication { sampleItems[0].style.setProperty('--healthEstimate-stroke-color', this.deadOutline) for (let i = 1; i <= 6; i++) { - const position = Math.max(Math.round(this.gradLength * ((i-1) / 5))-1, 0) + const position = Math.max(Math.round(this.gradLength * ((i-1) / 5))-1, 0) sampleItems[i].style.setProperty('--healthEstimate-text-color', this.gradColors[position]) sampleItems[i].style.setProperty('--healthEstimate-stroke-color', this.outlColors[position]) diff --git a/module/systemSpecifics.js b/module/systemSpecifics.js index 09a4c3e..bcf5bcc 100644 --- a/module/systemSpecifics.js +++ b/module/systemSpecifics.js @@ -4,22 +4,6 @@ import {updateSettings} from './logic.js' export let fractionFormula export let breakOverlayRender -export let systemSpecificSettings = { - 'core.deathState' : { - 'type' : Boolean, - 'default': false, - onChange : s => { - updateSettings() - }, - }, - 'core.deathMarker': { - type : String, - default : 'icons/svg/skull.svg', - onChange: s => { - updateSettings() - }, - }, -} /** * Function handling which description to show. Can be overriden by a system-specific implementation @@ -76,10 +60,10 @@ function updateBreakConditions () { } export function updateBreakSettings () { - breakConditions['onlyGM'] = sGet('core.onlyGM') ? `|| !game.user.isGM` : `` - breakConditions['onlyNotGM'] = sGet('core.onlyNotGM') ? `|| game.user.isGM` : `` - breakConditions['onlyNPCs'] = sGet('core.onlyNPCs') ? `|| (!game.user.isGM && token.actor.hasPlayerOwner)` : `` - breakConditions['onlyPCs'] = sGet('core.onlyPCs') ? `|| (!game.user.isGM && !token.actor.hasPlayerOwner)` : `` + breakConditions['onlyGM'] = sGet('core.showDescription') == 1 ? `|| !game.user.isGM` : `` + breakConditions['onlyNotGM'] = sGet('core.showDescription') == 2 ? `|| game.user.isGM` : `` + breakConditions['onlyNPCs'] = sGet('core.showDescription') == 3 ? `|| (!game.user.isGM && token.actor.hasPlayerOwner)` : `` + breakConditions['onlyPCs'] = sGet('core.showDescription') == 4 ? `|| (!game.user.isGM && !token.actor.hasPlayerOwner)` : `` updateBreakConditions() } @@ -93,23 +77,12 @@ export function prepareSystemSpecifics () { import(importString) .then(currentSystem => { fractionFormula = currentSystem.fraction - if (currentSystem.settings !== undefined) { - /* - * currentSystem.settings is a function because doing it otherwise causes - * l18n calls fire before they're initialized. - */ - systemSpecificSettings = Object.assign(systemSpecificSettings, currentSystem.settings()) - } if (currentSystem.breakCondition !== undefined) { breakConditions['system'] = currentSystem.breakCondition } if (currentSystem.descriptions !== undefined) { descriptionToShow = currentSystem.descriptions } - - for (let [key, data] of Object.entries(systemSpecificSettings)) { - addSetting(key, data) - } resolve('success') }) }) diff --git a/templates/deathSettings.hbs b/templates/deathSettings.hbs new file mode 100644 index 0000000..9c8710f --- /dev/null +++ b/templates/deathSettings.hbs @@ -0,0 +1,38 @@ +
+
+ {{#with deathState}} + + +

{{localize hint}}

+ {{/with}} +
+
+ {{#with deathStateName}} + + +

{{localize hint}}

+ {{/with}} +
+
+ {{#with NPCsJustDie}} + + +

{{localize hint}}

+ {{/with}} +
+
+ {{#with deathMarker}} + + +

{{localize hint}}

+ {{/with}} +
+ +
\ No newline at end of file diff --git a/templates/settings.hbs b/templates/settings.hbs index 3a727a3..bc1f5f4 100644 --- a/templates/settings.hbs +++ b/templates/settings.hbs @@ -85,13 +85,7 @@ -
- -