Skip to content

Commit

Permalink
v3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MaterialFoundry committed Jun 11, 2024
1 parent bfd3de1 commit fc9942b
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 126 deletions.
11 changes: 6 additions & 5 deletions MaterialPlane.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { registerSettings, onHwVariantChange } from "./src/Misc/settings.js";
import { mpConfig } from "./src/Misc/config.js";
import { sendWS, startWebsocket } from "./src/Communication/websocket.js";
import { calibrationProgressScreen, removeOverlay, calOverlay } from "./src/calibration.js";
import { registerLayer, configureDebug, compatibleCore } from "./src/Misc/misc.js";
import { registerLayer, configureDebug } from "./src/Misc/misc.js";
import { initializeIRtokens, initializeCursors, setLastBaseAddress, pen } from "./src/analyzeIR.js";
import { IRremote } from "./src/IRremote/IRremote.js";
import { analyzeTouch } from "./src/analyzeTouch.js";
import { compatibilityInit } from "./src/Misc/compatibilityHandler.js";

export const moduleName = "MaterialPlane";
export let lastToken;
Expand Down Expand Up @@ -329,6 +330,7 @@ Hooks.on('closecalibrationProgressScreen',() => {
* Initialize settings
*/
Hooks.once('init', function(){
compatibilityInit();
registerSettings();
registerLayer();
configDialog = new mpConfig();
Expand Down Expand Up @@ -398,10 +400,7 @@ Hooks.on('renderPlayerList', (a,b, playerlist) => {
const pl = playerlist.users.find(p => p._id == game.settings.get(moduleName,'ActiveUser'));
if (pl == undefined) return;
const html = `<span style="font-size:0.6rem; border:2px solid; border-radius:25%; padding: 0px 3px 0px 3px">MP</span>`;
if (compatibleCore('11.0'))
document.querySelectorAll(`[data-tooltip="${pl.displayName}"]`)[0].innerHTML+=html;
//else
// document.querySelectorAll(`[data-user-id="${pl._id}"]`)[0].innerHTML+=html;
document.querySelectorAll(`[data-tooltip="${pl.displayName}"]`)[0].innerHTML+=html;
});

//let scaleOld;
Expand Down Expand Up @@ -454,4 +453,6 @@ export async function checkForUpdate(reqType) {
latestReleases.materialCompanion = version;
}
});


}
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Changelog Material Plane Foundry Module

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

<b>The module is now compatible with Foundry v12, removed compatibility with v10.</b>

Fixes:
<ul>
<li>Fixed issue where linked tokens would sometimes not move</li>
</ul>

### v3.1.0 - 16-04-2024
Fixes:
<ul>
Expand Down
Binary file removed img/.thumb/MaterialFoundry2560x1440.jpg.jpg
Binary file not shown.
Binary file removed img/.thumb/macro.png.jpg
Binary file not shown.
6 changes: 6 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@
"MaterialPlane.Config.BaseId_Hint": "ID of the base.",
"MaterialPlane.Config.TokenName": "Token Name",
"MaterialPlane.Config.TokenName_Hint": "Name of the token to link to (only required if 'Link Actor' is not checked).",
"MaterialPlane.Config.TokenId": "Token ID",
"MaterialPlane.Config.TokenId_Hint": "ID of the token to link to (only required if 'Link Actor' is not checked).",
"MaterialPlane.Config.TokenNameId": "Token Name/ID",
"MaterialPlane.Config.TokenScene": "Token Scene",
"MaterialPlane.Config.TokenScene_Hint": "Name of the scene of the token (only required if 'Link Actor' is not checked).",
"MaterialPlane.Config.ActorName": "Actor Name",
"MaterialPlane.Config.ActorName_Hint": "Name of the actor to link to (only required if 'Link Actor' is checked.",
"MaterialPlane.Config.ActorId": "Actor ID",
"MaterialPlane.Config.ActorId_Hint": "ID of the actor to link to (only required if 'Link Actor' is checked.",
"MaterialPlane.Config.ActorNameId": "Actor Name/ID",
"MaterialPlane.Config.LinkActor": "Link",
"MaterialPlane.Config.LinkActorBtn": "Link button",
"MaterialPlane.Config.LinkActor_Hint": "Link the base to a specific actor, regardless of scene or token.",
Expand Down
95 changes: 55 additions & 40 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,61 @@
{
"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.0",
"esmodules": [
"MaterialPlane.js"
],
"socket": true,
"flags": {
"minimumSensorVersion": "3.0.0",
"minimumSensorWsVersion": "2.0.0",
"minimumBaseVersion": "2.0.0",
"minimumPenVersion": "2.0.0",
"minimumMSversion": "1.0.2"
},
"languages": [
{
"lang": "en",
"name": "English",
"path": "lang/en.json",
"flags": {}
}
],
"media": [
"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",
"authors": [
{
"type": "icon",
"url": "modules/MaterialPlane/img/MaterialFoundry512x512.png"
},
{
"type": "setup",
"url": "modules/MaterialPlane/img/MaterialFoundry2560x1440.jpg"
},
{
"type": "cover",
"url": "modules/MaterialPlane/img/MaterialFoundry2560x1440.jpg"
"name": "CDeenen",
"email": "[email protected]",
"discord": "Cris#6864",
"patreon": "MaterialFoundry",
"reddit": "CDeenen123"
}
],
"url": "https://github.com/MaterialFoundry/MaterialPlane_Foundry",
"manifest": "https://github.com/MaterialFoundry/MaterialPlane_Foundry/releases/latest/download/module.json",
"download": "https://github.com/MaterialFoundry/MaterialPlane_Foundry/releases/download/v3.0.0/module.zip",
"id": "MaterialPlane",
"compatibility": {
"minimum": "10",
"verified": "11"
"esmodules": [
"MaterialPlane.js"
],
"socket": true,
"flags": {
"minimumSensorVersion": "3.0.0",
"minimumSensorWsVersion": "2.0.0",
"minimumBaseVersion": "2.0.0",
"minimumPenVersion": "2.0.0",
"minimumMSversion": "1.0.2"
},
"languages": [
{
"lang": "en",
"name": "English",
"path": "lang/en.json",
"flags": {}
}
],
"media": [
{
"type": "icon",
"url": "modules/MaterialPlane/img/MaterialFoundry512x512.png",
"loop": false,
"flags": {}
},
{
"type": "setup",
"url": "modules/MaterialPlane/img/MaterialFoundry2560x1440.jpg",
"loop": false,
"flags": {}
},
{
"type": "cover",
"url": "modules/MaterialPlane/img/MaterialFoundry2560x1440.jpg",
"loop": false,
"flags": {}
}
],
"url": "https://github.com/MaterialFoundry/MaterialPlane_Foundry",
"manifest": "https://github.com/MaterialFoundry/MaterialPlane_Foundry/releases/latest/download/module.json",
"download": "https://github.com/MaterialFoundry/MaterialPlane_Foundry/releases/download/v3.1.1/module.zip",
"id": "MaterialPlane",
"compatibility": {
"minimum": "11",
"verified": "12"
}
}
13 changes: 9 additions & 4 deletions src/IRtoken/IRtoken.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DragRuler } from "./tokenRuler.js";
import { findToken, getGridCenter, getIRDeadZone, getIROffset, getTokenGridEnterPosition, getTokenCollision, comparePositions, addToCoordinates, checkSurroundingGridCollision, findNearestEmptySpace } from "./tokenHelpers.js";
import { TokenMarker } from "./tokenMarker.js";
import { TokenDebug } from "./tokenDebug.js";
import { compatibilityHandler } from "../Misc/compatibilityHandler.js";

let pausedMessage = false;

Expand Down Expand Up @@ -65,8 +66,9 @@ export class IRtoken {

//If the user can't control the token and non-owned token movement is disabled, prevent token movement
if (this.token.can(game.user,"control") == false && game.settings.get(moduleName,'EnNonOwned') == false) {

debug('updateMovement',`User can't control token ${this.token?.name}`)
this.token = undefined;
debug('updateMovement',`User can't control token ${this.token.name}`)
return false;
}

Expand Down Expand Up @@ -122,7 +124,7 @@ export class IRtoken {
this.debug.updateGridSpace(currentGridSpace);

//Check if a token has entered a new grid space, if so, store where it entered the space
let enterPos = getTokenGridEnterPosition(this.token, this.previousPosition, currentGridSpace, coords, this.debug);
let enterPos = await getTokenGridEnterPosition(this.token, this.previousPosition, currentGridSpace, coords, this.debug);

let movementMethod = game.settings.get(moduleName,'movementMethod');

Expand Down Expand Up @@ -221,7 +223,7 @@ export class IRtoken {
this.token.refresh();

//Update lighting in case of 'live' movement method
if (movementMethod == 'live') this.token.updateSource({noUpdateFog: false});
if (movementMethod == 'live') compatibilityHandler('initializeSources', this.token);

//Print debug message
debug('moveToken',`Token: ${this.token.name}, Move to: (${coords.x}, ${coords.y})`)
Expand Down Expand Up @@ -275,9 +277,12 @@ export class IRtoken {
if (this.token.can(game.user,"control")) {
//Update token position
await this.token.document.update(newCoords);

if (this.token == undefined) return false;

//Prevent token animation
CanvasAnimation.terminateAnimation(this.token.animationName);
if (this.token?.animationName)
CanvasAnimation.terminateAnimation(this.token.animationName);

//Print debug message
debug('dropToken',`Token ${this.token.name}, Dropping at (${newCoords.x}, ${newCoords.y})`)
Expand Down
38 changes: 21 additions & 17 deletions src/IRtoken/tokenHelpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { moduleName } from "../../MaterialPlane.js";
import { debug } from "../Misc/misc.js";
import { compatibilityHandler } from "../Misc/compatibilityHandler.js";

/**
* Compare positions of two tokens/objects. If they are equal, return true
Expand Down Expand Up @@ -78,7 +79,7 @@ export function findToken(coords, spacing, currentToken, mode){
if (token.h >= spacing && token.h > sp) sp = token.h;
}
else {
coordsCenter = token.getCenter(token.x,token.y);
coordsCenter = compatibilityHandler('tokenCenter', token, token.x, token.y);
const baseOrientation = game.settings.get(moduleName,'baseOrientation');
if (baseOrientation == '0') {
dx = Math.abs(coordsCenter.x - coords.x + (token.document.width-1)*spacing/2);
Expand Down Expand Up @@ -159,8 +160,10 @@ export function getGridCenter(coords, token) {
x: coords.x + 0.5*gridSize,
y: coords.y + 0.5*gridSize
}
const center = canvas.grid.getCenter(newCoords.x, newCoords.y);
return {x: center[0], y: center[1]};
//const center =
return compatibilityHandler('gridCenter', newCoords.x, newCoords.y);
//console.log('center',center)
//return {x: center[0], y: center[1]};
}

/**
Expand Down Expand Up @@ -197,6 +200,9 @@ export function getTokenGridEnterPosition(token, previousPosition, currentGridSp
if (token.MPlastPosition == undefined)
token.MPlastPosition = currentGridSpace;

if (token.MPgridEnterPosition == undefined)
token.MPgridEnterPosition = currentGridSpace;

debug.updateTokenLastPosition({
x: token.MPlastPosition.x,
y: token.MPlastPosition.y
Expand Down Expand Up @@ -251,7 +257,7 @@ export function getTokenCollision(token, origin, destination, useTestPosition=fa

if (useTestPosition) {
let dest = Object.assign({}, destination);

//Define a position to test for wall collisions. Start at the center of the token
let collisionTestPosition = {
x: origin.x + gridSize/2,
Expand Down Expand Up @@ -350,12 +356,12 @@ export function checkSurroundingGridCollision(token, coords, origin, debug) {
export function findNearestEmptySpace(token, coords, originPosition) {
const spacer = canvas.scene.gridType === CONST.GRID_TYPES.SQUARE ? 1.41 : 1;
//If space is already occupied
if (findToken(token.getCenter(coords.x,coords.y),(spacer * Math.min(canvas.grid.w, canvas.grid.h))/2,token) != undefined) {
if (findToken(compatibilityHandler('tokenCenter', token, coords.x, coords.y),(spacer * Math.min(compatibilityHandler('canvasWidth'), compatibilityHandler('canvasHeight')))/2,token) != undefined) {
ui.notifications.warn("Material Plane: "+game.i18n.localize("MaterialPlane.Notifications.SpaceOccupied"));
let ray = new Ray({x: originPosition.x, y: originPosition.y}, {x: coords.x, y: coords.y});

//Code below modified from _highlightMeasurement() in ruler class in core foundry
const nMax = Math.max(Math.floor(ray.distance / (spacer * Math.min(canvas.grid.w, canvas.grid.h))), 1);
const nMax = Math.max(Math.floor(ray.distance / (spacer * Math.min(compatibilityHandler('canvasWidth'), compatibilityHandler('canvasHeight')))), 1);
const tMax = Array.fromRange(nMax+1).map(t => t / nMax);

// Track prior position
Expand All @@ -367,34 +373,32 @@ export function findNearestEmptySpace(token, coords, originPosition) {

// Get grid position
let [r0, c0] = (i === 0) ? [null, null] : prior;
let [r1, c1] = canvas.grid.grid.getGridPositionFromPixels(x, y);
let [r1, c1] = compatibilityHandler('getGridOffset', x, y);
if ( r0 === r1 && c0 === c1 ) continue;
let [x1, y1] = canvas.grid.grid.getPixelsFromGridPosition(r1, c1);
let [x1, y1] = compatibilityHandler('getTopLeftPoint', r1, c1);
gridPositions.push({x: x1, y: y1})

// Skip the first one
prior = [r1, c1];
if ( i === 0 ) continue;

// If the positions are not neighbors, also highlight their halfway point
if ( !canvas.grid.isNeighbor(r0, c0, r1, c1) ) {
if (!compatibilityHandler('testAdjacency', {i:r0, j:c0}, {i:r1, j:c1})) {
let th = tMax[i - 1] + (0.5 / nMax);
let {x, y} = ray.project(th);
let [rh, ch] = canvas.grid.grid.getGridPositionFromPixels(x, y);
let [xh, yh] = canvas.grid.grid.getPixelsFromGridPosition(rh, ch);
let [rh, ch] = compatibilityHandler('getGridOffset', x, y);
let [xh, yh] = compatibilityHandler('getTopLeftPoint', rh, ch);
gridPositions.splice(gridPositions.length-1, 0, {x: xh, y: yh})
}
}
for (let i=gridPositions.length-1; i>=0; i--) {
const position = gridPositions[i];
const centeredPosition = token.getCenter(position.x,position.y);
if (getTokenCollision(token,token.getCenter(coords.x,coords.y),centeredPosition)) {
const centeredPosition = compatibilityHandler('tokenCenter', token, position.x, position.y);
if (getTokenCollision(token, compatibilityHandler('tokenCenter', token, coords.x, coords.y), centeredPosition)) {
continue;
}
if (findToken(centeredPosition,(spacer * Math.min(canvas.grid.w, canvas.grid.h))/2,token) == undefined) {
coords.x = position.x;
coords.y = position.y;
return coords;
if (findToken(centeredPosition,(spacer * Math.min(compatibilityHandler('canvasWidth'), compatibilityHandler('canvasHeight')))/2,token) == undefined) {
return position;
}
}
return originPosition;
Expand Down
Loading

0 comments on commit fc9942b

Please sign in to comment.