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

Commit

Permalink
version 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
p4535992 committed Dec 20, 2021
1 parent ba10c64 commit 3559761
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [0.2.13] Sync with [szefo09](https://github.com/szefo09/conditional-visibility)

- Sync with [szefo09](https://github.com/szefo09/conditional-visibility) (2021-12-20)
- Add some little check for typescript code

## [0.2.12] (ABBANDONED THE PROJECT)

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.2.13",
"version": "0.3.0",
"scripts": {
"package": "gulp package",
"build": "gulp build && gulp link",
Expand Down
8 changes: 4 additions & 4 deletions src/conditional-visibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export const setDebugLevel = (debugText: string): void => {
/* Initialize module */
/* ------------------------------------ */
Hooks.once('init', async function () {
// if (getGame().modules.get("levels")?.active) {
// return error("Conditional Visibility does not currently work with Levels module. Initialization stopped.");
// }
log(' init ' + CONDITIONAL_VISIBILITY_MODULE_NAME);
// Assign custom classes and constants here

Expand Down Expand Up @@ -86,7 +83,10 @@ Hooks.once('libChangelogsReady', function () {
//@ts-ignore
libChangelogs.register(
CONDITIONAL_VISIBILITY_MODULE_NAME,
'- Sync with [szefo09](https://github.com/szefo09/conditional-visibility) (2021-12-20)',
`
- Sync with [szefo09](https://github.com/szefo09/conditional-visibility) (2021-12-20)
- Add some little check for typescript code
`,
'minor',
);
});
8 changes: 4 additions & 4 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.2.13",
"version": "0.3.0",
"author": "Greg Ludington, p4535992, Szefo09, Teshynil",
"type": "module",
"socket": true,
Expand Down Expand Up @@ -62,9 +62,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.2.13/module.zip",
"readme": "https://github.com/p4535992/conditional-visibility/blob/v0.2.13/README.md",
"changelog": "https://github.com/p4535992/conditional-visibility/blob/v0.2.13/changelog.md",
"download": "https://github.com/p4535992/conditional-visibility/releases/download/v0.3.0/module.zip",
"readme": "https://github.com/p4535992/conditional-visibility/blob/v0.3.0/README.md",
"changelog": "https://github.com/p4535992/conditional-visibility/blob/v0.3.0/changelog.md",
"bugs": "https://github.com/p4535992/conditional-visibility/issues",
"allowBugReporter": true,
"dependencies": [
Expand Down
61 changes: 59 additions & 2 deletions src/module/ConditionalVisibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,46 @@ export class ConditionalVisibility {
*/
static onInit(): void {
const system = ConditionalVisibility.newSystem();
if (!getGame().modules.get('levels')?.active) {
//@ts-ignore
const realIsVisible: any = Object.getOwnPropertyDescriptor(Token.prototype, 'isVisible').get;
Object.defineProperty(Token.prototype, 'isVisible', {
get: function () {
const isVisible = realIsVisible.call(this);
if (isVisible === false) {
return false;
}
if (getGame().user?.isGM || this.owner || !getCanvas().sight?.tokenVision) {
return true;
}
return ConditionalVisibility.canSee(this);
},
});
} else {
//@ts-ignore
libWrapper.ignore_conflicts(
CONDITIONAL_VISIBILITY_MODULE_NAME,
['perfect-vision'],
'Levels.prototype.overrideVisibilityTest',
);
//@ts-ignore
const lw = libWrapper.register(
CONDITIONAL_VISIBILITY_MODULE_NAME,
'Levels.prototype.overrideVisibilityTest',
ConditionalVisibility.overrideVisibilityTestCV,
'MIXED',
);
}
system.initializeStatusEffects();
}

static overrideVisibilityTestCV(wrapped, ...args) {
const targetToken = args[1];
const flags = ConditionalVisibility.INSTANCE._conditionalVisibilitySystem.getVisionCapabilities(
ConditionalVisibility.INSTANCE._getSrcTokens(),
);
const isCVVisible = ConditionalVisibility.INSTANCE._conditionalVisibilitySystem.canSee(targetToken, flags);
return isCVVisible ? wrapped(...args) : false;
}
isSemvarGreater(first: string, second: string): Boolean {
const firstSemVar = this.splitOnDot(first);
const secondSemVar = this.splitOnDot(second);
Expand Down Expand Up @@ -117,7 +154,7 @@ export class ConditionalVisibility {
constructor(sightLayer: SightLayer, tokenHud: TokenHUD) {
this._conditionalVisibilitySystem = ConditionalVisibility.newSystem();
this._sightLayer = sightLayer;

// TO BE REMOVED 2021-12-20 in favor of levels dependencies
log(' starting against v0.7 or greater instance ' + getGame().data.version);
this._getSrcTokens = () => {
const srcTokens: Token[] = [];
Expand Down Expand Up @@ -254,6 +291,26 @@ export class ConditionalVisibility {
}
}
};
// END REMOVED 2021-12-20 in favor of levels dependencies
if(!getGame().modules.get("levels")?.active){
const realRestrictVisibility = sightLayer.restrictVisibility;
this._sightLayer.restrictVisibility = () => {
this._capabilities = this._conditionalVisibilitySystem.getVisionCapabilities(this._getSrcTokens());
realRestrictVisibility.call(this._sightLayer);
const restricted = getCanvas().tokens?.placeables.filter(token => token.visible);
if (restricted && restricted.length > 0) {
const srcTokens = this._getSrcTokens();
if (srcTokens.length > 0) {
const flags = this._conditionalVisibilitySystem.getVisionCapabilities(srcTokens);
for (const t of restricted) {
if (srcTokens.indexOf(t) < 0) {
t.visible = this._conditionalVisibilitySystem.canSee(t, flags);
}
}
}
}
}
};
const realTestVisiblity = sightLayer.testVisibility;
this._sightLayer.testVisibility = (point, options) => {
return realTestVisiblity.call(this._sightLayer, point, options);
Expand Down
74 changes: 38 additions & 36 deletions src/module/systems/DefaultConditionalVisibilitySystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,50 +146,52 @@ export class DefaultConditionalVisibilitySystem implements ConditionalVisibility
initializeOnToggleEffect(tokenHud: TokenHUD): void {}

getVisionCapabilities(srcToken: Array<Token> | Token): VisionCapabilities {
if (srcToken)
const flags: VisionCapabilities = new VisionCapabilities();
if (srcToken){
//In case of sending an array only take the first element
srcToken = srcToken instanceof Array ? srcToken[0] : srcToken;
const flags: VisionCapabilities = new VisionCapabilities();

let _seeinvisible =
<number>(
srcToken?.data?.document?.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, StatusEffectSightFlags.SEE_INVISIBLE)
) ?? 0; // 'seeinvisible'
}
if (srcToken){
let _seeinvisible =
<number>(
srcToken?.data?.document?.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, StatusEffectSightFlags.SEE_INVISIBLE)
) ?? 0; // 'seeinvisible'

let _blindsight =
<number>(
srcToken?.data?.document?.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, StatusEffectSightFlags.BLIND_SIGHT)
) ?? 0; // 'blindsight'
let _blindsight =
<number>(
srcToken?.data?.document?.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, StatusEffectSightFlags.BLIND_SIGHT)
) ?? 0; // 'blindsight'

let _tremorsense =
<number>(
srcToken?.data?.document?.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, StatusEffectSightFlags.TREMOR_SENSE)
) ?? 0; // 'tremorsense'
let _tremorsense =
<number>(
srcToken?.data?.document?.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, StatusEffectSightFlags.TREMOR_SENSE)
) ?? 0; // 'tremorsense'

let _truesight =
<number>(
srcToken?.data?.document?.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, StatusEffectSightFlags.TRUE_SIGHT)
) ?? 0; // 'truesight'
let _truesight =
<number>(
srcToken?.data?.document?.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, StatusEffectSightFlags.TRUE_SIGHT)
) ?? 0; // 'truesight'

let _devilssight =
<number>(
srcToken?.data?.document?.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, StatusEffectSightFlags.DEVILS_SIGHT)
) ?? 0; // 'devilssight'
_seeinvisible = _seeinvisible < 0 ? 100000 : _seeinvisible;
_blindsight = _blindsight < 0 ? 100000 : _blindsight;
_tremorsense = _tremorsense < 0 ? 100000 : _tremorsense;
_truesight = _truesight < 0 ? 100000 : _truesight;
_devilssight = _devilssight < 0 ? 100000 : _devilssight;
let _devilssight =
<number>(
srcToken?.data?.document?.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, StatusEffectSightFlags.DEVILS_SIGHT)
) ?? 0; // 'devilssight'
_seeinvisible = _seeinvisible < 0 ? 100000 : _seeinvisible;
_blindsight = _blindsight < 0 ? 100000 : _blindsight;
_tremorsense = _tremorsense < 0 ? 100000 : _tremorsense;
_truesight = _truesight < 0 ? 100000 : _truesight;
_devilssight = _devilssight < 0 ? 100000 : _devilssight;

flags.seeinvisible = Math.max(_seeinvisible, _blindsight, _tremorsense, _truesight, _devilssight);
flags.seeobscured = Math.max(_blindsight, _tremorsense);
flags.seeindarkness = Math.max(_blindsight, _devilssight, _tremorsense, _truesight);
//@ts-ignore
if (srcToken._movement !== null) {
flags.seeinvisible = Math.max(_seeinvisible, _blindsight, _tremorsense, _truesight, _devilssight);
flags.seeobscured = Math.max(_blindsight, _tremorsense);
flags.seeindarkness = Math.max(_blindsight, _devilssight, _tremorsense, _truesight);
//@ts-ignore
flags.visionfrom = srcToken._movement.B;
} else {
flags.visionfrom = srcToken?.position ?? { x: 0, y: 0 };
if (srcToken?._movement !== null) {
//@ts-ignore
flags.visionfrom = srcToken._movement.B;
} else {
flags.visionfrom = srcToken?.position ?? { x: 0, y: 0 };
}
}
return flags;
}
Expand Down

0 comments on commit 3559761

Please sign in to comment.