diff --git a/CHANGELOG.md b/CHANGELOG.md index b4737e4..6c2ab03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 0.5.23 + +- Bug fix on unset flag and repair method + ### 0.5.22 - Solved https://github.com/p4535992/conditional-visibility/issues/25 diff --git a/package.json b/package.json index 9d0882d..e7cd791 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "conditional-visibility", "title": "Conditional Visibility", "description": "Hide tokens from some players, but not others, based on the senses the players have. Uses unknown, newspaper, and foggy icons made by Freepik, from www.flaticon.com. Moon icon made by iconixar from www.flaticon.com", - "version": "0.5.22", + "version": "0.5.23", "scripts": { "package": "gulp package", "build": "gulp build && gulp link", diff --git a/src/module.json b/src/module.json index 6897300..c092ae9 100644 --- a/src/module.json +++ b/src/module.json @@ -2,7 +2,7 @@ "name": "conditional-visibility", "title": "Conditional Visibility", "description": "Hide tokens from some players, but not others, based on the senses the players have. Uses unknown, newspaper, and foggy icons made by Freepik, from www.flaticon.com. Moon icon made by iconixar from www.flaticon.com", - "version": "0.5.22", + "version": "0.5.23", "author": "Greg Ludington, p4535992, Szefo09, Teshynil", "type": "module", "socket": true, @@ -61,9 +61,9 @@ "manifestPlusVersion": "1.2.0", "url": "https://github.com/p4535992/conditional-visibility", "manifest": "https://github.com/p4535992/conditional-visibility/releases/latest/download/module.json", - "download": "https://github.com/p4535992/conditional-visibility/releases/download/v0.5.22/module.zip", - "readme": "https://github.com/p4535992/conditional-visibility/blob/v0.5.22/README.md", - "changelog": "https://github.com/p4535992/conditional-visibility/blob/v0.5.22/changelog.md", + "download": "https://github.com/p4535992/conditional-visibility/releases/download/v0.5.23/module.zip", + "readme": "https://github.com/p4535992/conditional-visibility/blob/v0.5.23/README.md", + "changelog": "https://github.com/p4535992/conditional-visibility/blob/v0.5.23/changelog.md", "bugs": "https://github.com/p4535992/conditional-visibility/issues", "allowBugReporter": true, "dependencies": [ diff --git a/src/module/lib/lib.ts b/src/module/lib/lib.ts index babe8ef..89740bb 100644 --- a/src/module/lib/lib.ts +++ b/src/module/lib/lib.ts @@ -1878,42 +1878,42 @@ export async function repairAndSetFlag(token: Token, key: string, value: AtcvEff let updateKey = ''; if (!aee.key.startsWith('ATCV.condition')) { updateKey = aee.key.slice(5); - if(aee.value != String(value?.visionLevelValue)){ + if (aee.value != String(value?.visionLevelValue)) { thereISADifference = true; } } else if (aee.key.startsWith('ATCV.conditionElevation')) { - if(aee.value != String(value?.visionElevation)){ + if (aee.value != String(value?.visionElevation)) { thereISADifference = true; } } else if (aee.key.startsWith('ATCV.conditionDistance')) { - if(aee.value != String(value?.visionDistanceValue)){ + if (aee.value != String(value?.visionDistanceValue)) { thereISADifference = true; } } else if (aee.key.startsWith('ATCV.conditionTargets')) { - if(aee.value != String(value?.visionTargets)){ + if (aee.value != String(value?.visionTargets)) { thereISADifference = true; } } else if (aee.key.startsWith('ATCV.conditionSources')) { - if(aee.value != String(value?.visionSources)){ + if (aee.value != String(value?.visionSources)) { thereISADifference = true; } } else if (aee.key.startsWith('ATCV.conditionTargetImage')) { - if(aee.value != String(value?.visionTargetImage)){ + if (aee.value != String(value?.visionTargetImage)) { thereISADifference = true; } } else if (aee.key.startsWith('ATCV.conditionType')) { - if(aee.value != String(value?.visionType)){ + if (aee.value != String(value?.visionType)) { thereISADifference = true; } } - if(updateKey === value.visionId){ + if (updateKey === value.visionId) { break; - }else{ + } else { thereISADifference = false; } } } - }else{ + } else { thereISADifference = true; } if (token.document.getFlag(CONSTANTS.MODULE_NAME, key)) { @@ -1938,7 +1938,7 @@ export async function repairAndSetFlag(token: Token, key: string, value: AtcvEff await token.actor.unsetFlag(CONSTANTS.MODULE_NAME, 'conditionType'); } - if(thereISADifference){ + if (thereISADifference) { await token.actor?.setFlag(CONSTANTS.MODULE_NAME, key, value); let data: AtcvEffect[] = []; if (value.visionType === 'sense') { @@ -2011,6 +2011,45 @@ export async function repairAndUnSetFlag(token: Token, key: string) { await token.actor.unsetFlag(CONSTANTS.MODULE_NAME, 'conditionType'); } await token.actor?.unsetFlag(CONSTANTS.MODULE_NAME, key); + + const isSense = !!API.SENSES.find((sense: SenseData) => { + return isStringEquals(sense.id, key); + }); + const isCondition = !!API.CONDITIONS.find((sense: SenseData) => { + return isStringEquals(sense.id, key); + }); + let data: AtcvEffect[] = []; + if (isSense) { + // data = token.actor?.getFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.DATA_SENSES) ?? []; + data = getSensesFromToken(token.document, true); + } else if (isCondition) { + // data = token.actor?.getFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.DATA_CONDITIONS) ?? []; + data = getConditionsFromToken(token.document, true); + } else { + return; + } + //Find index of specific object using findIndex method. + const objIndex = data.findIndex((obj) => obj.visionId === key); + if (objIndex >= 0) { + //Update object's name property. + data.splice(objIndex, 1); // 2nd parameter means remove one item only + } + data = data.filter((a) => { + return ( + a.visionLevelValue != 0 && + a.visionLevelValue != undefined && + a.visionLevelValue != null && + is_real_number(a.visionLevelValue) && + !a.visionIsDisabled + ); + }); + if (isSense) { + await token.actor?.setFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.DATA_SENSES, data); + } else if (isCondition) { + await token.actor?.setFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.DATA_CONDITIONS, data); + } else { + // DO NOTHING + } // canvas.perception.schedule({ // lighting: { refresh: true }, // sight: { refresh: true }, diff --git a/src/module/libwrapper.ts b/src/module/libwrapper.ts index a2676ed..e30a1a6 100644 --- a/src/module/libwrapper.ts +++ b/src/module/libwrapper.ts @@ -284,7 +284,7 @@ export function sightLayerPrototypeTestVisibilityHandler(wrapped, ...args) { // this.sources is a map of selected tokens (may be size 0) all tokens // contribute to the vision so iterate through the tokens // TODO find a better and fat way to prepera the sources array - + let mySources: Token[] = []; if (!this.sources || this.sources.size === 0) { // return res; @@ -328,7 +328,6 @@ export function sightLayerPrototypeTestVisibilityHandler(wrapped, ...args) { break; } } - if (game.settings.get(CONSTANTS.MODULE_NAME, 'debug')) { const sourcesNames = mySources.map((e) => { diff --git a/src/module/module.ts b/src/module/module.ts index c3e26d1..76c1cf2 100644 --- a/src/module/module.ts +++ b/src/module/module.ts @@ -187,7 +187,7 @@ const module = { const conditionsTemplateData: any[] = []; for (const s of conditions) { if (s.visionId != AtcvEffectConditionFlags.NONE) { - const s2:AtcvEffect = duplicateExtended(s); + const s2: AtcvEffect = duplicateExtended(s); // const currentAtcvEffectFlagData = tokenConfig.object.getFlag(CONSTANTS.MODULE_NAME, s.visionId); /* const currentAtcvEffectFlagData = @@ -256,8 +256,7 @@ const module = { !getProperty(change, `flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.DATA_CONDITIONS}`) ) { module.updateToken(sourceToken.document, change, options, userId); - } - else if ( + } else if ( change.actor && change.actor.data && change.actor.data.flags[CONSTANTS.MODULE_NAME] && @@ -276,41 +275,34 @@ const module = { !getProperty(change, `flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.DATA_SENSES}`) && !getProperty(change, `flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.DATA_CONDITIONS}`) ) { - const forceVisible = !!getProperty(change, `flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`); - if(forceVisible){ - await sourceToken.actor?.setFlag( - CONSTANTS.MODULE_NAME, - ConditionalVisibilityFlags.FORCE_VISIBLE, - forceVisible - ); - }else{ - await sourceToken.actor?.unsetFlag( - CONSTANTS.MODULE_NAME, - ConditionalVisibilityFlags.FORCE_VISIBLE - ); + const forceVisible = !!getProperty( + change, + `flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`, + ); + if (forceVisible) { + await sourceToken.actor?.setFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE, forceVisible); + } else { + await sourceToken.actor?.unsetFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE); } - } - else if ( + } else if ( change.actor && change.actor.data && change.actor.data.flags[CONSTANTS.MODULE_NAME] && - getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`) != null && - getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`) != undefined && + getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`) != + null && + getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`) != + undefined && !getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.DATA_SENSES}`) && !getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.DATA_CONDITIONS}`) ) { - const forceVisible = !!getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`); - if(forceVisible){ - await sourceToken.actor?.setFlag( - CONSTANTS.MODULE_NAME, - ConditionalVisibilityFlags.FORCE_VISIBLE, - forceVisible - ); - }else{ - await sourceToken.actor?.unsetFlag( - CONSTANTS.MODULE_NAME, - ConditionalVisibilityFlags.FORCE_VISIBLE - ); + const forceVisible = !!getProperty( + change, + `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`, + ); + if (forceVisible) { + await sourceToken.actor?.setFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE, forceVisible); + } else { + await sourceToken.actor?.unsetFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE); } } }, @@ -407,12 +399,14 @@ const module = { isStringEquals(sense.visionName, senseOrConditionId) ); }); - const conditionAtcvEffect = getConditionsFromToken(sourceToken.document).find((sense: AtcvEffect) => { - return ( - isStringEquals(sense.visionId, senseOrConditionId) || - isStringEquals(sense.visionName, senseOrConditionId) - ); - }); + const conditionAtcvEffect = getConditionsFromToken(sourceToken.document).find( + (sense: AtcvEffect) => { + return ( + isStringEquals(sense.visionId, senseOrConditionId) || + isStringEquals(sense.visionName, senseOrConditionId) + ); + }, + ); if (!senseAtcvEffect && !conditionAtcvEffect) { warn( @@ -489,23 +483,21 @@ const module = { change.actor && change.actor.data && change.actor.data.flags[CONSTANTS.MODULE_NAME] && - getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`) != null && - getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`) != undefined && + getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`) != + null && + getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`) != + undefined && !getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.DATA_SENSES}`) && !getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.DATA_CONDITIONS}`) ) { - const forceVisible = !!getProperty(change, `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`); - if(forceVisible){ - await sourceToken.actor?.setFlag( - CONSTANTS.MODULE_NAME, - ConditionalVisibilityFlags.FORCE_VISIBLE, - forceVisible - ); - }else{ - await sourceToken.actor?.unsetFlag( - CONSTANTS.MODULE_NAME, - ConditionalVisibilityFlags.FORCE_VISIBLE - ); + const forceVisible = !!getProperty( + change, + `actor.data.flags.${CONSTANTS.MODULE_NAME}.${ConditionalVisibilityFlags.FORCE_VISIBLE}`, + ); + if (forceVisible) { + await sourceToken.actor?.setFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE, forceVisible); + } else { + await sourceToken.actor?.unsetFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE); } } }, @@ -552,15 +544,15 @@ const module = { ) { if (isRemoved) { // for (const sourceToken of tokenArray) { - const sense = (await getAllDefaultSensesAndConditions(sourceToken)).find((sense: AtcvEffect) => { - return ( - isStringEquals(sense.visionName, activeEffect.name) || - isStringEquals(sense.visionName, activeEffect.data.label) - ); - }); - if (sense?.visionId) { - await repairAndUnSetFlag(sourceToken, sense?.visionId); - } + const sense = (await getAllDefaultSensesAndConditions(sourceToken)).find((sense: AtcvEffect) => { + return ( + isStringEquals(sense.visionName, activeEffect.name) || + isStringEquals(sense.visionName, activeEffect.data.label) + ); + }); + if (sense?.visionId) { + await repairAndUnSetFlag(sourceToken, sense?.visionId); + } // } } else { return; @@ -591,45 +583,45 @@ const module = { } const updateKey = change.key.slice(5); // for (const sourceToken of tokenArray) { - // const isPlayerOwned = sourceToken.document.isOwner; - // if (!isPlayerOwned) { - // continue; - // } - //@ts-ignore - // if (updateValue == options.changes.find((a) => change.key === a.key)?.value) { - // if (tokenToSet.actor?.getFlag(CONSTANTS.MODULE_NAME, updateKey) != updateValue) { - // const atcvEffectFlagData = AtcvEffect.fromActiveEffect(tokenToSet.document, atcvEffect); - // await repairAndSetFlag(tokenToSet, updateKey, atcvEffectFlagData); - // } - // continue; - // } - const sensesData = await getAllDefaultSensesAndConditions(sourceToken); - for (const statusSight of sensesData) { - if (updateKey === statusSight.visionId) { - // TODO TO CHECK IF WE NEED TO FILTER THE TOKENS AGAIN MAYBE WITH A ADDITIONAL ATCV active change data effect ? - const currentAtcvEffectFlagData = ( - (sourceToken?.actor?.getFlag(CONSTANTS.MODULE_NAME, updateKey) ?? - sourceToken?.document.getFlag(CONSTANTS.MODULE_NAME, updateKey)) - ); - const currentValue = String(currentAtcvEffectFlagData?.visionLevelValue) ?? '0'; - // const currentValue = String(statusSight.visionLevelValue) ?? '0'; - if (change.value != currentValue) { - if (isRemoved || currentValue == '0') { - await repairAndUnSetFlag(sourceToken, updateKey); - } else { - const atcvEffectFlagData = AtcvEffect.fromActiveEffect(sourceToken.document, atcvEffect); - await repairAndSetFlag(sourceToken, updateKey, atcvEffectFlagData); - } + // const isPlayerOwned = sourceToken.document.isOwner; + // if (!isPlayerOwned) { + // continue; + // } + //@ts-ignore + // if (updateValue == options.changes.find((a) => change.key === a.key)?.value) { + // if (tokenToSet.actor?.getFlag(CONSTANTS.MODULE_NAME, updateKey) != updateValue) { + // const atcvEffectFlagData = AtcvEffect.fromActiveEffect(tokenToSet.document, atcvEffect); + // await repairAndSetFlag(tokenToSet, updateKey, atcvEffectFlagData); + // } + // continue; + // } + const sensesData = await getAllDefaultSensesAndConditions(sourceToken); + for (const statusSight of sensesData) { + if (updateKey === statusSight.visionId) { + // TODO TO CHECK IF WE NEED TO FILTER THE TOKENS AGAIN MAYBE WITH A ADDITIONAL ATCV active change data effect ? + const currentAtcvEffectFlagData = ( + (sourceToken?.actor?.getFlag(CONSTANTS.MODULE_NAME, updateKey) ?? + sourceToken?.document.getFlag(CONSTANTS.MODULE_NAME, updateKey)) + ); + const currentValue = String(currentAtcvEffectFlagData?.visionLevelValue) ?? '0'; + // const currentValue = String(statusSight.visionLevelValue) ?? '0'; + if (change.value != currentValue) { + if (isRemoved || currentValue == '0') { + await repairAndUnSetFlag(sourceToken, updateKey); } else { - // Strange bug fixing - if (isRemoved && activeEffect.id === atcvEffect.id) { - // await tokenToSet?.document.unsetFlag(CONSTANTS.MODULE_NAME, updateKey); - await repairAndUnSetFlag(sourceToken, updateKey); - } + const atcvEffectFlagData = AtcvEffect.fromActiveEffect(sourceToken.document, atcvEffect); + await repairAndSetFlag(sourceToken, updateKey, atcvEffectFlagData); + } + } else { + // Strange bug fixing + if (isRemoved && activeEffect.id === atcvEffect.id) { + // await tokenToSet?.document.unsetFlag(CONSTANTS.MODULE_NAME, updateKey); + await repairAndUnSetFlag(sourceToken, updateKey); } - break; } + break; } + } // } } } @@ -744,7 +736,7 @@ const module = { const actorChatId = speakerInfo.message.speaker.actor; let sourceToken: Token | null = null; - if(actorChatId){ + if (actorChatId) { const actor = game.actors?.get(actorChatId); const isPlayerOwnedActor = actor?.isOwner; if (actor && !game.user?.isGM && !isPlayerOwnedActor) { @@ -760,12 +752,12 @@ const module = { return t.id === tokenChatId; }); } - }else if(tokenChatId){ + } else if (tokenChatId) { sourceToken = canvas.tokens?.placeables.find((t) => { return t.id === tokenChatId; }); } - if(!sourceToken){ + if (!sourceToken) { return; } const isPlayerOwned = sourceToken.document.isOwner; @@ -839,62 +831,62 @@ const module = { const selectedToken = sourceToken; // for (const selectedToken of selectedTokens) { - // if (!selectedToken) { - // continue; - // } - const setAeToRemove = new Set(); - const actorEffects = >selectedToken.actor?.data.effects; - if (senseId != AtcvEffectSenseFlags.NONE && senseId != AtcvEffectSenseFlags.NORMAL) { - const effect = await ConditionalVisibilityEffectDefinitions.effect(senseId); - if (effect) { - if (valStealthRoll == 0) { - // await API.removeEffectOnToken(selectedToken.id, i18n(effect?.name)); - const effectToRemove = ( - actorEffects.find((activeEffect) => - isStringEquals(activeEffect?.data?.label, effect?.name), - ) - ); - if (effectToRemove) { - setAeToRemove.add(effectToRemove.id); - } - await repairAndUnSetFlag(selectedToken, senseId); - } else { - const atcvEffectFlagData = AtcvEffect.fromEffect(selectedToken.document, effect); - atcvEffectFlagData.visionLevelValue = valStealthRoll; - await repairAndSetFlag(selectedToken, senseId, atcvEffectFlagData); + // if (!selectedToken) { + // continue; + // } + const setAeToRemove = new Set(); + const actorEffects = >selectedToken.actor?.data.effects; + if (senseId != AtcvEffectSenseFlags.NONE && senseId != AtcvEffectSenseFlags.NORMAL) { + const effect = await ConditionalVisibilityEffectDefinitions.effect(senseId); + if (effect) { + if (valStealthRoll == 0) { + // await API.removeEffectOnToken(selectedToken.id, i18n(effect?.name)); + const effectToRemove = ( + actorEffects.find((activeEffect) => + isStringEquals(activeEffect?.data?.label, effect?.name), + ) + ); + if (effectToRemove) { + setAeToRemove.add(effectToRemove.id); } + await repairAndUnSetFlag(selectedToken, senseId); } else { - warn(`Can't find effect definition for '${senseId}'`, true); + const atcvEffectFlagData = AtcvEffect.fromEffect(selectedToken.document, effect); + atcvEffectFlagData.visionLevelValue = valStealthRoll; + await repairAndSetFlag(selectedToken, senseId, atcvEffectFlagData); } + } else { + warn(`Can't find effect definition for '${senseId}'`, true); } - //@ts-ignore - if (conditionId != AtcvEffectConditionFlags.NONE) { - const effect = await ConditionalVisibilityEffectDefinitions.effect(conditionId); - if (effect) { - if (valStealthRoll == 0) { - // await API.removeEffectOnToken(selectedToken.id, i18n(effect?.name)); - const effectToRemove = ( - actorEffects.find((activeEffect) => - isStringEquals(activeEffect?.data?.label, effect?.name), - ) - ); - if (effectToRemove) { - setAeToRemove.add(effectToRemove.id); - } - await repairAndUnSetFlag(selectedToken, conditionId); - } else { - const atcvEffectFlagData = AtcvEffect.fromEffect(selectedToken.document, effect); - atcvEffectFlagData.visionLevelValue = valStealthRoll; - await repairAndSetFlag(selectedToken, conditionId, atcvEffectFlagData); + } + //@ts-ignore + if (conditionId != AtcvEffectConditionFlags.NONE) { + const effect = await ConditionalVisibilityEffectDefinitions.effect(conditionId); + if (effect) { + if (valStealthRoll == 0) { + // await API.removeEffectOnToken(selectedToken.id, i18n(effect?.name)); + const effectToRemove = ( + actorEffects.find((activeEffect) => + isStringEquals(activeEffect?.data?.label, effect?.name), + ) + ); + if (effectToRemove) { + setAeToRemove.add(effectToRemove.id); } + await repairAndUnSetFlag(selectedToken, conditionId); } else { - warn(`Can't find effect definition for '${conditionId}'`, true); + const atcvEffectFlagData = AtcvEffect.fromEffect(selectedToken.document, effect); + atcvEffectFlagData.visionLevelValue = valStealthRoll; + await repairAndSetFlag(selectedToken, conditionId, atcvEffectFlagData); } + } else { + warn(`Can't find effect definition for '${conditionId}'`, true); } - // FINALLY REMVE ALL THE ACTIVE EFFECT - if (setAeToRemove.size > 0) { - API.removeEffectFromIdOnTokenMultiple(selectedToken.id, Array.from(setAeToRemove)); - } + } + // FINALLY REMVE ALL THE ACTIVE EFFECT + if (setAeToRemove.size > 0) { + API.removeEffectFromIdOnTokenMultiple(selectedToken.id, Array.from(setAeToRemove)); + } // } } } @@ -945,59 +937,59 @@ const module = { // if (!selectedToken) { // continue; // } - const setAeToRemove = new Set(); - const actorEffects = >selectedToken.actor?.data.effects; - if (senseId != AtcvEffectSenseFlags.NONE && senseId != AtcvEffectSenseFlags.NORMAL) { - const effect = await ConditionalVisibilityEffectDefinitions.effect(senseId); - if (effect) { - if (valStealthRoll == 0) { - // await API.removeEffectOnToken(selectedToken.id, i18n(effect?.name)); - const effectToRemove = ( - actorEffects.find((activeEffect) => - isStringEquals(activeEffect?.data?.label, effect?.name), - ) - ); - if (effectToRemove) { - setAeToRemove.add(effectToRemove.id); - } - await repairAndUnSetFlag(selectedToken, senseId); - } else { - const atcvEffectFlagData = AtcvEffect.fromEffect(selectedToken.document, effect); - atcvEffectFlagData.visionLevelValue = valStealthRoll; - await repairAndSetFlag(selectedToken, senseId, atcvEffectFlagData); + const setAeToRemove = new Set(); + const actorEffects = >selectedToken.actor?.data.effects; + if (senseId != AtcvEffectSenseFlags.NONE && senseId != AtcvEffectSenseFlags.NORMAL) { + const effect = await ConditionalVisibilityEffectDefinitions.effect(senseId); + if (effect) { + if (valStealthRoll == 0) { + // await API.removeEffectOnToken(selectedToken.id, i18n(effect?.name)); + const effectToRemove = ( + actorEffects.find((activeEffect) => + isStringEquals(activeEffect?.data?.label, effect?.name), + ) + ); + if (effectToRemove) { + setAeToRemove.add(effectToRemove.id); } + await repairAndUnSetFlag(selectedToken, senseId); } else { - warn(`Can't find effect definition for '${senseId}'`, true); + const atcvEffectFlagData = AtcvEffect.fromEffect(selectedToken.document, effect); + atcvEffectFlagData.visionLevelValue = valStealthRoll; + await repairAndSetFlag(selectedToken, senseId, atcvEffectFlagData); } + } else { + warn(`Can't find effect definition for '${senseId}'`, true); } - //@ts-ignore - if (conditionId != AtcvEffectConditionFlags.NONE) { - const effect = await ConditionalVisibilityEffectDefinitions.effect(conditionId); - if (effect) { - if (valStealthRoll == 0) { - // await API.removeEffectOnToken(selectedToken.id, i18n(effect?.name)); - const effectToRemove = ( - actorEffects.find((activeEffect) => - isStringEquals(activeEffect?.data?.label, effect?.name), - ) - ); - if (effectToRemove) { - setAeToRemove.add(effectToRemove.id); - } - await repairAndUnSetFlag(selectedToken, conditionId); - } else { - const atcvEffectFlagData = AtcvEffect.fromEffect(selectedToken.document, effect); - atcvEffectFlagData.visionLevelValue = valStealthRoll; - await repairAndSetFlag(selectedToken, conditionId, atcvEffectFlagData); + } + //@ts-ignore + if (conditionId != AtcvEffectConditionFlags.NONE) { + const effect = await ConditionalVisibilityEffectDefinitions.effect(conditionId); + if (effect) { + if (valStealthRoll == 0) { + // await API.removeEffectOnToken(selectedToken.id, i18n(effect?.name)); + const effectToRemove = ( + actorEffects.find((activeEffect) => + isStringEquals(activeEffect?.data?.label, effect?.name), + ) + ); + if (effectToRemove) { + setAeToRemove.add(effectToRemove.id); } + await repairAndUnSetFlag(selectedToken, conditionId); } else { - warn(`Can't find effect definition for '${conditionId}'`, true); + const atcvEffectFlagData = AtcvEffect.fromEffect(selectedToken.document, effect); + atcvEffectFlagData.visionLevelValue = valStealthRoll; + await repairAndSetFlag(selectedToken, conditionId, atcvEffectFlagData); } + } else { + warn(`Can't find effect definition for '${conditionId}'`, true); } - // FINALLY REMVE ALL THE ACTIVE EFFECT - if (setAeToRemove.size > 0) { - API.removeEffectFromIdOnTokenMultiple(selectedToken.id, Array.from(setAeToRemove)); - } + } + // FINALLY REMVE ALL THE ACTIVE EFFECT + if (setAeToRemove.size > 0) { + API.removeEffectFromIdOnTokenMultiple(selectedToken.id, Array.from(setAeToRemove)); + } // } } }