Skip to content

Commit

Permalink
version 2.2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
p4535992 committed Sep 29, 2022
1 parent 23d6ed1 commit 9ea844b
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 45 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# CHANGELOG
### 2.2.10

- Bug fix : [[BUG] PF2e LootSheet Characters still able to be interacted with from distance ](https://github.com/p4535992/foundryvtt-arms-reach/issues/65)

### 2.2.8-9

- Added french language
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "foundryvtt-arms-reach",
"title": "FoundryVTT Arms Reach",
"description": "Allows the GM to limit the distance that a player can interacted with a placeable object like door, journal, stairway, token, ecc..",
"version": "2.2.9",
"version": "2.2.10",
"main": "foundryvtt-arms-reach.js",
"scripts": {
"publish": "gulp publish --update",
Expand Down
4 changes: 2 additions & 2 deletions src/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
"foundryvtt-arms-reach.settingNameGlobalInteractionDistanceForGMOnTokens": "Aktiviert die Prüfung der Distanz für Token auch für den GM",
"foundryvtt-arms-reach.settingHintGlobalInteractionDistanceForGMOnTokens": "Wenn diese Option aktiviert ist, gilt die Prüfung des Abstands für Token auch für den GM, nützlich wenn der GM als Spieler agieren möchte.",

"foundryvtt-arms-reach.settingNameTokensIntegrationWithLootSheet": "Aktiviert die Entfernungsinteraktion für 'Loot Sheet'.",
"foundryvtt-arms-reach.settingHintTokensIntegrationWithLootSheet": "Wenn aktiviert, dann wird standardmässig die Entfernungsintegration für alle Token aktiviert, bei denen das Blatt 'LootSheet' aktiv ist",
"foundryvtt-arms-reach.settingNameTokensIntegrationWithLootSheet": "Aktiviert die Entfernungsinteraktion für 'Loot Sheet NPC 5E'.",
"foundryvtt-arms-reach.settingHintTokensIntegrationWithLootSheet": "Wenn aktiviert, dann wird standardmässig die Entfernungsintegration für alle Token aktiviert, bei denen das Blatt 'LootSheet' aktiv ist (https://foundryvtt.com/packages/lootsheetnpc5e)",

"foundryvtt-arms-reach.settingNameTokensIntegrationByPrefix": "Aktivieren der Abstandsinteraktion für Ziel-Token mit einem bestimmten Namenspräfix",
"foundryvtt-arms-reach.settingHintTokensIntegrationByPrefix": "Bei Aktivierung wird standardmässig die Abstandsintegration für alle Ziel-Token aktiviert, wobei das Präfix auf den Namen des Tokens (nicht den Zeichennamen) gesetzt wird.",
Expand Down
4 changes: 2 additions & 2 deletions src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
"foundryvtt-arms-reach.settingNameGlobalInteractionDistanceForGMOnTokens": "Enable the check distance on Tokens even for GM",
"foundryvtt-arms-reach.settingHintGlobalInteractionDistanceForGMOnTokens": "If enabled it will apply the check of the distance on Tokens even for GM, useful if the GM want to play as a player.",

"foundryvtt-arms-reach.settingNameTokensIntegrationWithLootSheet": "Enable the distance interaction for 'Loot Sheet'",
"foundryvtt-arms-reach.settingHintTokensIntegrationWithLootSheet": "If true by default enable the distance integration for all the token with the 'LootSheet' sheet active",
"foundryvtt-arms-reach.settingNameTokensIntegrationWithLootSheet": "Enable the distance interaction for 'Loot Sheet NPC 5E'",
"foundryvtt-arms-reach.settingHintTokensIntegrationWithLootSheet": "If true by default enable the distance integration for all the token with the 'LootSheet' sheet active (https://foundryvtt.com/packages/lootsheetnpc5e)",

"foundryvtt-arms-reach.settingNameTokensIntegrationByPrefix": "Enable the distance interaction on target token with a specific name prefix",
"foundryvtt-arms-reach.settingHintTokensIntegrationByPrefix": "If true by default enable the distance integration for all the target token with the prefix setted on the name of the token (not the character name)",
Expand Down
2 changes: 1 addition & 1 deletion src/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"foundryvtt-arms-reach.settingNameTokensIntegrationFeature": "Activer/Désactiver l'intégration des jetons",
"foundryvtt-arms-reach.settingHintTokensIntegrationFeature": "Distance maximale à laquelle un jeton peut interagir avec un autre jeton... 0 désactivera la limite (nécessite le rechargement de l'appli). Le MJ ignore la limitation de distance.",
"foundryvtt-arms-reach.settingNameGlobalInteractionDistanceForGMOnTokens": "Activer la distance du test sur les jetons même pour le MJ",
"foundryvtt-arms-reach.settingNameTokensIntegrationWithLootSheet": "Activer l'interaction de la distance pour 'Loot Sheet'",
"foundryvtt-arms-reach.settingNameTokensIntegrationWithLootSheet": "Activer l'interaction de la distance pour 'Loot Sheet NPC 5E' (https://foundryvtt.com/packages/lootsheetnpc5e)",
"foundryvtt-arms-reach.settingHintTokensIntegrationWithLootSheet": "Si coché par défaut, active l'intégration de la distance pour tous les jetons avec la feuille 'LootSheet' active",
"foundryvtt-arms-reach.settingNameTokensIntegrationByPrefix": "Activer l'interaction de la distance sur le jeton cible avec un préfixe de nom spécifique",
"foundryvtt-arms-reach.settingNameTokensIntegrationExplicitName": "Définir le nom du jeton source que vous voulez utiliser pour l'interaction",
Expand Down
16 changes: 6 additions & 10 deletions src/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "foundryvtt-arms-reach",
"title": "FoundryVTT Arms Reach",
"description": "Allows the GM to limit the distance that a player can interacted with a placeable object like door, journal, stairway, token, ecc..",
"version": "2.2.9",
"version": "2.2.10",
"authors": [
{
"name": "Psyny"
Expand Down Expand Up @@ -72,12 +72,8 @@
"packs": [],
"systems": [],
"scripts": [],
"esmodules": [
"foundryvtt-arms-reach.js"
],
"styles": [
"styles/foundryvtt-arms-reach.css"
],
"esmodules": ["foundryvtt-arms-reach.js"],
"styles": ["styles/foundryvtt-arms-reach.css"],
"compatibility": {
"minimum": 10,
"verified": 10,
Expand All @@ -87,8 +83,8 @@
"url": "https://github.com/p4535992/foundryvtt-arms-reach",
"manifest": "https://github.com/p4535992/foundryvtt-arms-reach/releases/latest/download/module.json",
"download": "https://github.com/p4535992/foundryvtt-arms-reach/releases/latest/download/module.zip",
"readme": "https://github.com/p4535992/foundryvtt-arms-reach/blob/v2.2.9/README.md",
"changelog": "https://github.com/p4535992/foundryvtt-arms-reach/blob/v2.2.9/changelog.md",
"readme": "https://github.com/p4535992/foundryvtt-arms-reach/blob/v2.2.10/README.md",
"changelog": "https://github.com/p4535992/foundryvtt-arms-reach/blob/v2.2.10/changelog.md",
"bugs": "https://github.com/p4535992/foundryvtt-arms-reach/issues",
"allowBugReporter": true,
"relationships": {
Expand All @@ -109,4 +105,4 @@
],
"conflicts": []
}
}
}
128 changes: 118 additions & 10 deletions src/scripts/ArmsReachHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,39 @@ export const getFirstPlayerTokenSelected = function (): Token | null {
}
};

/**
* Returns the first selected token
*/
export const getFirstPlayerTokenSelectedNo = function (noToken: Token): Token | null {
// Get first token ownted by the player
const selectedTokens = <Token[]>canvas.tokens?.controlled;
if (selectedTokens.length > 1) {
//iteractionFailNotification(i18n(`${CONSTANTS.MODULE_NAME}.warningNoSelectMoreThanOneToken`));
return null;
}
if (!selectedTokens || selectedTokens.length === 0) {
//if(game.user.character.token){
// //@ts-ignore
// return game.user.character.token;
//}else{
return null;
//}
}
if (
selectedTokens[0] &&
<boolean>game.settings.get(CONSTANTS.MODULE_NAME, "enableInteractionForTokenOwnedByUser")
) {
const isPlayerOwned = selectedTokens[0]?.document.isOwner;
if (!isPlayerOwned) {
return null;
} else {
return <string>selectedTokens[0]?.id !== <string>noToken?.id ? <Token>selectedTokens[0] : null;
}
} else {
return <string>selectedTokens[0]?.id !== <string>noToken?.id ? <Token>selectedTokens[0] : null;
}
};

/**
* Returns a list of selected (or owned, if no token is selected)
* note: ex getSelectedOrOwnedToken
Expand All @@ -222,8 +255,9 @@ export const getFirstPlayerToken = function (): Token | null {
if (<boolean>game.settings.get(CONSTANTS.MODULE_NAME, "useOwnedTokenIfNoTokenIsSelected")) {
if (!controlled.length || controlled.length === 0) {
// If no token is selected use the token of the users character
token = <Token>//@ts-ignore
canvas.tokens?.placeables.find((token) => token.document.actorId === game.user?.character?.id);
token = <
Token //@ts-ignore
>canvas.tokens?.placeables.find((token) => token.document.actorId === game.user?.character?.id);
}
// If no token is selected use the first owned token of the users character you found
if (!token) {
Expand All @@ -243,6 +277,55 @@ export const getFirstPlayerToken = function (): Token | null {
}
};

/**
* Returns a list of selected (or owned, if no token is selected)
* note: ex getSelectedOrOwnedToken
*/
export const getFirstPlayerTokenNo = function (noToken: Token): Token | null {
// Get controlled token
let token: Token;
const controlled: Token[] = <Token[]>canvas.tokens?.controlled;
// Do nothing if multiple tokens are selected
if (controlled.length && controlled.length > 1) {
//iteractionFailNotification(i18n(`${CONSTANTS.MODULE_NAME}.warningNoSelectMoreThanOneToken`));
return null;
}
// If exactly one token is selected, take that
token = <Token>controlled[0];
if (!token) {
if (<boolean>game.settings.get(CONSTANTS.MODULE_NAME, "useOwnedTokenIfNoTokenIsSelected")) {
if (!controlled.length || controlled.length === 0) {
// If no token is selected use the token of the users character
token = <Token>canvas.tokens?.placeables.find(
(token) =>
//@ts-ignore
token.document.actorId === game.user?.character?.id && token.id !== noToken.id
);
}
// If no token is selected use the first owned token of the users character you found
if (!token) {
for (const tok of <Token[]>canvas.tokens?.ownedTokens) {
if (tok.id !== noToken.id) {
token = tok;
break;
}
}
// token = <Token>canvas.tokens?.ownedTokens[0];
}
}
}
if (token && <boolean>game.settings.get(CONSTANTS.MODULE_NAME, "enableInteractionForTokenOwnedByUser")) {
const isPlayerOwned = token.document.isOwner;
if (!isPlayerOwned) {
return null;
} else {
return token;
}
} else {
return token;
}
};

/**
* Check if active document is the canvas
*/
Expand Down Expand Up @@ -434,15 +517,19 @@ const getPlaceableY = function (placeable: any): number {
// ============================================================================================

function distance_between_token_rect(p1: Token, p2: ArmsreachData) {
const x1 = p1.x;
const y1 = p1.y;
const x1b = p1.x + <number>p1.w;
const y1b = p1.y + <number>p1.h;
//@ts-ignore
const x1 = p1.x ? p1.x : p1.document.x;
//@ts-ignore
const y1 = p1.y ? p1.y : p1.document.y;
const x1b = x1 + <number>p1.w;
const y1b = y1 + <number>p1.h;

const x2 = p2.x;
const y2 = p2.y;
const x2b = p2.x + <number>p2.w;
const y2b = p2.y + <number>p2.h;
//@ts-ignore
const x2 = p2.x ? p2.x : p2.document.x;
//@ts-ignore
const y2 = p2.y ? p2.y : p2.document.y;
const x2b = x2 + <number>p2.w;
const y2b = y2 + <number>p2.h;

const left = x2b < x1;
const right = x1b < x2;
Expand Down Expand Up @@ -496,6 +583,14 @@ function units_between_token_and_placeable(token: Token, b: ArmsreachData) {
// TODO i don't understand this for manage the door control
if (b.documentName !== WallDocument.documentName) {
// dist = (Math.floor(dist) / unitGridSize) * unitSize;
// if (b.documentName === TokenDocument.documentName) {
// // const tokensSizeAdjust = (Math.min(<number>b.w, <number>b.h) || 0) / Math.SQRT2;
// // const tokenScaleAdjust = tokensSizeAdjust / <number>canvas.dimensions?.size;
// // // dist = (dist * <number>canvas.dimensions?.size) / <number>canvas.dimensions?.distance - tokensSizeAdjust;
// // dist = dist / <number>canvas.dimensions?.distance;
// const grids = grids_between_tokens(token, b);
// dist = grids / (<number>canvas.dimensions?.size / <number>canvas.grid?.size);
// }
} else {
//@ts-ignore
const isDoor: DoorControl = <DoorControl>canvas.controls?.doors?.children.find((x: DoorControl) => {
Expand Down Expand Up @@ -622,6 +717,19 @@ function getUnitTokenDist(token: Token, placeableObjectTarget: ArmsreachData) {
return d;
}

// function getUnitTokenDistOriginalLevels(token1, token2) {
// const unitsToPixel = <number>canvas.dimensions?.size / <number>canvas.dimensions?.distance;
// const x1 = token1.center.x;
// const y1 = token1.center.y;
// const z1 = token1.losHeight * unitsToPixel;
// const x2 = token2.center.x;
// const y2 = token2.center.y;
// const z2 = token2.losHeight * unitsToPixel;

// const d = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2) + Math.pow(z2 - z1, 2)) / unitsToPixel;
// return d;
// }

/**
* Find out if a token is in the range of a particular object
* @param {Object} token - a token
Expand Down
6 changes: 5 additions & 1 deletion src/scripts/DoorsReach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,11 @@ export const DoorsReach = {
if (game.settings.get(CONSTANTS.MODULE_NAME, "autoCheckElevationByDefault")) {
const res = checkElevation(token, wall);
if (!res) {
warn(`The token '${token.name}' is not on the elevation range of this placeable object`);
warn(
`The token '${getCharacterName(
token
)}' is not on the elevation range of this placeable object`
);
return false;
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/scripts/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,15 @@ export function getTokenByTokenName(name) {
*/
export const getCharacterName = function (token: Token) {
let tokenName = "";
if (token.name) {
tokenName = token.name;
} else if (token.actor && token.actor.name) {
if (token.actor && token.actor.name) {
tokenName = token.actor.name;
} else if (token.name) {
tokenName = token.name;
}
//@ts-ignore
else if (token.document.actorId) {
//@ts-ignore
tokenName = game.actors?.get(token.document.actorId).name;
}
return tokenName;
};
Loading

0 comments on commit 9ea844b

Please sign in to comment.