From 272491b44d70d020bde4a97aee336bcb789a5311 Mon Sep 17 00:00:00 2001 From: Haka <76921756+Hakorr@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:06:39 +0300 Subject: [PATCH] Fix for old configs & arrow opacity affects GUI too --- assets/js/acas-backend-instance.js | 19 ++++++++++--------- assets/js/acas-globals.js | 22 +++++++++++----------- index.html | 16 +++++++--------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/assets/js/acas-backend-instance.js b/assets/js/acas-backend-instance.js index 8739a10..6ab6e27 100644 --- a/assets/js/acas-backend-instance.js +++ b/assets/js/acas-backend-instance.js @@ -172,31 +172,31 @@ class BackendInstance { } } - getArrowStyle(type, fill) { + getArrowStyle(type, fill, opacity) { const baseStyleArr = [ 'stroke: rgb(0 0 0 / 50%);', 'stroke-width: 2px;', 'stroke-linejoin: round;' ]; - + switch(type) { case 'best': return [ - `fill: ${fill ? fill : 'limegreen'};`, - 'opacity: 0.9;', + `fill: ${fill || 'limegreen'};`, + `opacity: ${opacity || 0.9};`, ...baseStyleArr ].join('\n'); case 'secondary': return [ ...baseStyleArr, `fill: ${fill ? fill : 'dodgerblue'};`, - 'opacity: 0.7;' + `opacity: ${opacity || 0.7};`, ].join('\n'); case 'opponent': return [ ...baseStyleArr, `fill: ${fill ? fill : 'crimson'};`, - 'opacity: 0.5;' + `opacity: ${opacity || 0.3};`, ].join('\n'); } }; @@ -209,6 +209,7 @@ class BackendInstance { const maxScale = 1; const minScale = 0.5; const totalRanks = moveObjArr.length; + const arrowOpacity = this.getConfigValue(this.configKeys.arrowOpacity, profile) / 100; const showOpponentMoveGuess = this.getConfigValue(this.configKeys.showOpponentMoveGuess, profile); const showOpponentMoveGuessConstantly = this.getConfigValue(this.configKeys.showOpponentMoveGuessConstantly, profile); const primaryArrowColorHex = this.getConfigValue(this.configKeys.primaryArrowColorHex, profile); @@ -223,14 +224,14 @@ class BackendInstance { let playerArrowElem = null; let oppArrowElem = null; - let arrowStyle = this.getArrowStyle('best', primaryArrowColorHex); + let arrowStyle = this.getArrowStyle('best', primaryArrowColorHex, arrowOpacity); let lineWidth = 30; let arrowheadWidth = 80; let arrowheadHeight = 60; let startOffset = 30; if(idx !== 0) { - arrowStyle = this.getArrowStyle('secondary', secondaryArrowColorHex); + arrowStyle = this.getArrowStyle('secondary', secondaryArrowColorHex, arrowOpacity); const arrowScale = totalRanks === 2 ? 0.75 @@ -252,7 +253,7 @@ class BackendInstance { if(oppMovesExist && showOpponentMoveGuess) { oppArrowElem = this.BoardDrawer.createShape('arrow', [oppFrom, oppTo], { - style: this.getArrowStyle('opponent', opponentArrowColorHex), + style: this.getArrowStyle('opponent', opponentArrowColorHex, arrowOpacity), lineWidth, arrowheadWidth, arrowheadHeight, startOffset } ); diff --git a/assets/js/acas-globals.js b/assets/js/acas-globals.js index f210a80..d79c7ca 100644 --- a/assets/js/acas-globals.js +++ b/assets/js/acas-globals.js @@ -250,17 +250,6 @@ function getGmConfigValue(key, instanceID, profileID) { const config = USERSCRIPT.GM_getValue(USERSCRIPT.dbValues.AcasConfig); - const instanceValue = config?.instance?.[instanceID]?.[key]; - const globalValue = config?.global?.[key]; - - if(instanceValue !== undefined) { - return instanceValue; - } - - if(globalValue !== undefined) { - return globalValue; - } - if(profileID) { const globalProfileValue = config?.global?.['profiles']?.[profileID]?.[key]; const instanceProfileValue = config?.instance?.[instanceID]?.['profiles']?.[profileID]?.[key]; @@ -274,6 +263,17 @@ function getGmConfigValue(key, instanceID, profileID) { } } + const instanceValue = config?.instance?.[instanceID]?.[key]; + const globalValue = config?.global?.[key]; + + if(instanceValue !== undefined) { + return instanceValue; + } + + if(globalValue !== undefined) { + return globalValue; + } + return null; } diff --git a/index.html b/index.html index a01a78e..b14e19a 100644 --- a/index.html +++ b/index.html @@ -246,15 +246,13 @@
Visual 👁️‍🗨️
-
-
Moves on external site
-
Show move arrows on chess site's board (e.g. chess.com's board)
-
-
-
Arrow opacity (1 - 100%)
-
Change the opacity of arrows on the external site, refresh external site to see changes
- -
+
Moves on external site
+
Show move arrows on chess site's board (e.g. chess.com's board)
+
+
+
Arrow opacity (1 - 100%)
+
Change the opacity of the arrows
+
Primary Arrow Color
The best move color