Skip to content

Commit

Permalink
v3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MaterialFoundry committed Aug 16, 2024
1 parent fc9942b commit f2a526a
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 30 deletions.
20 changes: 12 additions & 8 deletions MaterialPlane.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<p>The touch functionality of Material Plane is incompatible with Foundry V11.<br>You should downgrade to Foundry V10 if you want to use the touch functionality. If you ignore this message, expect weird behavior.</p>",
content: "<p>The touch functionality of Material Plane is incompatible with Foundry V11.<br>You should upgrade to Foundry v12 if you want to use the touch functionality. If you ignore this message, expect weird behavior.</p>",
buttons: {
one: {
icon: '<i class="fas fa-check"></i>',
Expand All @@ -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;
Expand All @@ -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){
Expand Down
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog Material Plane Foundry Module

### v3.2.0 - 16-08-2024

Additions:
<ul>
<li>(Touch) Added the ability to ping on a double tap</li>
</ul>

Fixes:
<ul>
<li>Touch now works for Foundry v12</li>
<li>Hide UI elements is now only applied to the active user</li>
</ul>

### v3.1.1 - 12-06-2024

<b>The module is now compatible with Foundry v12, removed compatibility with v10.</b>
Expand Down
10 changes: 5 additions & 5 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/IRtoken/IRtoken.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/Misc/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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 => {
Expand Down
10 changes: 10 additions & 0 deletions src/Misc/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
12 changes: 12 additions & 0 deletions src/analyzeTouch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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')
Expand Down
44 changes: 28 additions & 16 deletions templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@

<div class="mpConfigTab">
<button type="button" class="mpConfigTabLinks active" onclick="openTab(event, 'mpConfigGeneral')">{{localize "MaterialPlane.Config.General"}}</button>
<button type="button" class="mpConfigTabLinks" onclick="openTab(event, 'mpConfigControl')" {{#ifNCond device 'sensor'}}style="display:none"{{/ifNCond}}>{{localize "MaterialPlane.Config.Control"}}</button>
<button type="button" class="mpConfigTabLinks" onclick="openTab(event, 'mpConfigControl')">{{localize "MaterialPlane.Config.Control"}}</button>
<button type="button" class="mpConfigTabLinks" onclick="openTab(event, 'mpConfigConnection')" {{#ifNCond device 'sensor'}}style="display:none"{{/ifNCond}}>{{localize "MaterialPlane.Config.Connection"}}</button>
<button type="button" class="mpConfigTabLinks" onclick="openTab(event, 'mpConfigSensor')" {{#ifNCond device 'sensor'}}style="display:none"{{/ifNCond}}>{{localize "MaterialPlane.Config.Sensor"}}</button>
<button type="button" class="mpConfigTabLinks mpProd" onclick="openTab(event, 'mpConfigBase')" {{#ifNCond device 'sensor'}}style="display:none"{{/ifNCond}}>{{localize "MaterialPlane.Config.BaseSetup"}}</button>
Expand Down Expand Up @@ -376,7 +376,7 @@
</div>

<!-- Low Battery Notifications -->
<div class="mpConfigFormElements mpProd">
<div class="mpConfigFormElements mpProd" {{#ifNCond device 'sensor'}}style="display:none"{{/ifNCond}}>
<label class="mpTooltip">{{localize "MaterialPlane.Config.BatteryNotifications_Label"}}
<span class="mpTooltiptext">{{localize "MaterialPlane.Config.BatteryNotifications_Hint"}}</span>
</label>
Expand Down Expand Up @@ -428,7 +428,7 @@
</div>

<!-- Base Orientation -->
<div class="mpConfigFormElements">
<div class="mpConfigFormElements" {{#ifNCond device 'sensor'}}style="display:none"{{/ifNCond}}>
<label class="mpTooltip">{{localize "MaterialPlane.Config.BaseOrientation_Label"}}
<span class="mpTooltiptext">{{localize "MaterialPlane.Config.BaseOrientation_Hint"}}</span>
</label>
Expand Down Expand Up @@ -1006,7 +1006,9 @@ <h3><h3>{{localize "MaterialPlane.Config.MostRecentData"}}</h3></h3>

<!-- Tap Mode -->
<div class="mpConfigFormElements">
<label for="mpTapMode">{{localize "MaterialPlane.Config.TapMode"}}</label>
<label class="mpTooltip">{{localize "MaterialPlane.Config.TapMode"}}
<span class="mpTooltiptext">{{localize "MaterialPlane.Config.TapMode_Hint"}}</span>
</label>
<div class="mpConfigFormVal">
<select id="mpTapMode">
<option value="disable" {{#ifCond tapMode 'disable'}}selected{{/ifCond}}>{{localize "MaterialPlane.Config.TapMode_Disable"}}</option>
Expand All @@ -1015,50 +1017,60 @@ <h3><h3>{{localize "MaterialPlane.Config.MostRecentData"}}</h3></h3>
</select>
</div>
</div>
<p class="mpConfigNotes">{{localize "MaterialPlane.Config.TapMode_Hint"}}</p>
<p class="mpConfigNotes">{{localize "MaterialPlane.Config.TapMode_Timeout_Hint"}}</p>
<p class="mpConfigNotes">{{localize "MaterialPlane.Config.TapMode_RaiseMini_Hint"}}</p>


<!-- Touch Timeout -->
<div class="mpConfigFormElements">
<label for="mpTouchTimeout">{{localize "MaterialPlane.Config.TouchTimeout"}}</label>
<label class="mpTooltip">{{localize "MaterialPlane.Config.TouchTimeout"}}
<span class="mpTooltiptext">{{localize "MaterialPlane.Config.TouchTimeout_Hint"}}</span>
</label>
<div class="mpConfigFormValRange">
<input type="range" id="mpTouchTimeout" min=500 max=5000 step=100 value={{touchTimeout}}>
<input type="number" id="mpTouchTimeoutNumber" value={{touchTimeout}}>
</div>
</div>
<p class="mpConfigNotes">{{localize "MaterialPlane.Config.TouchTimeout_Hint"}}</p>

<!-- Tap Timeout -->
<div class="mpConfigFormElements">
<label for="mpTapTimeout">{{localize "MaterialPlane.Config.TapTimeout"}}</label>
<label class="mpTooltip">{{localize "MaterialPlane.Config.TapTimeout"}}
<span class="mpTooltiptext">{{localize "MaterialPlane.Config.TapTimeout_Hint"}}</span>
</label>
<div class="mpConfigFormValRange">
<input type="range" id="mpTapTimeout" min=100 max=5000 step=100 value={{tapTimeout}}>
<input type="number" id="mpTapTimeoutNumber" value={{tapTimeout}}>
</div>
</div>
<p class="mpConfigNotes">{{localize "MaterialPlane.Config.TapTimeout_Hint"}}</p>

<!-- Tap Ping -->
<div class="mpConfigFormElements">
<label class="mpTooltip">{{localize "MaterialPlane.Config.TapPing"}}
<span class="mpTooltiptext">{{localize "MaterialPlane.Config.TapPing_Hint"}}</span>
</label>
<div class="mpConfigFormVal">
<input type="checkbox" id="mpTapPing" {{#if tapPing}}checked{{/if}}>
</div>
</div>

<!-- X Scale -->
<div class="mpConfigFormElements">
<label for="mpTouchScaleX">{{localize "MaterialPlane.Config.ScaleX"}}</label>
<label class="mpTooltip">{{localize "MaterialPlane.Config.ScaleX"}}
<span class="mpTooltiptext">{{localize "MaterialPlane.Config.ScaleX_Hint"}}</span>
</label>
<div class="mpConfigFormValRange">
<input type="range" id="mpTouchScaleX" min=0 max=2 step=0.01 value={{touchScaleX}}>
<input type="number" id="mpTouchScaleXNumber" value={{touchScaleX}}>
</div>
</div>
<p class="mpConfigNotes">{{localize "MaterialPlane.Config.ScaleX_Hint"}}</p>

<!-- Y Scale -->
<div class="mpConfigFormElements">
<label for="mpTouchScaleY">{{localize "MaterialPlane.Config.ScaleY"}}</label>
<label class="mpTooltip">{{localize "MaterialPlane.Config.ScaleY"}}
<span class="mpTooltiptext">{{localize "MaterialPlane.Config.ScaleY_Hint"}}</span>
</label>
<div class="mpConfigFormValRange">
<input type="range" id="mpTouchScaleY" min=0 max=2 step=0.01 value={{touchScaleY}}>
<input type="number" id="mpTouchScaleYNumber" value={{touchScaleY}}>
</div>
</div>
<p class="mpConfigNotes">{{localize "MaterialPlane.Config.ScaleY_Hint"}}</p>
</div>

<!-----------------------------------------------Downloads--------------------------------------------------------------------->
Expand Down

0 comments on commit f2a526a

Please sign in to comment.