From 0bc7d0378baadc9be7e52ee14d9022f1576133f8 Mon Sep 17 00:00:00 2001 From: Saibot393 <137942782+Saibot393@users.noreply.github.com> Date: Fri, 31 May 2024 18:55:26 +0200 Subject: [PATCH] v3.0.2 --- module.json | 4 ++-- scripts/RidingScript.js | 16 ++++++++++++---- scripts/utils/GeometricUtils.js | 29 +++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/module.json b/module.json index 6e14e57..47f36ca 100644 --- a/module.json +++ b/module.json @@ -7,7 +7,7 @@ "name": "saibot" } ], - "version": "3.0.1", + "version": "3.0.2", "compatibility": { "minimum": "10", "verified": "12" @@ -64,7 +64,7 @@ ] }, "url": "https://github.com/Saibot393/Rideable", - "download": "https://github.com/Saibot393/Rideable/archive/refs/tags/v3.0.1.zip", + "download": "https://github.com/Saibot393/Rideable/archive/refs/tags/v3.0.2.zip", "manifest": "https://github.com/Saibot393/Rideable/releases/latest/download/module.json", "readme": "https://github.com/Saibot393/Rideable/blob/main/README.md", "changelog": "https://github.com/Saibot393/Rideable/blob/main/CHANGELOG.md", diff --git a/scripts/RidingScript.js b/scripts/RidingScript.js index 7f97969..dbc7972 100644 --- a/scripts/RidingScript.js +++ b/scripts/RidingScript.js @@ -861,11 +861,19 @@ class Ridingmanager { if (RideableUtils.canbeMoved(pRidden)) { if (vPilot && RideableFlags.isPilotedby(pRidden, vPilot)) { - let vCurrentCenter = GeometricUtils.CenterPositionXY(pRidden); - let vTargetCenter = {x : vCurrentCenter.x + (pRelativChanges.x || 0), y : vCurrentCenter.y + (pRelativChanges.y || 0)} - let vCollision = CONFIG.Canvas.polygonBackends.move.testCollision(vCurrentCenter, vTargetCenter, {type : "move"}); + //let vCurrentCenter = GeometricUtils.CenterPositionXY(pRidden); + //let vTargetCenter = {x : vCurrentCenter.x + (pRelativChanges.x || 0), y : vCurrentCenter.y + (pRelativChanges.y || 0)} + //let vCollision = CONFIG.Canvas.polygonBackends.move.testCollision(vCurrentCenter, vTargetCenter, {type : "move"}); + let vCurrentPoints = GeometricUtils.fourspread(GeometricUtils.changedGeometry(pRidden)); + let vTargetPoints = GeometricUtils.fourspread(GeometricUtils.changedGeometry(pRidden, pRelativChanges)); + let vCollisions = []; - if (!vCollision.length) { + for (let i = 0; i < 4; i++) { + vCollisions.push(...CONFIG.Canvas.polygonBackends.move.testCollision(vCurrentPoints[i], vTargetPoints[i], {type : "move"})); + } + console.log(vCollisions) + + if (!vCollisions.length) { let vTarget = {}; for (let i = 0; i < cMotionProperties.length; i++) { diff --git a/scripts/utils/GeometricUtils.js b/scripts/utils/GeometricUtils.js index 9c9a633..799c5f6 100644 --- a/scripts/utils/GeometricUtils.js +++ b/scripts/utils/GeometricUtils.js @@ -33,7 +33,9 @@ class GeometricUtils { static CenterPositionXY(pToken) {} //returns the center position (x,y) of pToken - static updatedGeometry(pToken, pChange) {} //returns the center position (x,y) of pToken after pChange + static updatedGeometry(pToken, pChange = {}) {} //returns the center position (x,y) of pToken after pChange + + static changedGeometry(pToken, pChange = {}) {} //returns the center position (x,y) of pToken with pChange static CentertoXY(pPoint, pToken) {} //maps a center point to a tl-corner point @@ -79,6 +81,8 @@ class GeometricUtils { static insceneSize(pToken) {} // returns the scene size of pTokens scene + static fourspread(pPoint) {} // returns 4 equally spread points around pPoint + //sort static sortbymaxdim(pTokens) {} //sorts pTokens array by their largest dimensions, returns sorted array and array with their values @@ -126,7 +130,7 @@ class GeometricUtils { } } - static updatedGeometry(pToken, pChange) { + static updatedGeometry(pToken, pChange = {}) { let vData = {}; for (let vKey of ["x", "y", "width", "height", "rotation"]) { @@ -138,6 +142,18 @@ class GeometricUtils { return {...vData, x : vData.x + vScale * vData.width / 2, y : vData.y + vScale * vData.height / 2, insceneWidth : vScale * vData.width, insceneHeight : vScale * vData.height, 0 : vData.x + vScale * vData.width / 2, 1 : vData.y + vScale * vData.height / 2}; } + static changedGeometry(pToken, pChange = {}) { + let vData = {}; + + for (let vKey of ["x", "y", "width", "height", "rotation"]) { + vData[vKey] = pToken[vKey] + (pChange[vKey] || 0); + } + + let vScale = pToken.documentName == "Token" ? FCore.sceneof(pToken).dimensions.size : 1; + + return {...vData, x : vData.x + vScale * vData.width / 2, y : vData.y + vScale * vData.height / 2, insceneWidth : vScale * vData.width, insceneHeight : vScale * vData.height, 0 : vData.x + vScale * vData.width / 2, 1 : vData.y + vScale * vData.height / 2}; + } + static CentertoXY(pPoint, pToken) { if (pToken) { return {x: pPoint.x - GeometricUtils.insceneWidth(pToken)/2, y: pPoint.y - GeometricUtils.insceneHeight(pToken)/2}; @@ -311,6 +327,15 @@ class GeometricUtils { return FCore.sceneof(pToken).dimensions.size; } + static fourspread(pPoint) { + return [ + {x : pPoint.x + pPoint.insceneWidth/4, y : pPoint.y + pPoint.insceneHeight/4}, + {x : pPoint.x + pPoint.insceneWidth/4, y : pPoint.y - pPoint.insceneHeight/4}, + {x : pPoint.x - pPoint.insceneWidth/4, y : pPoint.y + pPoint.insceneHeight/4}, + {x : pPoint.x - pPoint.insceneWidth/4, y : pPoint.y - pPoint.insceneHeight/4} + ] + } + //sort static sortbymaxdim(pTokens) { let vsortedTokens = pTokens.sort(function(vTokena,vTokenb){return Math.max(vTokena.height, vTokena.width)-Math.max(vTokenb.height, vTokenb.width)});