Skip to content

Commit

Permalink
v3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Saibot393 committed May 31, 2024
1 parent e719513 commit 0bc7d03
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "saibot"
}
],
"version": "3.0.1",
"version": "3.0.2",
"compatibility": {
"minimum": "10",
"verified": "12"
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 12 additions & 4 deletions scripts/RidingScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
29 changes: 27 additions & 2 deletions scripts/utils/GeometricUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"]) {
Expand All @@ -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};
Expand Down Expand Up @@ -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)});
Expand Down

0 comments on commit 0bc7d03

Please sign in to comment.