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.11
Browse files Browse the repository at this point in the history
  • Loading branch information
p4535992 committed Jun 7, 2022
1 parent c9aa66d commit b752d25
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 28 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### 0.6.11

- Bug fix API
- Update API
- Bug fix again [[BUG] (Maybe). api.canSee returns true when rolled by a player, but false when rolled by a GM](https://github.com/p4535992/conditional-visibility/issues/41)
- Update checker add check for both token are owned from a non GM user.

### 0.6.10

- Update API
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.10",
"version": "0.6.11",
"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.10",
"version": "0.6.11",
"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.10/README.md",
"changelog": "https://github.com/p4535992/conditional-visibility/blob/v0.6.10/changelog.md",
"readme": "https://github.com/p4535992/conditional-visibility/blob/v0.6.11/README.md",
"changelog": "https://github.com/p4535992/conditional-visibility/blob/v0.6.11/changelog.md",
"bugs": "https://github.com/p4535992/conditional-visibility/issues",
"allowBugReporter": true,
"dependencies": [
Expand Down
85 changes: 69 additions & 16 deletions src/module/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,33 +842,86 @@ const API = {
for (const atcvEffect of arr2) {
repairAndUnSetFlag(token, atcvEffect.visionId);
}
if (
game.modules.get('midi-qol')?.active &&
<boolean>(<any>(<any>game.settings.get('midi-qol', 'ConfigSettings'))?.optionalRules)?.removeHiddenInvis
) {
await token.actor?.unsetFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE);
}
// if (
// game.modules.get('midi-qol')?.active &&
// <boolean>(<any>(<any>game.settings.get('midi-qol', 'ConfigSettings'))?.optionalRules)?.removeHiddenInvis
// ) {
// await token.actor?.unsetFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE);
// }
}
},

async forceToBeVisible(token: Token) {
if (!token.actor?.getFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE)) {
await token.actor?.setFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE, true);
}
},

async unforceToBeVisible(token: Token) {
if (token.actor?.getFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE)) {
await token.actor?.unsetFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE);
}
},

/**
*
* @param tokens @deprecated to remove
* @param conditionId
* @param disabled
*/
async setCondition(tokens: Token[], conditionId: string, disabled: boolean): Promise<void> {
for (const token of tokens) {
if (
game.modules.get('midi-qol')?.active &&
<boolean>(<any>(<any>game.settings.get('midi-qol', 'ConfigSettings'))?.optionalRules)?.removeHiddenInvis
) {
await token.actor?.unsetFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE);
}
const sourceVisionLevels = getConditionsFromTokenFast(token.document, true) ?? [];
for (const sourceVision of sourceVisionLevels) {
if (isStringEquals(sourceVision.visionId, conditionId)) {
const atcvEffect = sourceVision; //AtcvEffect.fromSenseData(senseDataEffect, 1);
// if (
// game.modules.get('midi-qol')?.active &&
// <boolean>(<any>(<any>game.settings.get('midi-qol', 'ConfigSettings'))?.optionalRules)?.removeHiddenInvis
// ) {
// await token.actor?.unsetFlag(CONSTANTS.MODULE_NAME, ConditionalVisibilityFlags.FORCE_VISIBLE);
// }
const targetVisionLevels = getConditionsFromTokenFast(token.document, true) ?? [];
for (const targetVision of targetVisionLevels) {
if (isStringEquals(targetVision.visionId, conditionId)) {
const atcvEffect = targetVision; //AtcvEffect.fromSenseData(senseDataEffect, 1);
await token.actor?.setFlag(CONSTANTS.MODULE_NAME, conditionId, atcvEffect);
}
}
}
},

hasConditionFromId(tokenNameOrId: string, conditionId: string): boolean {
const tokens = <Token[]>canvas.tokens?.placeables;
const token = <Token>tokens.find((token) => {
return isStringEquals(token.name, i18n(tokenNameOrId)) || isStringEquals(token.id, tokenNameOrId);
});
if (!token) {
warn(`No token found with reference '${tokenNameOrId}'`, true);
}
let foundedCondition = false;
const targetVisionLevels = getConditionsFromTokenFast(token.document, true) ?? [];
for (const targetVision of targetVisionLevels) {
if (isStringEquals(targetVision.visionId, conditionId)) {
foundedCondition = true;
break;
}
}
return foundedCondition;
},

hasCondition(token: Token, conditionId: string): boolean {
if (!token) {
warn(`No token found with reference'`, true);
return false;
}
let foundedCondition = false;
const targetVisionLevels = getConditionsFromTokenFast(token.document, true) ?? [];
for (const targetVision of targetVisionLevels) {
if (isStringEquals(targetVision.visionId, conditionId)) {
foundedCondition = true;
break;
}
}
return foundedCondition;
},

async addOrUpdateEffectConditionalVisibilityOnToken(
tokenNameOrId: string,
senseDataEffect: AtcvEffect,
Expand Down
25 changes: 17 additions & 8 deletions src/module/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,20 @@ export function _getCVFromTokenFast(
}
const actorEffects = <EmbeddedCollection<typeof ActiveEffect, ActorData>>actor?.data.effects;
//const totalEffects = <EmbeddedCollection<typeof ActiveEffect, ActorData>>actor?.data.effects.contents.filter(i => !i.data.disabled);
const atcvEffects = actorEffects.filter((entity) => {
return (
!!entity.data.changes.find((effect) => effect.key.includes('ATCV')) && filterIsDisabled && !entity.data.disabled
);
let atcvEffects = actorEffects.filter((entity) => {
return !!entity.data.changes.find((effect) => effect.key.includes('ATCV'));
});

if (filterIsDisabled) {
atcvEffects = atcvEffects.filter((entity) => {
const isDisabled = <any>entity.data.disabled;
if(is_real_number(isDisabled)){
//@ts-ignore
return entity.data.disabled <= 0;
}else{
return !entity.data.disabled;
}
});
}
if (atcvEffects != null && atcvEffects != undefined) {
for (const effectEntity of atcvEffects) {
const effectNameToSet = effectEntity.name ? effectEntity.name : effectEntity.data.label;
Expand Down Expand Up @@ -1210,7 +1218,7 @@ export function retrieveAtcvEffectFromActiveEffect(
try {
// TODO Roll#evaluate is becoming asynchronous. In the short term you may pass async=true or async=false
// to evaluation options to nominate your preferred behavior.
roll.evaluate({async: false});
roll.evaluate({ async: false });
//await roll.evaluate({async: true});
myresult = roll.total ? <number>roll.total : parseInt(roll.result);
} catch (e) {
Expand Down Expand Up @@ -1922,8 +1930,9 @@ export function shouldIncludeVisionV2(sourceToken: Token, targetToken: Token): C

// 2) Check if the target is owned from the player if true you can see the token.
//const isPlayerOwned = <boolean>targetToken.actor?.hasPlayerOwner;
const isPlayerOwned = <boolean>targetToken.isOwner;
if (!game.user?.isGM && (isPlayerOwned || targetToken.owner)) {
const isTargetPlayerOwned = <boolean>targetToken.isOwner || targetToken.owner;
const issourcePlayerOwned = <boolean>sourceToken.isOwner || sourceToken.owner;
if (!game.user?.isGM && isTargetPlayerOwned && issourcePlayerOwned) {
debug(`(2) Is true, '${sourceToken.data.name}' can see '${targetToken.data.name}'`);
// return true;
return {
Expand Down
42 changes: 42 additions & 0 deletions wiki/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,48 @@ A method to force a array of tokens to be visible to everyone with a specific f
| tokens | <code>Token[]</code> | The array of tokens to make visible to everyone | <code>undefined</code> |


### async game.modules.get('conditional-visibility').api.forceToBeVisible(token: Token) ⇒ <code>Promise.&lt;void&gt;</code>

A method to force a token to be visibile for the CV checker

**Returns**: <code>Promise.&lt;void&gt;</code>

| Param | Type | Description | Default |
| --- | --- | --- | --- |
| token | <code>string</code> | The token to show | <code>undefined</code> |

### async game.modules.get('conditional-visibility').api.unforceToBeVisible(token:Token) ⇒ <code>Promise.&lt;void&gt;</code>

A method to unforce a token to be visibile for the CV checker, the cheker will work on effects anyway.

**Returns**: <code>Promise.&lt;void&gt;</code>

| Param | Type | Description | Default |
| --- | --- | --- | --- |
| token | <code>string</code> | The token to hide | <code>undefined</code> |

### game.modules.get('conditional-visibility').api.hasConditionFromId(tokenNameOrId:string, conditionId:string):boolean{

A method to check if a source token can has a specific condition

**Returns**: <code>boolean</code>

| Param | Type | Description | Default |
| --- | --- | --- | --- |
| tokenNameOrId | <code>string</code> | The reference to the token | <code>undefined</code> |
| conditionId | <code>string</code> | The id of the condition | <code>undefined</code> |

### game.modules.get('conditional-visibility').api.hasCondition(token:Token, conditionId:string):boolean ⇒ <code>boolean</code>

A method to check if a source token can has a specific condition

**Returns**: <code>boolean</code>

| Param | Type | Description | Default |
| --- | --- | --- | --- |
| token | <code>string</code> | The source token | <code>undefined</code> |
| conditionId | <code>string</code> | The id of the condition | <code>undefined</code> |

### game.modules.get('conditional-visibility').api.canSee(sourceToken: Token, targetToken: Token) ⇒ <code>boolean</code>

A method to check if a source token can see a target token
Expand Down

0 comments on commit b752d25

Please sign in to comment.