Change the way conditions with values are handled
This commit is contained in:
@@ -103,25 +103,33 @@ export class pf2e{
|
|||||||
return this.getCondition(token,condition) != undefined;
|
return this.getCondition(token,condition) != undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
getValuedCondition(token,condition) {
|
getConditionValue(token,condition) {
|
||||||
const effect = this.getCondition(token, condition);
|
const effect = this.getCondition(token, condition);
|
||||||
if (effect != undefined && effect?.data.value != null) return effect;
|
if (effect != undefined && effect?.value != null) return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
async modifyValuedCondition(token,condition,delta) {
|
async modifyConditionValue(token,condition,delta) {
|
||||||
const effect = this.getValuedCondition(token,condition);
|
if (condition == undefined) condition = 'removeAll';
|
||||||
if (effect == undefined) {
|
if (condition == 'removeAll'){
|
||||||
if (delta > 0) {
|
for( let effect of token.actor.items.filter(i => i.type == 'condition'))
|
||||||
const Condition = condition.charAt(0).toUpperCase() + condition.slice(1);
|
await effect.delete();
|
||||||
const newCondition = game.pf2e.ConditionManager.getCondition(Condition);
|
|
||||||
// newCondition.data.sources.hud = !0,
|
|
||||||
await game.pf2e.ConditionManager.addConditionToToken(newCondition, token);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const currentValue = effect.value;
|
const effect = this.getConditionValue(token,condition);
|
||||||
console.log(`Current Value: ${currentValue}`);
|
if (effect == undefined) {
|
||||||
await game.pf2e.ConditionManager.updateConditionValue(effect, token, currentValue+delta);
|
if (delta > 0) {
|
||||||
|
const Condition = condition.charAt(0).toUpperCase() + condition.slice(1);
|
||||||
|
const newCondition = game.pf2e.ConditionManager.getCondition(Condition);
|
||||||
|
await game.pf2e.ConditionManager.addConditionToToken(newCondition, token);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
await game.pf2e.ConditionManager.updateConditionValue(effect.id, token, effect.value+delta);
|
||||||
|
} catch (error) {
|
||||||
|
//Do nothing. updateConditionValue will have an error about 'documentData is not iterable' when called from an NPC token.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async toggleCondition(token,condition) {
|
async toggleCondition(token,condition) {
|
||||||
|
|||||||
@@ -242,13 +242,13 @@ export class TokenHelper{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* PF2E */
|
/* PF2E */
|
||||||
getValuedCondition(token,condition) {
|
getConditionValue(token,condition) {
|
||||||
return this.system.getValuedCondition(token,condition);
|
return this.system.getConditionValue(token,condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PF2E */
|
/* PF2E */
|
||||||
modifyValuedCondition(token,condition,delta) {
|
modifyConditionValue(token,condition,delta) {
|
||||||
return this.system.modifyValuedCondition(token,condition,delta);
|
return this.system.modifyConditionValue(token,condition,delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
57
src/token.js
57
src/token.js
@@ -153,7 +153,12 @@ export class TokenControl{
|
|||||||
else if (stats == 'Advantage') txt += tokenHelper.getAdvantage(token) /* WFRP4e */
|
else if (stats == 'Advantage') txt += tokenHelper.getAdvantage(token) /* WFRP4e */
|
||||||
else if (stats == 'Resolve') txt += tokenHelper.getResolve(token) /* WFRP4e */
|
else if (stats == 'Resolve') txt += tokenHelper.getResolve(token) /* WFRP4e */
|
||||||
else if (stats == 'Resilience') txt += tokenHelper.getResilience(token) /* WFRP4e */
|
else if (stats == 'Resilience') txt += tokenHelper.getResilience(token) /* WFRP4e */
|
||||||
|
else if (stats == 'Condition') {
|
||||||
|
const valuedCondition = tokenHelper.getConditionValue(token, settings.condition);
|
||||||
|
if (valuedCondition != undefined) {
|
||||||
|
txt += valuedCondition?.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (settings.onClick == 'visibility') { //toggle visibility
|
if (settings.onClick == 'visibility') { //toggle visibility
|
||||||
if (MODULE.getPermission('TOKEN','VISIBILITY') == false ) {
|
if (MODULE.getPermission('TOKEN','VISIBILITY') == false ) {
|
||||||
@@ -195,7 +200,7 @@ export class TokenControl{
|
|||||||
iconSrc = "fas fa-bullseye";
|
iconSrc = "fas fa-bullseye";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (settings.onClick == 'condition') { //toggle condition
|
else if (settings.onClick == 'condition') { //handle condition
|
||||||
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) {
|
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) {
|
||||||
streamDeck.noPermission(context,device);
|
streamDeck.noPermission(context,device);
|
||||||
return;
|
return;
|
||||||
@@ -210,21 +215,6 @@ export class TokenControl{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (settings.onClick == 'valuedCondition') { //modify valued condition
|
|
||||||
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) {
|
|
||||||
streamDeck.noPermission(context,device);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ring = 1;
|
|
||||||
overlay = true;
|
|
||||||
if (icon == 'stats') {
|
|
||||||
iconSrc = tokenHelper.getConditionIcon(settings.valuedCondition);
|
|
||||||
if (tokenHelper.getValuedCondition(token,settings.valuedCondition)) {
|
|
||||||
ring = 2;
|
|
||||||
ringColor = "#FF7B00";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (settings.onClick == 'cubCondition') { //Combat Utility Belt conditions
|
else if (settings.onClick == 'cubCondition') { //Combat Utility Belt conditions
|
||||||
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) {
|
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) {
|
||||||
streamDeck.noPermission(context,device);
|
streamDeck.noPermission(context,device);
|
||||||
@@ -359,15 +349,6 @@ export class TokenControl{
|
|||||||
overlay = true;
|
overlay = true;
|
||||||
if (icon == 'stats') iconSrc = tokenHelper.getConditionIcon(settings.condition);
|
if (icon == 'stats') iconSrc = tokenHelper.getConditionIcon(settings.condition);
|
||||||
}
|
}
|
||||||
else if (settings.onClick == 'valuedCondition') { //modify condition value
|
|
||||||
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) {
|
|
||||||
streamDeck.noPermission(context,device);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ring = 1;
|
|
||||||
overlay = true;
|
|
||||||
if (icon == 'stats') iconSrc = tokenHelper.getConditionIcon(settings.condition);
|
|
||||||
}
|
|
||||||
else if (settings.onClick == 'cubCondition') { //Combat Utility Belt conditions
|
else if (settings.onClick == 'cubCondition') { //Combat Utility Belt conditions
|
||||||
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) {
|
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) {
|
||||||
streamDeck.noPermission(context,device);
|
streamDeck.noPermission(context,device);
|
||||||
@@ -526,15 +507,23 @@ export class TokenControl{
|
|||||||
else if (onClick == 'target') { //Target token
|
else if (onClick == 'target') { //Target token
|
||||||
token.setTarget(!token.isTargeted,{releaseOthers:false});
|
token.setTarget(!token.isTargeted,{releaseOthers:false});
|
||||||
}
|
}
|
||||||
else if (onClick == 'condition') { //Toggle condition
|
else if (onClick == 'condition') { //Handle condition
|
||||||
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) return;
|
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) return;
|
||||||
await tokenHelper.toggleCondition(token,settings.condition);
|
const func = settings.conditionFunction ? settings.conditionFunction : 'toggle';
|
||||||
this.update(tokenId);
|
|
||||||
}
|
if (func == 'toggle'){ //toggle
|
||||||
else if (onClick == 'valuedCondition') { //Modify Valued condition
|
await tokenHelper.toggleCondition(token,settings.condition);
|
||||||
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) return;
|
this.update(tokenId);
|
||||||
await tokenHelper.modifyValuedCondition(token,settings.valuedCondition,settings.valuedConditionDelta);
|
}
|
||||||
this.update(tokenId);
|
else if (func == 'increase'){ //increase
|
||||||
|
await tokenHelper.modifyConditionValue(token, settings.condition, +1)
|
||||||
|
this.update(tokenId);
|
||||||
|
}
|
||||||
|
else if (func == 'decrease'){ //decrease
|
||||||
|
await tokenHelper.modifyConditionValue(token, settings.condition, -1)
|
||||||
|
this.update(tokenId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (onClick == 'cubCondition') { //Combat Utility Belt conditions
|
else if (onClick == 'cubCondition') { //Combat Utility Belt conditions
|
||||||
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) return;
|
if (MODULE.getPermission('TOKEN','CONDITIONS') == false ) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user