Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
version 0.6.9
Browse files Browse the repository at this point in the history
  • Loading branch information
p4535992 committed Jun 4, 2022
1 parent 056df3d commit 66144f9
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 229 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 0.6.9

- Bug fix [[BUG] Auto Roll not apply DF Convenient effect edit](https://github.com/p4535992/conditional-visibility/issues/42)

### 0.6.8

- Bug fix [[BUG] "Key.split is not a function or its return value is not iterable"](https://github.com/p4535992/conditional-visibility/issues/44)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=\"https://www.flaticon.com/authors/freepik\" title=\"Freepik\">Freepik</a>, from <a href=\"https://www.flaticon.com/\" title=\"Flaticon\"> www.flaticon.com</a>. Moon icon made by <a href=\"https://www.flaticon.com/authors/iconixar\" title=\"iconixar\">iconixar</a> from <a href=\"https://www.flaticon.com/\" title=\"Flaticon\"> www.flaticon.com</a>",
"version": "0.6.8",
"version": "0.6.9",
"scripts": {
"package": "gulp package",
"build": "gulp build && gulp link",
Expand Down
6 changes: 3 additions & 3 deletions src/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=\"https://www.flaticon.com/authors/freepik\" title=\"Freepik\">Freepik</a>, from <a href=\"https://www.flaticon.com/\" title=\"Flaticon\"> www.flaticon.com</a>. Moon icon made by <a href=\"https://www.flaticon.com/authors/iconixar\" title=\"iconixar\">iconixar</a> from <a href=\"https://www.flaticon.com/\" title=\"Flaticon\"> www.flaticon.com</a>",
"version": "0.6.8",
"version": "0.6.9",
"author": "Greg Ludington, p4535992, Szefo09, Teshynil",
"authors": [
{ "name": "Greg Ludington" },
Expand Down Expand Up @@ -78,8 +78,8 @@
"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/latest/download/module.zip",
"readme": "https://github.com/p4535992/conditional-visibility/blob/v0.6.8/README.md",
"changelog": "https://github.com/p4535992/conditional-visibility/blob/v0.6.8/changelog.md",
"readme": "https://github.com/p4535992/conditional-visibility/blob/v0.6.9/README.md",
"changelog": "https://github.com/p4535992/conditional-visibility/blob/v0.6.9/changelog.md",
"bugs": "https://github.com/p4535992/conditional-visibility/issues",
"allowBugReporter": true,
"dependencies": [
Expand Down
120 changes: 7 additions & 113 deletions src/module/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {
info,
isStringEquals,
is_real_number,
manageActiveEffectForAutoSkillsFeature,
prepareActiveEffectForConditionalVisibility,
renderAutoSkillsDialog,
repairAndSetFlag,
repairAndUnSetFlag,
retrieveAndMergeEffect,
retrieveAtcvVisionLevelKeyFromChanges,
retrieveEffectChangeDataFromAtcvEffect,
retrieveEffectChangeDataFromEffect,
Expand Down Expand Up @@ -882,115 +882,9 @@ const API = {
visionLevel = 0;
}

const effectsDefinition = await ConditionalVisibilityEffectDefinitions.all(distance, visionLevel);

let effect: Effect | undefined = undefined;
//let senseData: SenseData | undefined = undefined;

// const senseDataId = senseDataEffect.visionId;
// for (const sense of sensesAndConditionOrderByName) {
// // Check for dfred convenient effect and retrieve the effect with the specific name
// // https://github.com/DFreds/dfreds-convenient-effects/issues/110
// if (isStringEquals(senseDataId, sense.id)) {
// //@ts-ignore
// if (game.dfreds) {
// //@ts-ignore
// effect = <Effect>await game.dfreds.effectInterface.findCustomEffectByName(effectToFoundByName);
// if (effect) {
// //senseData = sense;
// break;
// }
// }
// effect = <Effect>effectsDefinition.find((effect: Effect) => {
// return isStringEquals(effect.customId, sense.id) || isStringEquals(effect.name, sense.name);
// });
// //senseData = sense;
// break;
// }
// }
let changesTmp: any[] = [];
// Check for dfred convenient effect and retrieve the effect with the specific name
// https://github.com/DFreds/dfreds-convenient-effects/issues/110
//@ts-ignore
if (game.modules.get('dfreds-convenient-effects')?.active && game.dfreds && game.dfreds.effectInterface) {
let effectToFoundByName = i18n(senseDataEffect.visionName);
if (!effectToFoundByName.endsWith('(CV)')) {
effectToFoundByName = effectToFoundByName + ' (CV)';
}
//@ts-ignore
const dfredEffect = <Effect>await game.dfreds.effectInterface.findCustomEffectByName(effectToFoundByName);
if (dfredEffect) {
if (game.user?.isGM) {
info(
`ATTENTION the module 'DFreds Convenient Effects' has a effect with name '${effectToFoundByName}', so we use that, edit that effect if you want to apply a customize solution`,
);
}
let foundedFlagVisionValue = false;
if (!dfredEffect.atcvChanges) {
dfredEffect.atcvChanges = [];
}
changesTmp = retrieveEffectChangeDataFromEffect(dfredEffect);
changesTmp = changesTmp.filter((c) => !c.key.startsWith(`data.`));
/*
changesTmp = EffectSupport._handleIntegrations(dfredEffect);
changesTmp = changesTmp.filter((c) => !c.key.startsWith(`data.`));
if (senseDataEffect.visionDistanceValue && senseDataEffect.visionDistanceValue > 0) {
changesTmp.push({
key: 'ATCV.conditionDistance',
mode: CONST.ACTIVE_EFFECT_MODES.CUSTOM,
value: `${senseDataEffect.visionDistanceValue}`,
priority: 5,
});
}
for (const obj of changesTmp) {
if (obj.key === 'ATCV.' + senseDataEffect.visionId && obj.value != String(senseDataEffect.visionLevelValue)) {
obj.value = String(senseDataEffect.visionLevelValue);
foundedFlagVisionValue = true;
break;
}
}
*/

if (!foundedFlagVisionValue) {
for (const obj of changesTmp) {
if (
obj.key === 'ATCV.' + senseDataEffect.visionId &&
obj.value != String(senseDataEffect.visionLevelValue)
) {
obj.value = String(senseDataEffect.visionLevelValue);
foundedFlagVisionValue = true;
break;
}
}
}
if (!foundedFlagVisionValue) {
// 2022-05-26 check for duplicate
const valueKey = retrieveAtcvVisionLevelKeyFromChanges(changesTmp);
if (!valueKey) {
senseDataEffect = AtcvEffect.mergeWithSensedataDefault(senseDataEffect);
if (!senseDataEffect.visionName.endsWith('(CV)')) {
senseDataEffect.visionName = senseDataEffect.visionName + ' (CV)';
}
changesTmp = retrieveEffectChangeDataFromAtcvEffect(senseDataEffect);
foundedFlagVisionValue = true;
}
}
effect = <Effect>duplicateExtended(dfredEffect);
if (effect) {
effect.changes = duplicateExtended(changesTmp);
} else {
warn(`Found dfred active effect ${effectToFoundByName} but can't clone...`);
}
}
}
if (!effect) {
effect = <Effect>effectsDefinition.find((effect: Effect) => {
return (
isStringEquals(effect.customId, senseDataEffect.visionId) ||
isStringEquals(effect.name, senseDataEffect.visionName)
);
});
}
let effect:Effect = <Effect>await retrieveAndMergeEffect(
senseDataEffect.visionId, senseDataEffect.visionName,
distance, visionLevel);

const isSense = senseDataEffect.visionType === 'sense';
if (!effect) {
Expand Down Expand Up @@ -1021,7 +915,7 @@ const API = {
});
}
*/
changesTmp = retrieveEffectChangeDataFromAtcvEffect(senseDataEffect);
const changesTmp = retrieveEffectChangeDataFromAtcvEffect(senseDataEffect);
effect = EffectSupport.buildDefault(
senseOrCondition.visionId,
senseOrCondition.visionName,
Expand Down Expand Up @@ -1052,7 +946,7 @@ const API = {
});
}
*/
changesTmp = retrieveEffectChangeDataFromAtcvEffect(senseDataEffect);
const changesTmp = retrieveEffectChangeDataFromAtcvEffect(senseDataEffect);
effect = EffectSupport.buildDefault(
senseDataEffect.visionId,
senseDataEffect.visionName,
Expand All @@ -1066,7 +960,7 @@ const API = {
}
}
// TODO check if we need this ??? ADDED 2022-05-22
else if (changesTmp.length == 0) {
else if (EffectSupport._handleIntegrations(effect)?.length == 0) {
info(`The use case 'changesTmp.length==0' should not be happening`);
const effectTmp = AtcvEffect.toEffectFromAtcvEffect(senseDataEffect);
effect.changes = effectTmp.changes;
Expand Down
116 changes: 12 additions & 104 deletions src/module/conditional-visibility-effect-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
info,
isStringEquals,
mergeByProperty,
retrieveAndMergeEffect,
retrieveEffectChangeDataFromEffect,
warn,
} from './lib/lib';
Expand Down Expand Up @@ -98,117 +99,24 @@ export class ConditionalVisibilityEffectDefinitions {
indarkness.atcvChanges = AtcvEffect.retrieveAtcvChangesFromEffect(indarkness);
effects.push(indarkness);
}

for (const effectExternal of API.EFFECTS) {
let effectFounded = <Effect>effects.find((effect: Effect) => {
return (
isStringEquals(effect.name, effectExternal.name) || isStringEquals(effect.customId, effectExternal.customId)
);
});
if (!effectFounded && effectExternal) {
// Before launch error check dfred effects
// Check for dfred convenient effect and retrieve the effect with the specific name
// https://github.com/DFreds/dfreds-convenient-effects/issues/110
//@ts-ignore
if (game.modules.get('dfreds-convenient-effects')?.active && game.dfreds && game.dfreds.effectInterface) {
let changesTmp: any[] = [];
let effectToFoundByName = i18n(effectExternal.name);
if (!effectToFoundByName.endsWith('(CV)')) {
effectToFoundByName = effectToFoundByName + ' (CV)';
}
//@ts-ignore
const dfredEffect = <Effect>await game.dfreds.effectInterface.findCustomEffectByName(effectToFoundByName);
if (dfredEffect) {
if (game.user?.isGM) {
info(
`ATTENTION the module 'DFreds Convenient Effects' has a effect with name '${effectToFoundByName}', so we use that, edit that effect if you want to apply a customize solution`,
);
}
let foundedFlagVisionValue = false;
if (!dfredEffect.atcvChanges) {
dfredEffect.atcvChanges = [];
}
/*
changesTmp = EffectSupport._handleIntegrations(dfredEffect);
changesTmp = changesTmp.filter((c) => !c.key.startsWith(`data.`));
if (distance && distance > 0) {
changesTmp.push({
key: 'ATCV.conditionDistance',
mode: CONST.ACTIVE_EFFECT_MODES.CUSTOM,
value: `${distance}`,
priority: 5,
});
}
*/
changesTmp = retrieveEffectChangeDataFromEffect(dfredEffect);
changesTmp = changesTmp.filter((c) => !c.key.startsWith(`data.`));
for (const obj of changesTmp) {
if (obj.key === 'ATCV.' + effectExternal.customId && obj.value != String(visionLevel)) {
obj.value = String(visionLevel);
foundedFlagVisionValue = true;
break;
}
}
if (!foundedFlagVisionValue) {
for (const obj of changesTmp) {
if (obj.key === 'ATCV.' + effectExternal.customId && obj.value != String(visionLevel)) {
obj.value = String(visionLevel);
foundedFlagVisionValue = true;
break;
}
}
}
if (!foundedFlagVisionValue) {
changesTmp.push(<any>{
key: 'ATCV.' + effectExternal.customId,
mode: CONST.ACTIVE_EFFECT_MODES.CUSTOM,
value: String(visionLevel),
priority: 5,
});
}
let foundedFlagVisionType = false;
for (const obj of changesTmp) {
if (obj.key === 'ATCV.conditionType' && obj.value) {
foundedFlagVisionType = true;
break;
}
}
if (!foundedFlagVisionType) {
changesTmp.push({
key: 'ATCV.conditionType',
mode: CONST.ACTIVE_EFFECT_MODES.CUSTOM,
value: 'sense',
priority: 5,
});
}
effectFounded = <Effect>duplicateExtended(dfredEffect);
if (!effectFounded.name.endsWith('(CV)')) {
effectFounded.name = effectFounded.name + ' (CV)';
}
if (effectFounded) {
effectFounded.changes = duplicateExtended(changesTmp);
} else {
warn(`Found dfred active effect ${effectToFoundByName} but can't clone...`);
}
}
}
if (effectFounded) {
effects.push(effectFounded);
} else {
effects.push(effectExternal);
}
if(effectExternal.customId){
effects.push(effectExternal);
}
}
return effects;
}

static async effect(nameOrCustomId: string, distance = 0, visionLevel = 0): Promise<Effect | undefined> {
/*
static async effect(effectCustomId: string, distance = 0, visionLevel = 0): Promise<Effect | undefined> {
const effectsToCheck = await ConditionalVisibilityEffectDefinitions.all(distance, visionLevel);
const effect = effectsToCheck.find((effect: Effect) => {
return isStringEquals(effect.name, nameOrCustomId) || isStringEquals(effect.customId, nameOrCustomId);
const effectTmp = effectsToCheck.find((effect: Effect) => {
return isStringEquals(effect.name, effectCustomId) || isStringEquals(effect.customId, effectCustomId);
});
const effect = await retrieveAndMergeEffect(
<string>effectTmp?.customId,<string>effectTmp?.name,
distance, visionLevel);
if (!effect) {
warn(`Not founded effect with name ${nameOrCustomId}`, true);
warn(`Not founded effect with id '${effectCustomId}' and name '${effectCustomId}'`, true);
return undefined;
}
//const senses = await API.getAllDefaultSensesAndConditions();
Expand All @@ -226,7 +134,7 @@ export class ConditionalVisibilityEffectDefinitions {
}
return effectFounded;
}

*/
// ===========================================
// The source effect
// =============================================
Expand Down
Loading

0 comments on commit 66144f9

Please sign in to comment.