Skip to content

Commit

Permalink
1.0.46 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IronMonk88 committed Jul 25, 2021
1 parent ab4e2c9 commit 9c000c5
Show file tree
Hide file tree
Showing 28 changed files with 2,132 additions and 81 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## Version 1.0.46

Fixing issue with Assigning XP dialog getting NaN for xp to distribute.

Added the option to customise the number of stats being displayed.

When using the requestRoll API you can now call using English names instead of codes. So calling with "perception" with translate to "skill:prc".

Requesting a roll will now default to the current tokens on the Tokenbar instead of all player controlled.

Moved dynamic items being added to the request roll dialog to the system object

Tokenbar attributes that are an object will default to trying to find the .value of the object.

Fixed issue with using fastForward and requestRoll from the API causing an error.

used libWrapper to encapsulate canDrag override. This should stop the message getting flagged from DF-QOL.

Added skills to SWADE, so they'll now appear when requesting a Roll.

## Version 1.0.45

Fixing issues with finding the proper tokens for the Tokenbar.
Expand Down
4 changes: 2 additions & 2 deletions apps/assignxp.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class AssignXPApp extends Application {
let monstXP = this.xpchart[Math.clamped(4 + (monstLevel - calcAPL), 0, this.xpchart.length - 1)];
combatxp += monstXP;
}else
combatxp += combatant.actor?.data.data.details?.xp?.value;
combatxp += (combatant.actor?.data.data.details?.xp?.value || 0);
}
};
//xp += (combatant?.actor.data.data.details?.xp?.value || MonksLittleDetails.xpchart[Math.clamped(parseInt(combatant?.actor.data.data.details?.level?.value), 0, MonksLittleDetails.xpchart.length - 1)] || 0);
Expand Down Expand Up @@ -100,7 +100,7 @@ export class AssignXPApp extends Application {
return a + (b?.levels || b?.level || 0);
}, 0);
} else {
levels = actor.data.data.details?.level?.value || combatant?.actor.data.data.details?.level || 0;
levels = actor.data.data.details?.level?.value || actor.data.data.details?.level || 0;
}

return levels;
Expand Down
4 changes: 2 additions & 2 deletions apps/contestedroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ContestedRollApp extends Application {
//let requestname = $('.request-roll[data-type="item' + index + '"] option:selected', this.element).html() + " " + (requesttype == 'ability' ? i18n("MonksTokenBar.AbilityCheck") : (requesttype == 'save' ? i18n("MonksTokenBar.SavingThrow") : i18n("MonksTokenBar.Check")));
return {
id: item.token.id,
uuid: item.token.uuid,
uuid: item.token.document.uuid,
actorid: item.token.actor.id,
requesttype: requesttype,
request: request,
Expand All @@ -78,7 +78,7 @@ export class ContestedRollApp extends Application {
rollmode: rollmode,
modename: modename,
tokens: tokens,
canGrab: ['dnd5e','sw5e'].includes(game.system.id),
canGrab: ['dnd5e', 'sw5e'].includes(game.system.id),
options: this.opts
};
const html = await renderTemplate("./modules/monks-tokenbar/templates/contestedrollchatmsg.html", requestdata);
Expand Down
144 changes: 144 additions & 0 deletions apps/editstats.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/lootables.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class LootablesApp extends Application {
}

let oldAlpha = token.token.data.alpha;
await token.token.update({
await token.token.document.update({
"overlayEffect": 'icons/svg/chest.svg',
"alpha": 0.6,
"actorData": {
Expand Down
63 changes: 32 additions & 31 deletions apps/savingthrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,28 @@ export class SavingThrowApp extends Application {

if (this.tokens.length == 0) { //if none have been selected then default to the party
this.tokens = canvas.tokens.placeables.filter(t => {
return t.actor != undefined && t.actor?.hasPlayerOwner && t.actor?.data.type != 'npc';
let include = t.document.getFlag('monks-tokenbar', 'include');
include = (include === true ? 'include' : (include === false ? 'exclude' : include || 'default'));
return (t.actor != undefined && ((t.actor?.hasPlayerOwner && t.data.disposition == 1 && include != 'exclude') || include === 'include'));
});
}
this.rollmode = (options?.rollmode || game.user.getFlag("monks-tokenbar", "lastmodeST") || 'roll');
this.request = options.request;
this.baseoptions = this.requestoptions = (options.requestoptions || MonksTokenBar.system.requestoptions);
this.request = options.request;

//find best match for request
if (options.request) {
for (let opt of this.baseoptions) {
let byname = Object.entries(opt.groups).find(([k, v]) => {
return i18n(v).toLowerCase() == options.request.toLowerCase()
});
if (byname) {
this.request = opt.id + ':' + byname[0];
break;
}
}
}

this.dc = options.dc;
}

Expand All @@ -36,32 +52,9 @@ export class SavingThrowApp extends Application {
this.requestoptions = this.baseoptions;

if (this.tokens.length > 0) {
let tools = {};
//get the first token's tools
for (let item of this.tokens[0].actor.items) {
if (item.type == 'tool') {
let sourceID = item.getFlag("core", "sourceId") || item.id;
//let toolid = item.data.name.toLowerCase().replace(/[^a-z]/gi, '');
tools[sourceID] = item.data.name;
}
}
//see if the other tokens have these tools
if (Object.keys(tools).length > 0) {
for (let i = 1; i < this.tokens.length; i++) {
let token = this.tokens[i];
for (let [k, v] of Object.entries(tools)) {
let tool = token.actor.items.find(t => {
return t.type == 'tool' && (t.getFlag("core", "sourceId") || t.id) == k;
});
if (tool == undefined)
delete tools[k];
}
}
}

if (Object.keys(tools).length > 0) {
this.requestoptions = this.requestoptions.concat([{ id: 'tool', text: 'Tools', groups: tools }]);
}
let dynamic = MonksTokenBar.system.dynamicRequest(this.tokens);
if (dynamic)
this.requestoptions = this.requestoptions.concat(dynamic);
}

return {
Expand Down Expand Up @@ -91,7 +84,9 @@ export class SavingThrowApp extends Application {
switch (type) {
case 'player':
this.tokens = canvas.tokens.placeables.filter(t => {
return t.actor != undefined && t.actor?.hasPlayerOwner && t.actor?.data.type != 'npc';
let include = t.document.getFlag('monks-tokenbar', 'include');
include = (include === true ? 'include' : (include === false ? 'exclude' : include || 'default'));
return (t.actor != undefined && ((t.actor?.hasPlayerOwner && t.data.disposition == 1 && include != 'exclude') || include === 'include'));
});
this.render(true);
break;
Expand Down Expand Up @@ -140,6 +135,12 @@ export class SavingThrowApp extends Application {
});
SavingThrow.lastRequest = this.request;

if (this.request == undefined) {
log('Invalid request');
ui.notifications.error("Invalid value sent as a request");
return;
}

let parts = this.request.split(':'); //$('.request-roll', this.element).val()
let requesttype = (parts.length > 1 ? parts[0] : '');
let request = (parts.length > 1 ? parts[1] : parts[0]);
Expand All @@ -150,14 +151,14 @@ export class SavingThrowApp extends Application {
let name = MonksTokenBar.getRequestName(this.requestoptions, requesttype, request);

let requestdata = {
dc: this.dc || (request == 'death' && ['dnd5e','sw5e'].includes(game.system.id) ? '10' : ''),
dc: this.dc || (request == 'death' && ['dnd5e', 'sw5e'].includes(game.system.id) ? '10' : ''),
name: name,
requesttype: requesttype,
request: request,
rollmode: rollmode,
modename: modename,
tokens: tokens,
canGrab: ['dnd5e','sw5e'].includes(game.system.id),
canGrab: ['dnd5e', 'sw5e'].includes(game.system.id),
options: this.opts
};
const html = await renderTemplate("./modules/monks-tokenbar/templates/svgthrowchatmsg.html", requestdata);
Expand Down
49 changes: 41 additions & 8 deletions apps/tokenbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export class TokenBar extends Application {
/** @override */
getData(options) {
let css = [
((game.system.id == "dnd5e" || game.system.id == "sw5e") && (game.settings.get(game.system.id, 'disableExperienceTracking')) ? 'hidexp' : null),
!game.user.isGM ? "hidectrl" : null
].filter(c => !!c).join(" ");
let pos = this.getPos();
Expand Down Expand Up @@ -131,7 +130,7 @@ export class TokenBar extends Application {
let value = parseInt(term);
if (isNaN(value)) {
value = getProperty(data, term);
return (value == undefined || value == null ? null : String(value).trim());
return (value == undefined || value == null ? null : String(typeof value == 'object' ? value.value : value).trim());
} else
return value;
});
Expand All @@ -149,8 +148,14 @@ export class TokenBar extends Application {
async mapToken(token) {
let actor = token.actor;

let stat1 = TokenBar.processStat(setting("stat1-resource"), actor.data.data);
let stat2 = TokenBar.processStat(setting("stat2-resource"), actor.data.data);
let stats = {};
for (let stat of MonksTokenBar.stats) {
let value = TokenBar.processStat(stat.stat, actor.data.data);
stats[stat.stat] = { icon: stat.icon, value: value, hidden: (value == undefined) };
}

//let stat1 = TokenBar.processStat(setting("stat1-resource"), actor.data.data);
//let stat2 = TokenBar.processStat(setting("stat2-resource"), actor.data.data);

token.document.unsetFlag("monks-tokenbar", "notified");

Expand All @@ -176,9 +181,8 @@ export class TokenBar extends Application {
img: img,
thumb: thumb?.thumb || thumb,
movement: token.document.getFlag("monks-tokenbar", "movement"),
stat1: stat1,
stat2: stat2,
statClass: (stat1 == undefined && stat2 == undefined ? 'hidden' : ''),
stats: stats,
//statClass: (stat1 == undefined && stat2 == undefined ? 'hidden' : ''),
resource1: resources[0],
resource2: resources[1]
}
Expand Down Expand Up @@ -239,6 +243,34 @@ export class TokenBar extends Application {
if (tkn?.resource2?.value != tkn.token.document.getBarAttribute('bar2')?.value) { //getAttrProperty(tkn.token.actor.data.data, tkn.token.data.bar2.attribute)) {
diff.resource2 = this.getResourceBar(tkn.token, "bar2");
}

let viewstats = MonksTokenBar.stats;
let diffstats = {};
for (let stat of viewstats) {
let value = TokenBar.processStat(stat.stat, tkn.token.actor.data.data);

if (tkn.stats[stat.stat] == undefined) {
tkn.stats[stat.stat] = { icon: stat.icon, value: value, hidden: (value == undefined) };
diffstats[stat.stat] = tkn.stats[stat.stat];
}
else {
let tokenstat = duplicate(tkn.stats[stat.stat]);
if (tokenstat.value != value) {
tokenstat.value = value;
tokenstat.hidden = (value == undefined);
diffstats[stat.stat] = tokenstat;
//diff.statClass = (tkn.stat1 == undefined && tkn.stat2 == undefined ? 'hidden' : '');
}
}
}
for (let [k,v] of Object.entries(tkn.stats)) {
if (!viewstats.find(s => s.stat == k))
delete tkn.stats[k];
}
if (Object.keys(diffstats).length > 0) {
diff.stats = diffstats;
}
/*
let stat1 = TokenBar.processStat(setting("stat1-resource"), tkn.token.actor.data.data);
if (tkn.stat1 != stat1) {
diff.stat1 = stat1;
Expand All @@ -248,7 +280,8 @@ export class TokenBar extends Application {
if (tkn.stat2 != stat2) {
diff.stat2 = stat2;
diff.statClass = (tkn.stat1 == undefined && tkn.stat2 == undefined ? 'hidden' : '');
}
}*/

if (tkn.img != (setting("token-pictures") == "actor" && tkn.token.actor != undefined ? tkn.token.actor.data.img : tkn.token.data.img)) {
diff.img = (setting("token-pictures") == "actor" && tkn.token.actor != undefined ? tkn.token.actor.data.img : tkn.token.data.img);
//let thumb = diff.img;
Expand Down
Loading

0 comments on commit 9c000c5

Please sign in to comment.