Skip to content

Commit

Permalink
improvements to world settings moving to player browers.
Browse files Browse the repository at this point in the history
blindTokensControllable setting didn't cause a loss of control when vision was lost unless the player released control.  Fixed to cause loss of control on the next attempt to move the token.
  • Loading branch information
David-Zvekic committed Jul 21, 2021
1 parent e92f591 commit 1239e35
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/davidzvekic)
# Your Tokens Visible v2.6.0
# Your Tokens Visible v2.6.1
*See what you need to see. No more, no less!*
***
A module for Foundry VTT.
Expand Down
36 changes: 18 additions & 18 deletions TokensVisible.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,17 @@ registerSettings();
tokensVisible.panMode = game.settings.get('TokensVisible', 'panMode');
tokensVisible.pushhotkey=game.settings.get('TokensVisible', 'pushhotkey');
tokensVisible.autopanMargin= game.settings.get('TokensVisible', 'autopanningMargin');
tokensVisible.hiddenCanLight = game.settings.get('TokensVisible', 'hiddenCanLight');
tokensVisible.hiddenCanSee = game.settings.get('TokensVisible', 'hiddenCanSee');
tokensVisible.wallsCancelAnimation = game.settings.get('TokensVisible', 'wallsCancelAnimation');
tokensVisible.castRayshotkey =game.settings.get('TokensVisible', 'castRayshotkey');
tokensVisible.sightCachehotkey =game.settings.get('TokensVisible', 'sightCachehotkey');
tokensVisible.setupCombatantMasking(game.settings.get('TokensVisible', 'combatantHidden'));
tokensVisible.tokenAnimationSpeed=game.settings.get('TokensVisible', 'tokenAnimationSpeed') / 10.0;
tokensVisible.tokenMultiVision=game.settings.get('TokensVisible', 'tokenMultiVision');
tokensVisible.blindControllable = game.settings.get('TokensVisible', 'blindTokensControllable');

}
);




function nameToHexA(name) {
return RGBToHexA(nameToRGB(name));
}
Expand Down Expand Up @@ -300,7 +297,7 @@ Hooks.once('ready',() => {
function(wrapped, ...args) {


if (this.data.hidden && this.emitsLight && tokensVisible.hiddenCanLight=="Yes") {
if (this.data.hidden && this.emitsLight && game.settings.get('TokensVisible', 'hiddenCanLight')=="Yes") {
this.data.hidden=false;
const wrappedresult = wrapped(...args);
this.data.hidden=true;
Expand All @@ -316,7 +313,7 @@ Hooks.once('ready',() => {
});

function tokenHasSight (tokenInQuestion){
if (tokenInQuestion.data.hidden && tokensVisible.hiddenCanSee=='No') return false;
if (tokenInQuestion.data.hidden && game.settings.get('TokensVisible', 'hiddenCanSee')=='No') return false;
return tokenInQuestion.hasSight;
}

Expand All @@ -325,8 +322,9 @@ Hooks.once('init', () => {

libWrapper.register(moduleName,'TokenLayer.prototype._getCycleOrder',
function(wrapped,...args){

let observable = wrapped(...args);
if (tokensVisible.blindControllable=='No') {
if (game.settings.get('TokensVisible', 'blindTokensControllable')=='No') {
observable = observable.filter( t => {return tokenHasSight(t) })
}
return observable;
Expand All @@ -336,7 +334,7 @@ Hooks.once('init', () => {
libWrapper.register(moduleName,'Token.prototype.control',
function(wrapped, ...args ) {

if (!game.user.isGM && canvas.sight.tokenVision && !this.hasSight && (tokensVisible.blindControllable=='No')) {
if (!game.user.isGM && canvas.sight.tokenVision && !this.hasSight && (game.settings.get('TokensVisible', 'blindTokensControllable')=='No')) {

this._controlled = true;
// calling the wrapped function will cause clicking a blind owned token to be act like clicking on an unowned token.
Expand All @@ -350,13 +348,13 @@ Hooks.once('init', () => {

libWrapper.register(moduleName,'CanvasAnimation.animateLinear',
function(wrapped, attributes, {context, name, duration, ontick} ) {

const tokenAnimationSpeed=game.settings.get('TokensVisible', 'tokenAnimationSpeed') / 10.0;

if ((tokensVisible.tokenAnimationSpeed!=1 || tokensVisible.cancelTokenAnimation) && name != undefined){
if ((tokenAnimationSpeed!=1 || tokensVisible.cancelTokenAnimation) && name != undefined){
if ((name.substring(0,6)=="Token.") && (name.substring(name.length -16) == ".animateMovement")) {
if (tokensVisible.cancelTokenAnimation) duration=0;
else
duration = duration / tokensVisible.tokenAnimationSpeed ;
duration = duration / tokenAnimationSpeed ;
}
};
return wrapped(attributes,{context,name,duration,ontick});
Expand Down Expand Up @@ -400,7 +398,9 @@ libWrapper.register(moduleName,'Wall.prototype._onUpdate',

libWrapper.register(moduleName,'Token.prototype.isVisible',
function(wrapped) {

const blindTokensControllable = (game.settings.get('TokensVisible', 'blindTokensControllable') == 'Yes');
if (!game.user.isGM && this._controlled && !tokenHasSight(this) && !blindTokensControllable) this.release();

if (wrapped()) return true;

if ( this._controlled ) return true;
Expand All @@ -413,7 +413,7 @@ libWrapper.register(moduleName,'Wall.prototype._onUpdate',
canObserve = this.actor?.hasPerm(game.user, "OBSERVER");
}

if (canObserve && ((tokensVisible.blindControllable == 'Yes') || this._isVisionSource() || !canvas.sight.tokenVision )) return true;
if (canObserve && (blindTokensControllable || !canvas.sight.tokenVision || this._isVisionSource() )) return true;
}
}
return false;
Expand All @@ -425,13 +425,13 @@ libWrapper.register(moduleName,'Wall.prototype._onUpdate',
libWrapper.register(moduleName,'Token.prototype._isVisionSource',
function (wrapped) {


const tokenMultiVision = game.settings.get('TokensVisible', 'tokenMultiVision');
const computerSaysYes = wrapped(); // always chain wrapper even if we may never use the result - on the chance another module needs it's version executed

if (tokensVisible.hiddenCanSee=='No' && tokensVisible.tokenMultiVision=='Limited') return computerSaysYes ;
if (tokenMultiVision=='Limited' && game.settings.get('TokensVisible', 'hiddenCanSee')=='No' ) return computerSaysYes ;

if (computerSaysYes &&
(tokensVisible.tokenMultiVision=='Yes' || this.data._id == tokensVisible.lastControlledToken?.data._id || !canvas.sight.tokenVision)
(tokenMultiVision=='Yes' || this.data._id == tokensVisible.lastControlledToken?.data._id || !canvas.sight.tokenVision)
) return true;


Expand All @@ -442,7 +442,7 @@ libWrapper.register(moduleName,'Wall.prototype._onUpdate',
}
else {
if (!tokenHasSight(this)) return false;
switch(tokensVisible.tokenMultiVision) {
switch(tokenMultiVision) {
case 'Yes':
if ( this.observer ) return true;
case 'Limited' :
Expand Down
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"title": "Your Tokens Visible",
"description": "Usability and vision enhancements for Tokens",
"author": "David Zvekic",
"version": "2.6.0",
"version": "2.6.1",
"compatibleCoreVersion": "0.8.8",
"minimumCoreVersion": "0.7.9",
"url":"https://github.com/David-Zvekic/TokensVisible",
"manifest": "https://github.com/David-Zvekic/TokensVisible/releases/download/v2.6.0/module.json",
"download": "https://github.com/David-Zvekic/TokensVisible/releases/download/v2.6.0/TokensVisible.zip",
"manifest": "https://github.com/David-Zvekic/TokensVisible/releases/download/v2.6.1/module.json",
"download": "https://github.com/David-Zvekic/TokensVisible/releases/download/v2.6.1/TokensVisible.zip",
"esmodules": [
"./lib/colorsettings/colorSetting.js", "TokensVisible.js"
],
Expand Down
16 changes: 7 additions & 9 deletions settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export function registerSettings() {
scope: 'world',
config: true,
type: Number,
default: "10",
onChange: value => { tokensVisible.tokenAnimationSpeed = value / 10.0; }
default: "10"

});


Expand All @@ -29,8 +29,8 @@ export function registerSettings() {
"Limited": game.i18n.localize(MODULE_ID+".tokenMultiVisionLimited"),
"Never": game.i18n.localize(MODULE_ID+".tokenMultiVisionNever")
},
default: "Limited",
onChange: value => { tokensVisible.tokenMultiVision= value; }
default: "Limited"

});


Expand Down Expand Up @@ -146,8 +146,7 @@ export function registerSettings() {
"Yes": game.i18n.localize(MODULE_ID+".hiddenCanLightYES"),
"No": game.i18n.localize(MODULE_ID+".hiddenCanLightNO"),
},
default: "Yes",
onChange: value => { tokensVisible.hiddenCanLight = value }
default: "Yes"
});


Expand All @@ -161,8 +160,7 @@ export function registerSettings() {
"Yes": game.i18n.localize(MODULE_ID+".hiddenCanSeeYES"),
"No": game.i18n.localize(MODULE_ID+".hiddenCanSeeNO"),
},
default: "Yes",
onChange: value => { tokensVisible.hiddenCanSee = value }
default: "Yes"
});


Expand All @@ -178,7 +176,7 @@ export function registerSettings() {
"No": game.i18n.localize(MODULE_ID+".blindTokensControllableNO"),
},
default: "Yes",
onChange: value => { tokensVisible.blindControllable = value }
onChange: value => { tokensVisible.blindControllable = value ; }
});


Expand Down

0 comments on commit 1239e35

Please sign in to comment.