From f2a526a73c9ee7566c86c9a4f50acc3ba7941d1b Mon Sep 17 00:00:00 2001 From: Material Foundry Date: Fri, 16 Aug 2024 19:43:29 +0200 Subject: [PATCH] v3.2.0 --- MaterialPlane.js | 20 +++++++++++-------- changelog.md | 13 +++++++++++++ lang/en.json | 10 +++++----- module.json | 2 +- src/IRtoken/IRtoken.js | 1 + src/Misc/config.js | 4 ++++ src/Misc/settings.js | 10 ++++++++++ src/analyzeTouch.js | 12 ++++++++++++ templates/config.html | 44 +++++++++++++++++++++++++++--------------- 9 files changed, 86 insertions(+), 30 deletions(-) diff --git a/MaterialPlane.js b/MaterialPlane.js index 8ab5a5f..076c7f0 100644 --- a/MaterialPlane.js +++ b/MaterialPlane.js @@ -151,10 +151,10 @@ Hooks.on('ready', async ()=>{ // configDialog.setConfigOpen(true); // configDialog.render(true); - if (game.version.split('.')[0] >= 11 && game.settings.get(moduleName,'device') == 'touch') { + if (game.version.split('.')[0] < 12 && game.settings.get(moduleName,'device') == 'touch') { let d = new Dialog({ title: "Material Plane: Incompatibility", - content: "

The touch functionality of Material Plane is incompatible with Foundry V11.
You should downgrade to Foundry V10 if you want to use the touch functionality. If you ignore this message, expect weird behavior.

", + content: "

The touch functionality of Material Plane is incompatible with Foundry V11.
You should upgrade to Foundry v12 if you want to use the touch functionality. If you ignore this message, expect weird behavior.

", buttons: { one: { icon: '', @@ -171,7 +171,7 @@ Hooks.on('ready', async ()=>{ } enableModule = game.user.id == game.settings.get(moduleName,'ActiveUser'); - hideElements = game.settings.get(moduleName,'HideElements') && game.user.isGM == false; + hideElements = game.settings.get(moduleName,'HideElements') && game.user.isGM == false && enableModule; if (game.settings.get(moduleName,'device') == 'sensor' && game.settings.get(moduleName,'ConnectionMode') != "noConnect" && window.location.protocol == "https:" && game.settings.get(moduleName,'ConnectionMode') != 'materialCompanion'){ ui.notifications.warn("Material Plane: "+game.i18n.localize("MaterialPlane.Notifications.SSL")); enableModule = false; @@ -181,11 +181,15 @@ Hooks.on('ready', async ()=>{ if (game.settings.get(moduleName,'device') == 'sensor') { startWebsocket(); } - else { - document.addEventListener('touchstart',function(e) {e.preventDefault(); analyzeTouch('start',e);}); - document.addEventListener('touchmove',function(e) {e.preventDefault(); analyzeTouch('move',e);}); - document.addEventListener('touchend',function(e) {e.preventDefault(); analyzeTouch('end',e);}); - document.addEventListener('touchcancel',function(e) {e.preventDefault(); analyzeTouch('end',e);}); + else if (enableModule) { + document.addEventListener('touchstart',function(e) {analyzeTouch('start',e);}); + document.addEventListener('touchmove',function(e) {analyzeTouch('move',e);}); + document.addEventListener('touchend',function(e) {analyzeTouch('end',e);}); + document.addEventListener('touchcancel',function(e) {analyzeTouch('end',e);}); + + //disable ping on long press + canvas.pingOld = canvas.ping; + canvas.ping = function(origin) {}; } if (hideElements){ diff --git a/changelog.md b/changelog.md index 44cdc2e..ced99ed 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,18 @@ # Changelog Material Plane Foundry Module +### v3.2.0 - 16-08-2024 + +Additions: + + +Fixes: + + ### v3.1.1 - 12-06-2024 The module is now compatible with Foundry v12, removed compatibility with v10. diff --git a/lang/en.json b/lang/en.json index 6c093bd..517441f 100644 --- a/lang/en.json +++ b/lang/en.json @@ -60,17 +60,17 @@ "MaterialPlane.Config.MaxAttempts": "Maximum Connection Attempts", "MaterialPlane.Config.MaxAttempts_Hint": "The maximum amount of times Material Plane will attempt to connect to the sensor or Material Companion.", - "MaterialPlane.Config.TapMode": "Tap Mode", - "MaterialPlane.Config.TapMode_Hint": "Sets the tap mode. This can be used to distinguish between touches caused by minis and taps that are meant to interact with the canvas (such as opening doors).", - "MaterialPlane.Config.TapMode_Timeout_Hint": "'Tap Timeout': When a new touch is detected, a timer will start. If the touch is removed before the timer is bigger than 'Tap Timeout', MP will assume it was a tap. Otherwise it'll assume a mini was placed. Token movement will start after 'Tap Timeout' has elapsed.", - "MaterialPlane.Config.TapMode_RaiseMini_Hint": "'Raise Mini': When a new touch is detected, MP will check if a touch has recently (within the last 'Tap Timeout' ms) ended near the new touch. It that's the case, MP will assume a mini is being moved, otherwise it'll assume a tap.", - "MaterialPlane.Config.TapMode_Disable": "Disable", + "MaterialPlane.Config.TapMode": "Touch Mode", + "MaterialPlane.Config.TapMode_Hint": "Sets the touch mode. This can be used to distinguish between touches caused by minis and taps that are meant to interact with the canvas (such as opening doors). 'Tap Timeout': When a new touch is detected, a timer will start. If the touch is removed before the timer is bigger than 'Tap Timeout', MP will assume it was a tap. Otherwise it'll assume a mini was placed. Token movement will start after 'Tap Timeout' has elapsed. 'Raise Mini': When a new touch is detected, MP will check if a touch has recently (within the last 'Tap Timeout' ms) ended near the new touch. It that's the case, MP will assume a mini is being moved, otherwise it'll assume a tap.", + "MaterialPlane.Config.TapMode_Disable": "Direct", "MaterialPlane.Config.TapMode_TapTimeout": "Tap Timeout", "MaterialPlane.Config.TapMode_RaiseMini": "Raise Mini", "MaterialPlane.Config.TouchTimeout": "Token Drop Timeout (ms)", "MaterialPlane.Config.TouchTimeout_Hint": "Time in milliseconds after which a token is dropped if no new touch is detected.", "MaterialPlane.Config.TapTimeout": "Tap Timeout (ms)", "MaterialPlane.Config.TapTimeout_Hint": "Sets the timeout (in ms) to detect a tap. The exact function depends on 'Tap Mode'. For 'Tap Timeout', the value should be relatively small (probably 500ms or smaller), while for 'Raise Mini' it should be bigger (probably 1000 to 2000ms).", + "MaterialPlane.Config.TapPing": "Ping on Double Tap", + "MaterialPlane.Config.TapPing_Hint": "Enables pinging by double tapping (within 500ms).", "MaterialPlane.Config.MostRecentData": "Most Recent Data", "MaterialPlane.Config.MostRecentData_Hint": "Displays the most recent detected data. Can be updated by activating a base or selecting a token.", diff --git a/module.json b/module.json index fa4fa57..1c70e3e 100644 --- a/module.json +++ b/module.json @@ -1,7 +1,7 @@ { "title": "Material Plane", "description": "Module for tracking physical minis. By using an IR tracking camera and mini bases with IR LED's this module can be used to move tokens in Foundry by moving physical tokens on top of a horizontally mounted TV", - "version": "3.1.1", + "version": "3.2.0", "authors": [ { "name": "CDeenen", diff --git a/src/IRtoken/IRtoken.js b/src/IRtoken/IRtoken.js index a48db19..8df09d4 100644 --- a/src/IRtoken/IRtoken.js +++ b/src/IRtoken/IRtoken.js @@ -307,6 +307,7 @@ export class IRtoken { this.token.document.x = newCoords.x; this.token.document.y = newCoords.y; this.token.refresh(); + compatibilityHandler('initializeSources', this.token); //Release token, if setting is enabled if (release) this.token.release(); diff --git a/src/Misc/config.js b/src/Misc/config.js index f542869..bf57f24 100644 --- a/src/Misc/config.js +++ b/src/Misc/config.js @@ -80,6 +80,7 @@ export class mpConfig extends FormApplication { tapTimeout: game.settings.get(moduleName,'tapTimeout'), touchScaleX: game.settings.get(moduleName,'touchScaleX'), touchScaleY: game.settings.get(moduleName,'touchScaleY'), + tapPing: game.settings.get(moduleName, 'tapPing'), baseSetup: this.baseSettings, @@ -256,6 +257,9 @@ export class mpConfig extends FormApplication { html.find("input[id=mpTouchScaleY]")[0].value = event.target.value; this.setSettings('touchScaleY', event.target.value); }); + html.find("input[id=mpTapPing]").on('change', event => { + this.setSettings('tapPing',event.target.checked); + }); // --- Base Setup settings, more in buildBaseTable() --- html.find("button[name='addBaseConfig']").on('click', async event => { diff --git a/src/Misc/settings.js b/src/Misc/settings.js index 7bacc7a..a5bc046 100644 --- a/src/Misc/settings.js +++ b/src/Misc/settings.js @@ -58,6 +58,16 @@ export const registerSettings = function() { config: false, }); + /** + * Ping on double tap + */ + game.settings.register(moduleName,'tapPing', { + scope: "world", + config: false, + default: true, + type: Boolean + }); + /** * Touch Scale X */ diff --git a/src/analyzeTouch.js b/src/analyzeTouch.js index 2307174..6fbe342 100644 --- a/src/analyzeTouch.js +++ b/src/analyzeTouch.js @@ -7,11 +7,13 @@ let tokenActive = []; let tapTimeout = []; let raiseData = []; let touches = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]; +let touchesTimer = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]; let pauseTimeoutCheck = false; export async function analyzeTouch(type,data) { //console.log('data',type,data) //debug('touchDetect',{type,data}); + if (game.paused) { if (!pauseTimeoutCheck) { @@ -40,6 +42,16 @@ export async function analyzeTouch(type,data) { debug('touchDetect', `${type}, id: ${id}, Coordinates: (${coordinates.x}, ${coordinates.y}), Scaled: (${scaledCoordinates.x}, ${scaledCoordinates.y})`); const forceNew = type == 'start'; const tapMode = game.settings.get('MaterialPlane','tapMode'); + + if (type == 'start') { + const timeSinceLastTouch = Date.now() - touchesTimer[id]; + touchesTimer[id] = Date.now(); + + if (game.settings.get(moduleName, 'tapPing') && timeSinceLastTouch < 500) { + canvas.pingOld(scaledCoordinates); + return; + } + } if (tapMode == 'disable') { //Tap disabled if (type == 'end') diff --git a/templates/config.html b/templates/config.html index 54ebce3..2dcbc7f 100644 --- a/templates/config.html +++ b/templates/config.html @@ -331,7 +331,7 @@
- + @@ -376,7 +376,7 @@
-
+
@@ -428,7 +428,7 @@
-
+
@@ -1006,7 +1006,9 @@

{{localize "MaterialPlane.Config.MostRecentData"}}

- +
-

{{localize "MaterialPlane.Config.TapMode_Hint"}}

-

{{localize "MaterialPlane.Config.TapMode_Timeout_Hint"}}

-

{{localize "MaterialPlane.Config.TapMode_RaiseMini_Hint"}}

-
- +
-

{{localize "MaterialPlane.Config.TouchTimeout_Hint"}}

- +
-

{{localize "MaterialPlane.Config.TapTimeout_Hint"}}

+ + +
+ +
+ +
+
- +
-

{{localize "MaterialPlane.Config.ScaleX_Hint"}}

- +
-

{{localize "MaterialPlane.Config.ScaleY_Hint"}}