Skip to content

Commit

Permalink
10.2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ironmonk88 committed Sep 14, 2022
1 parent ef7068b commit a745c19
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Version 10.2

Fixing a bug with the defeated status that was preventing a token from healing.

Added the option to change what AlwaysHP does with an unsigned value. Currently a number without a + or minus is treate as negative and will hurt the token. You can now change it so it will assume healing instead.

# Version 10.1

Fixed issues detecting when a token is defeated
Expand Down
38 changes: 22 additions & 16 deletions alwayshp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export let setting = key => {
return game.settings.get("always-hp", key);
};

export let isV10 = () => {
return isNewerVersion(game.version, "9.9999");
};

export class AlwaysHP extends Application {
tokenname = '';
tokenstat = '';
Expand Down Expand Up @@ -82,26 +86,28 @@ export class AlwaysHP extends Application {
if (!a)
continue;

let dataname = (isNewerVersion(game.version, "9.9999") ? "system." : "data.");
let dataname = (isV10 ? "system." : "data.");
let resourcename = (setting("resourcename") || (game.system?.primaryTokenAttribute ?? game.data?.primaryTokenAttribute) || 'attributes.hp');
let resource = getProperty(isNewerVersion(game.version, "9.9999") ? a : a.data, dataname + resourcename);
let resource = getProperty(isV10 ? a : a.data, dataname + resourcename);

if (value.value == 'zero')
value.value = this.getResValue(resource, "value", resource) + this.getResValue(resource, "temp");
if (value.value == 'full')
value.value = (resource instanceof Object ? resource.value - resource.max : resource);

let defeatedStatus = isV10 ? CONFIG.specialStatusEffects.DEFEATED : CONFIG.Combat.defeatedStatusId;

if (active != undefined && setting("add-defeated")) {
let status = CONFIG.statusEffects.find(e => e.id === CONFIG.specialStatusEffects.DEFEATED);
let status = CONFIG.statusEffects.find(e => e.id === defeatedStatus);
let effect = a && status ? status : CONFIG.controlIcons.defeated;
let overlay = (isNewerVersion(game.version, "9.9999") ? t.document.overlayEffect : t.data.overlayEffect);
let overlay = (isV10 ? t.document.overlayEffect : t.data.overlayEffect);
const exists = (effect.icon == undefined ? (overlay == effect) : (a.effects.find(e => e.getFlag("core", "statusId") === effect.id) != undefined));
if (exists != active)
await t.toggleEffect(effect, { overlay: true, active: (active == 'toggle' ? !exists : active) });
}

if (active === false && setting("clear-savingthrows")) {
a.update(isNewerVersion(game.version, "9.9999")
a.update(isV10
? { "system.attributes.death.failure": 0, "system.attributes.death.success": 0 }
: { "data.attributes.death.failure": 0, "data.attributes.death.success": 0 });
}
Expand All @@ -123,9 +129,9 @@ export class AlwaysHP extends Application {
let actor = token.actor;
let { value, target } = amount;
let updates = {};
let dataname = (isNewerVersion(game.version, "9.9999") ? "system." : "data.");
let dataname = (isV10 ? "system." : "data.");
let resourcename = (setting("resourcename") || (game.system?.primaryTokenAttribute ?? game.data?.primaryTokenAttribute) || 'attributes.hp');
let resource = getProperty((isNewerVersion(game.version, "9.9999") ? actor : actor.data), dataname + resourcename);
let resource = getProperty((isV10 ? actor : actor.data), dataname + resourcename);
if (resource instanceof Object) {
value = Math.floor(parseInt(value) * multiplier);

Expand All @@ -152,7 +158,7 @@ export class AlwaysHP extends Application {
const dh = Math.clamped(resource.value - change, (game.system.id == 'D35E' || game.system.id == 'pf1' ? -2000 : 0), resource.max + tmpMax);
updates[dataname + resourcename + ".value"] = dh;

if (isNewerVersion(game.version, "9.9999")) {
if (isV10) {
let display = change + dt;
canvas.interface.createScrollingText(token.center, (-display).signedString(), {
anchor: CONST.TEXT_ANCHOR_POINTS.CENTER,
Expand Down Expand Up @@ -202,7 +208,7 @@ export class AlwaysHP extends Application {
this.tokenstat = "";
this.tokentemp = "";
this.tokentooltip = "";
let dataname = (isNewerVersion(game.version, "9.9999") ? "system." : "data.");
let dataname = (isV10 ? "system." : "data.");
$('.character-name', this.element).removeClass("single");
if (canvas.tokens.controlled.length == 0)
this.tokenname = "";
Expand All @@ -213,7 +219,7 @@ export class AlwaysHP extends Application {
else {
$('.character-name', this.element).addClass("single");
let resourcename = setting("resourcename");
let resource = getProperty((isNewerVersion(game.version, "9.9999") ? a : a.data), dataname + resourcename);
let resource = getProperty((isV10 ? a : a.data), dataname + resourcename);

let value = this.getResValue(resource, "value", resource);
let max = this.getResValue(resource, "max");
Expand Down Expand Up @@ -252,10 +258,10 @@ export class AlwaysHP extends Application {
if (!a)
return;

let prop = (isNewerVersion(game.version, "9.9999") ? a.system.attributes.death : a.data.data.attributes.death);
let prop = (isV10 ? a.system.attributes.death : a.data.data.attributes.death);
prop[save ? 'success' : 'failure'] = Math.max(0, Math.min(3, prop[save ? 'success' : 'failure'] + value));

let dataname = (isNewerVersion(game.version, "9.9999") ? "system." : "data.");
let dataname = (isV10 ? "system." : "data.");
let updates = {};
updates[dataname + "attributes.death." + (save ? 'success' : 'failure')] = prop[save ? 'success' : 'failure'];
canvas.tokens.controlled[0].actor.update(updates);
Expand All @@ -269,7 +275,7 @@ export class AlwaysHP extends Application {
$('.token-stats', this.element).attr('title', this.tokentooltip).html((this.tokentemp ? `<div class="stat temp">${this.tokentemp}</div>` : '') + (this.tokenstat ? `<div class="stat" style="background-color:${this.color}">${this.tokenstat}</div>` : ''));

let actor = (canvas.tokens.controlled.length == 1 ? canvas.tokens.controlled[0].actor : null);
let data = (isNewerVersion(game.version, "9.9999") ? actor?.system : actor?.data?.data);
let data = (isV10 ? actor?.system : actor?.data?.data);
let showST = (actor != undefined && game.system.id == "dnd5e" && data?.attributes.hp.value == 0 && actor?.hasPlayerOwner);
$('.death-savingthrow', this.element).css({ display: (showST ? 'inline-block' : 'none') });
if (showST) {
Expand Down Expand Up @@ -316,7 +322,7 @@ export class AlwaysHP extends Application {
if (canvas.tokens.controlled.length == 1) {
const actor = canvas.tokens.controlled[0].actor;

let dataname = (isNewerVersion(game.version, "9.9999") ? "system." : "data.");
let dataname = (isV10 ? "system." : "data.");
let resourcename = (setting("resourcename") || (game.system.primaryTokenAttribute ?? game.system.data.primaryTokenAttribute) || 'attributes.hp');
let resource = getProperty(actor, dataname + resourcename);

Expand Down Expand Up @@ -421,7 +427,7 @@ export class AlwaysHP extends Application {

let rawvalue = $('#alwayshp-hp', this.element).val();

value.value = (rawvalue.startsWith('+') ? -Math.abs(value.value) : Math.abs(value.value));
value.value = (rawvalue.startsWith('+') || (!rawvalue.startsWith('-') && !setting("no-sign-negative")) ? -Math.abs(value.value) : Math.abs(value.value));

this.changeHP(value); //Heal with a + but everything else is a hurt
this.clearInput();
Expand Down Expand Up @@ -487,7 +493,7 @@ Hooks.on('controlToken', () => {

Hooks.on('updateActor', (actor, data) => {
//log('Updating actor', actor, data);
let dataname = (isNewerVersion(game.version, "9.9999") ? "system." : "data.");
let dataname = (isV10 ? "system." : "data.");
if (canvas.tokens.controlled.length == 1
&& canvas.tokens.controlled[0]?.actor?.id == actor.id
&& (getProperty(data, dataname + "attributes.death") != undefined || getProperty(data, dataname + setting("resourcename")))) {
Expand Down
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"ALWAYSHP.load-option.name": "Load Option",
"ALWAYSHP.allow-bar-click.name": "Allow Bar Click",
"ALWAYSHP.allow-bar-click.hint": "Hover over and click on the HP bar to alter the attribute",
"ALWAYSHP.no-sign-negative.name": "No sign means negative",
"ALWAYSHP.no-sign-negative.hint": "If no + or - is added, Always HP assumes negative",

"ALWAYSHP.DeathSavingThrowFail": "Death Savingthrow, Fail",
"ALWAYSHP.DeathSavingThrowPass": "Death Savingthrow, Pass"
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "Always HP",
"description": "We're always updating HP, add a window to make it easier to adjust that",
"version": "10.1",
"version": "10.2",
"authors": [
{
"name": "IronMonk",
Expand Down Expand Up @@ -29,7 +29,7 @@
"css/alwayshp.css"
],
"url": "https://github.com/ironmonk88/always-hp",
"download": "https://github.com/ironmonk88/always-hp/archive/10.1.zip",
"download": "https://github.com/ironmonk88/always-hp/archive/10.2.zip",
"manifest": "https://github.com/ironmonk88/always-hp/releases/latest/download/module.json",
"bugs": "https://github.com/ironmonk88/always-hp/issues",
"allowBugReporter": true,
Expand Down
9 changes: 9 additions & 0 deletions modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ export const registerSettings = function () {
config: true
});

game.settings.register(modulename, "no-sign-negative", {
name: i18n("ALWAYSHP.no-sign-negative.name"),
hint: i18n("ALWAYSHP.no-sign-negative.hint"),
scope: "client",
default: true,
type: Boolean,
config: true
});

game.settings.register(modulename, "add-defeated", {
name: i18n("ALWAYSHP.add-defeated.name"),
hint: i18n("ALWAYSHP.add-defeated.hint"),
Expand Down

0 comments on commit a745c19

Please sign in to comment.