Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Shylight committed Nov 9, 2020
2 parents f340dbf + a6e1fc2 commit 8978587
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 39 deletions.
3 changes: 2 additions & 1 deletion dist/healthEstimate.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
--healthEstimate-text-size : x-large;
--healthEstimate-alignment : start;
--healthEstimate-margin : -1em;
--healthEstimate-width : 100px;
}

.healthEstimate {
Expand All @@ -14,7 +15,7 @@
align-content : var(--healthEstimate-alignment);
justify-content : unsafe center;
margin-top : var(--healthEstimate-margin);
width : 100%;
width : var(--healthEstimate-width) !important;
}

.healthEstimateColor {
Expand Down
2 changes: 1 addition & 1 deletion dist/lang/en.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"healthEstimate":{"core":{"onlyGM":{"name":"GM only","hint":"Only show estimations to GM."},"onlyNPCs":{"name":"NPCs only","hint":"Only show estimations for NPCs, but not for player characters."},"stateNames":{"name":"Stages","hint":"An array of descriptions shown to players, arranged from worst to best possible health.\nThe amount of possible descriptions is not limited, the module will adjust the health percentage to show them proportionally to the amount.\nIf there is a need for one description to cover a higher range of health than others simply copy it several times.","default":["Unconscious","Near Death","Badly Injured","Injured","Barely Injured","Uninjured"]},"deathState":{"name":"Death State on Condition","hint":"Show token as dead when it's been marked with specific condition. Works independently from the macro."},"deathStateName":{"name":"Death State Name","hint":"The description shown to players when the token is dead. Compendium tab has a macro for marking a token (or several) as dead.","default":"Dead"},"deathMarker":{"name":"Death Marker","hint":"Path to the condition icon that marks the dead tokens.\nTo get a custom icon's path, select a token marked with it, open the console and enter \"canvas.tokens.controlled[0].data.overlayEffect\""},"NPCsJustDie":{"name":"NPCs die immediately","hint":"With this setting on the lowest option in normal description list won't be shown for NPCs, they'll be shown as dead instead."},"addTemp":{"name":"Add Temporary Health","hint":"Include temporary health points in calculating what description to show.\nE.g. with the setting turned on the token receiving temp HP will look \"healthier\" unless it's already at max health."},"breakOnZeroMaxHP":{"name":"Hide on tokens with 0 max HP","hint":"Useful for objects with tokens"},"menuSettings":{"fontSize":{"name":"Font Size","hint":"Accepts any valid property for CSS font-size"},"useColor":{"name":"Use Color","hint":"This won't affect the settings window, but with checkmark off the descriptions will be shown in black and white."},"smoothGradient":{"name":"Smooth Gradient","hint":"With this setting off the color will only change when the next description is reached, with it on it will reflect the health percentage."},"deadColor":{"name":"Color of dead tokens"},"outline":{"name":"Outline","darken":"Darken","brighten":"Brighten"},"position":{"name":"Position","top":"Top","middle":"Middle","bottom":"Bottom"},"positionAdjustment":{"name":"Position Adjustment","hint":"Position is set relative to the frame. The number lets you tweak the position relative to its normal place. Positive numbers push it lower, negative – higher. The default value of -1 sets it to \"1 line above initial position\"."}}},"PF1":{"showExtra":{"name":"Disabled & Dying","hint":"Show \"Disabled\" and \"Dying\" descriptions"},"disabledName":{"name":"Disabled","hint":"Description to show when token is precisely at 0 HP","default":"Disabled"},"dyingName":{"name":"Dying","hint":"Description to show when token is below 0 HP","default":"Dying"}},"numenera":{"countPools":{"name":"Count Empty Pools","hint":"Count empty pools instead of sum of their values, with the estimation only changing when a pool is depleted/replenished"}},"starfinder":{"useThreshold":{"name":"Use Vehicle Threshold","hint":"If this setting is on, the \"Threshold Stages\" descriptions will be used for vehicles above threshold, below it, and at 0 HP respectively."},"thresholdNames":{"name":"Threshold Stages","hint":"The amount of stages is limited to 3, arranged from worst to best condition","default":["Wrecked","Broken","Fully Functional"]},"vehicleNames":{"name":"Vehicle Stages","hint":"Descriptions shown for starships (always), and vehicles (if \"Use Vehicle Threshold\" is off)","default":["Wrecked","Flaming","Smoking","Battered","Scratched","Pristine"]},"addStamina":{"name":"Account for Stamina","hint":"With this setting on Stamina will be added to HP for calculations."}},"worldbuilding":{"simpleRule":{"name":"Estimation Rule","hint":"The JS formula for calculating the fraction of health token has. Alter with caution. Default assumes simple descending health, e.g. you start with 10/10 in your health field and go down to 0/10 when taking damage.","default":"const hp = token.actor.data.data.health; return hp.value / hp.max"}}}}
{"healthEstimate":{"core":{"onlyGM":{"name":"GM only","hint":"Only show estimations to GM."},"onlyNPCs":{"name":"NPCs only","hint":"Only show estimations for NPCs, but not for player characters."},"stateNames":{"name":"Stages","hint":"An array of descriptions shown to players, arranged from worst to best possible health.\nThe amount of possible descriptions is not limited, the module will adjust the health percentage to show them proportionally to the amount.\nIf there is a need for one description to cover a higher range of health than others simply copy it several times.","default":["Unconscious","Near Death","Badly Injured","Injured","Barely Injured","Uninjured"]},"deathState":{"name":"Death State on Condition","hint":"Show token as dead when it's been marked with specific condition. Works independently from the macro."},"deathStateName":{"name":"Death State Name","hint":"The description shown to players when the token is dead. Compendium tab has a macro for marking a token (or several) as dead.","default":"Dead"},"deathMarker":{"name":"Death Marker","hint":"Path to the condition icon that marks the dead tokens.\nTo get a custom icon's path, select a token marked with it, open the console and enter \"canvas.tokens.controlled[0].data.overlayEffect\""},"NPCsJustDie":{"name":"NPCs die immediately","hint":"With this setting on the lowest option in normal description list won't be shown for NPCs, they'll be shown as dead instead."},"addTemp":{"name":"Add Temporary Health","hint":"Include temporary health points in calculating what description to show.\nE.g. with the setting turned on the token receiving temp HP will look \"healthier\" unless it's already at max health."},"breakOnZeroMaxHP":{"name":"Hide on tokens with 0 max HP","hint":"Useful for objects with tokens"},"menuSettings":{"fontSize":{"name":"Font Size","hint":"Accepts any valid property for CSS font-size"},"useColor":{"name":"Use Color","hint":"This won't affect the settings window, but with checkmark off the descriptions will be shown in black and white."},"smoothGradient":{"name":"Smooth Gradient","hint":"With this setting off the color will only change when the next description is reached, with it on it will reflect the health percentage."},"deadColor":{"name":"Color of dead tokens"},"outline":{"name":"Outline","darken":"Darken","brighten":"Brighten"},"position":{"name":"Position","top":"Top","middle":"Middle","bottom":"Bottom"},"positionAdjustment":{"name":"Position Adjustment","hint":"Position is set relative to the frame. The number lets you tweak the position relative to its normal place. Positive numbers push it lower, negative – higher. The default value of -1 sets it to \"1 line above initial position\"."}}},"dnd5e":{"vehicleNames":{"hint":"Descriptions shown for vehicles if \"Use Vehicle Threshold\" is off","default":["Wrecked","Broken","Battered","Scratched","Pristine"]}},"PF1":{"showExtra":{"name":"Disabled & Dying","hint":"Show \"Disabled\" and \"Dying\" descriptions"},"disabledName":{"name":"Disabled","hint":"Description to show when token is precisely at 0 HP","default":"Disabled"},"dyingName":{"name":"Dying","hint":"Description to show when token is below 0 HP","default":"Dying"}},"numenera":{"countPools":{"name":"Count Empty Pools","hint":"Count empty pools instead of sum of their values, with the estimation only changing when a pool is depleted/replenished"}},"starfinder":{"useThreshold":{"name":"Use Vehicle Threshold","hint":"If this setting is on, the \"Threshold Stages\" descriptions will be used for vehicles above threshold, below it, and at 0 HP respectively."},"thresholdNames":{"name":"Threshold Stages","hint":"The amount of stages is limited to 3, arranged from worst to best condition","default":["Wrecked","Broken","Fully Functional"]},"vehicleNames":{"name":"Vehicle Stages","hint":"Descriptions shown for starships (always), and vehicles (if \"Use Vehicle Threshold\" is off)","default":["Wrecked","Flaming","Smoking","Battered","Scratched","Pristine"]},"addStamina":{"name":"Account for Stamina","hint":"With this setting on Stamina will be added to HP for calculations."}},"worldbuilding":{"simpleRule":{"name":"Estimation Rule","hint":"The JS formula for calculating the fraction of health token has. Alter with caution. Default assumes simple descending health, e.g. you start with 10/10 in your health field and go down to 0/10 when taking damage.","default":"const hp = token.actor.data.data.health; return hp.value / hp.max"}}}}
5 changes: 3 additions & 2 deletions dist/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "healthEstimate",
"title": "Health Estimate",
"description": "Gives players ability to see approximate health status of a token",
"version": "2.0.3",
"version": "2.1.0",
"author": "Shylight",
"scripts": [
"./lib/chroma.min.js",
Expand Down Expand Up @@ -52,6 +52,7 @@
"archmage",
"dungeonworld",
"fate",
"lancer",
"numenera",
"pf1",
"pf2e",
Expand All @@ -69,6 +70,6 @@
"compatibleCoreVersion": "0.7.6",
"url": "https://github.com/Shylight/healthEstimate",
"manifest": "https://raw.githubusercontent.com/Shylight/healthEstimate/master/src/module.json",
"download": "https://raw.githubusercontent.com/Shylight/healthEstimate/2.0.3/package/healthEstimate-v2.0.3.zip",
"download": "https://raw.githubusercontent.com/Shylight/healthEstimate/2.1.0/package/healthEstimate-v2.1.0.zip",
"license": "https://choosealicense.com/licenses/mit/"
}
33 changes: 18 additions & 15 deletions dist/module/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ let descriptions, deathStateName, showDead, useColor, smooth, isDead, NPCsJustDi

export function updateSettings () {
useColor = sGet('core.menuSettings.useColor')
descriptions = sGet('core.stateNames').split(/[,;]\s*/)
smooth = sGet('core.menuSettings.smoothGradient')
deathStateName = sGet('core.deathStateName')
showDead = sGet('core.deathState')
NPCsJustDie = sGet('core.NPCsJustDie')
deathMarker = sGet('core.deathMarker')
colors = sGet('core.variables.colors')[0]
outline = sGet('core.variables.outline')[0]
deadColor = sGet('core.variables.deadColor')
deadOutline = sGet('core.variables.deadOutline')
descriptions = sGet('core.stateNames').split(/[,;]\s*/)
smooth = sGet('core.menuSettings.smoothGradient')
deathStateName = sGet('core.deathStateName')
showDead = sGet('core.deathState')
NPCsJustDie = sGet('core.NPCsJustDie')
deathMarker = sGet('core.deathMarker')
colors = sGet('core.variables.colors')[0]
outline = sGet('core.variables.outline')[0]
deadColor = sGet('core.variables.deadColor')
deadOutline = sGet('core.variables.deadOutline')

const margin = `${sGet('core.menuSettings.positionAdjustment')}em`
const margin = `${sGet('core.menuSettings.positionAdjustment')}em`
const alignment = sGet('core.menuSettings.position')
document.documentElement.style.setProperty('--healthEstimate-margin', margin)
document.documentElement.style.setProperty('--healthEstimate-alignment', alignment)
Expand Down Expand Up @@ -79,6 +79,9 @@ export class HealthEstimate {
if (breakOverlayRender(token)) {
return
}
const width = `${canvas.scene.data.grid * token.data.width}px`
document.documentElement.style.setProperty('--healthEstimate-width', width)

if (hovered) {
this._getEstimation(token)
canvas.hud.HealthEstimate.bind(token)
Expand All @@ -88,13 +91,13 @@ export class HealthEstimate {
}

_getEstimation (token) {
const fraction = Math.min(fractionFormula(token), 1)
const stage = Math.max(0, Math.ceil((descriptions.length - 1) * fraction))
const fraction = Math.min(fractionFormula(token), 1)
const stage = Math.max(0, Math.ceil((descriptions.length - 1) * fraction))
const colorIndex = Math.max(0, Math.ceil((colors.length - 1) * fraction))
let desc, color, stroke

desc = descriptionToShow(descriptions, stage, token, {isDead: isDead(token, stage), desc: deathStateName})
color = colors[colorIndex]
desc = descriptionToShow(descriptions, stage, token, {isDead: isDead(token, stage), desc: deathStateName}, fraction)
color = colors[colorIndex]
stroke = outline[colorIndex]
if (isDead(token, stage)) {
color = deadColor
Expand Down
3 changes: 2 additions & 1 deletion dist/module/systemSpecifics.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export let descriptionToShow = function
descriptions,
stage,
token,
state = {isDead: false, desc: ''}
state = {isDead: false, desc: ''},
fraction
) {
if (state.isDead) {
return state.desc
Expand Down
2 changes: 2 additions & 0 deletions dist/module/systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as bitd from './systems/blades-in-the-dark.js'
import * as dnd5e from './systems/dnd5e.js'
import * as dungeonworld from './systems/dungeonworld.js'
import * as fate from './systems/fate.js'
import * as lancer from './systems/lancer.js'
import * as numenera from './systems/numenera.js'
import * as pf1 from './systems/pf1.js'
import * as pf2e from './systems/pf2e.js'
Expand All @@ -22,6 +23,7 @@ export {
dnd5e,
dungeonworld,
fate,
lancer,
numenera,
pf1,
pf2e,
Expand Down
47 changes: 41 additions & 6 deletions dist/module/systems/dnd5e.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
import {addTemp, breakOnZeroMaxHP} from './commonSettings.js'
// import {addTemp, breakOnZeroMaxHP} from './commonSettings.js'
import {descriptions} from './starfinder.js'
import {t} from '../utils.js'

const fraction = function (token) {
const hp = token.actor.data.data.attributes.hp
let addTemp = 0
let temp = 0
if (token.actor.data.type === 'vehicle' && game.settings.get('healthEstimate', 'starfinder.useThreshold')){
if (hp.value > hp.dt) {
return 1
} else if (hp.value > 0) {
return 0.5
} else {
return 0
}
}
if (token.actor.data.type === 'character' && game.settings.get('healthEstimate', 'core.addTemp')) {
addTemp = 1
temp = hp.temp
}
return Math.min((temp + hp.value) / hp.max, 1)
}
const settings = () => {
return {
'core.addTemp' : {
type : Boolean,
default: false,
},
'core.breakOnZeroMaxHP' : {
type : Boolean,
default: true,
},
'starfinder.useThreshold' : {
type : Boolean,
default: false,
},
'starfinder.thresholdNames': {
type : String,
default: t('starfinder.thresholdNames.default').join(', '),
},
'starfinder.vehicleNames' : {
type : String,
default: t('dnd5e.vehicleNames.default').join(', '),
hint : t('dnd5e.vehicleNames.hint'),
},
}
return Math.min((hp.temp * addTemp + hp.value) / hp.max, 1)
}
const settings = () => {return Object.assign({}, addTemp, breakOnZeroMaxHP)}

const breakCondition = `||game.settings.get('healthEstimate', 'core.breakOnZeroMaxHP') && token.actor.data.data.attributes.hp.max === 0`

export {fraction, settings, breakCondition}
export {fraction, settings, breakCondition, descriptions}
30 changes: 30 additions & 0 deletions dist/module/systems/lancer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {t} from '../utils.js'

const fraction = (token) => {
const data = token.actor.data
const hp = data.type === 'deployable' ? data.data.hp : data.data.mech.hp
return hp.value / hp.max
}

const settings = () => {
return {
'core.breakOnZeroMaxHP': {
type : Boolean,
default: true,
},
'core.stateNames': {
config : true,
scope : 'world',
type : String,
default: t('starfinder.vehicleNames.default').join(', ')
}
}
}

const breakCondition = `
|| game.settings.get('healthEstimate', 'core.breakOnZeroMaxHP')
&& (token.actor.data.data.mech?.hp.max === 0
|| token.actor.data.data.hp?.max === 0)
`

export {fraction, settings, breakCondition}
63 changes: 56 additions & 7 deletions dist/module/systems/pf2e.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,67 @@
import {t} from '../utils.js'

const fraction = function (token) {
const hp = token.actor.data.data.attributes.hp
let addTemp = 0
if (game.settings.get('healthEstimate', 'core.addTemp')) {
addTemp = 1
const hp = token.actor.data.data.attributes.hp
let temp = 0
if (token.actor.data.type === 'vehicle' && game.settings.get('healthEstimate', 'starfinder.useThreshold')) {
if (hp.value > hp.brokenThreshold) {
return 1
} else if (hp.value > 0) {
return 0.5
} else {
return 0
}
}
if (game.settings.get('healthEstimate', 'core.addTemp') && token.actor.data.type === 'character') {
temp = hp.temp
}
return Math.min((hp.value + (hp.temp * addTemp)) / hp.max, 1)
return Math.min((hp.value + temp) / hp.max, 1)
}
const settings = () => {
return {
'core.addTemp': {
'core.addTemp' : {
type : Boolean,
default: false,
},
'core.breakOnZeroMaxHP' : {
type : Boolean,
default: true,
},
'starfinder.useThreshold' : {
type : Boolean,
default: false,
},
'starfinder.thresholdNames': {
type : String,
default: t('starfinder.thresholdNames.default').join(', '),
},
'starfinder.vehicleNames' : {
type : String,
default: t('dnd5e.vehicleNames.default').join(', '),
hint : t('dnd5e.vehicleNames.hint'),
},
}
}

const descriptions = function (descriptions, stage, token, state = {isDead: false, desc: ''}, fraction) {
if (state.isDead) {
return state.desc
}
const type = token.actor.data.type
if (type === 'vehicle' || type === 'hazard') {
if (type === 'vehicle' && game.settings.get('healthEstimate', 'starfinder.useThreshold')) {
descriptions = game.settings.get('healthEstimate', 'starfinder.thresholdNames').split(/[,;]\s*/)
} else {
descriptions = game.settings.get('healthEstimate', 'starfinder.vehicleNames').split(/[,;]\s*/)
}
stage = Math.max(0, Math.ceil((descriptions.length - 1) * fraction))
}
return descriptions[stage]
}

export {fraction, settings}
const breakCondition = `
|| (game.settings.get('healthEstimate', 'core.breakOnZeroMaxHP') && token.actor.data.data.attributes.hp.max === 0)
|| token.actor.data.type === 'loot'
`

export {fraction, settings, descriptions, breakCondition}
13 changes: 10 additions & 3 deletions dist/module/systems/starfinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const settings = () => {
type : Boolean,
default: false,
},
'core.breakOnZeroMaxHP' : {
type : Boolean,
default: true,
},
'starfinder.addStamina' : {
type : Boolean,
default: true,
Expand All @@ -50,10 +54,10 @@ const settings = () => {
'starfinder.vehicleNames' : {
type : String,
default: t('starfinder.vehicleNames.default').join(', '),
}
},
}
}
const descriptions = function (descriptions, stage, token, state = {isDead: false, desc: ''}) {
const descriptions = function (descriptions, stage, token, state = {isDead: false, desc: ''}, fraction) {
if (state.isDead) {
return state.desc
}
Expand All @@ -64,8 +68,11 @@ const descriptions = function (descriptions, stage, token, state = {isDead: fals
} else {
descriptions = game.settings.get('healthEstimate', 'starfinder.vehicleNames').split(/[,;]\s*/)
}
stage = Math.max(0, Math.ceil((descriptions.length - 1) * fraction))
}
return descriptions[stage]
}

export {fraction, settings, descriptions}
const breakCondition = `||game.settings.get('healthEstimate', 'core.breakOnZeroMaxHP') && token.actor.data.data.attributes.hp.max === 0`

export {fraction, settings, descriptions, breakCondition}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "healthEstimate",
"version": "2.0.3",
"version": "2.1.0",
"description": "",
"scripts": {
"package": "gulp package"
Expand Down
Binary file added package/healthEstimate-v2.1.0.zip
Binary file not shown.
Loading

0 comments on commit 8978587

Please sign in to comment.