Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f770f7597 | |||
| fa62e1d9c4 | |||
| f18ce33779 | |||
| 34cead5cba | |||
| eeb6db76a6 | |||
| 9c44994fd2 | |||
| 23c1a903a0 | |||
| 1b3f563c4e | |||
| c4595f408f | |||
| fae1bb8fe0 | |||
| f203bea673 | |||
| 84c18a6221 | |||
| 0573adf0fe | |||
| 76c71329d6 | |||
| f918e148fe | |||
| 52d77ba0a4 | |||
| b06169f149 | |||
| c914eb23ae | |||
| c8a7c73ace | |||
| 76cff06b66 | |||
| ad005c1bb1 | |||
| 40b882ec93 | |||
| 1c8ce20a45 | |||
| a16f97f9e7 | |||
| a3e0ea9832 | |||
| aa2b8b3928 | |||
| a164811bb6 | |||
| 752b8375ab | |||
| 32b38d8efe | |||
| c3a62e3646 | |||
| 39f7bab4b6 | |||
| a3be4ceb03 | |||
| b275e777db |
@@ -1,3 +1,59 @@
|
|||||||
|
## 1.10.3
|
||||||
|
### Compatibility
|
||||||
|
- This release contains changes required to be compatible with Foundry 9.245
|
||||||
|
|
||||||
|
|
||||||
|
## 1.10.2
|
||||||
|
### Bugfixes
|
||||||
|
- Fixed a bug that could cause squares to be highlighted in the wrong color when using waypoints on a 5/10/5 gird
|
||||||
|
- When using Token Drag Vision, the temporary vision is now correctly cleaned up when dropping the token (resolves a conflict with the "Perfect Vision" module)
|
||||||
|
|
||||||
|
|
||||||
|
## 1.10.1
|
||||||
|
### Bugfixes
|
||||||
|
- Fixed a bug that caused keybindings to break if no scene is active
|
||||||
|
|
||||||
|
### Translation
|
||||||
|
- Updated Spanish translation (thanks to Viriato139ac#342)
|
||||||
|
|
||||||
|
|
||||||
|
## 1.10.0
|
||||||
|
**BREAKING** Drag Ruler 1.10.0 and onward cannot update directly from Drag Ruler versions older than 1.3.0. If you've been using Drag Ruler 1.2.2 or earlier in your world make sure to update to any Version between (inclusive) Drag Ruler 1.3.0 and 1.9.1, launch your world and log in as GM at least once. After doing so you can safely update to v1.10.0 or newer versions. Updating directly from 1.2.2 or older to 1.10.0 or newer will cause Drag Ruler to forget your Speed Prover Settings.
|
||||||
|
|
||||||
|
### New features
|
||||||
|
- Drag Ruler's key bindings can now be assigned to custom keys by the user
|
||||||
|
- Measuring difficult terrain on gridded maps with euclidean grid rule is now supported (for this to work the `Terrain Ruler` module needs to be enabled)
|
||||||
|
|
||||||
|
### Compatibility
|
||||||
|
- Drag Ruler now supports Foundry v9
|
||||||
|
- Drag Ruler now utilizes libwrapper to increase interoperability with other modules
|
||||||
|
|
||||||
|
### Translation
|
||||||
|
- Added french translation (thanks to Elfenduli)
|
||||||
|
- Updated japanese translation (thanks to touge)
|
||||||
|
|
||||||
|
|
||||||
|
## 1.9.1
|
||||||
|
### Bugfixes
|
||||||
|
- Fixed a bug that caused the ruler to misbehave or not show up at all if the speed provider isn't configured (this was a regression introduced in 1.9.0)
|
||||||
|
|
||||||
|
### Translation
|
||||||
|
- Updated the spaish translation (thanks to Viriato139ac#342)
|
||||||
|
|
||||||
|
|
||||||
|
## 1.9.0
|
||||||
|
### New features
|
||||||
|
- On Gridless scenes, tokens can now snap to their speed limits, to make full usage of a token's movement speed easier. This feature can be temporarily disabled by pressing Shift during drag and can be disabled completely in the settings.
|
||||||
|
|
||||||
|
### Bugfixes
|
||||||
|
- Non-square tokens (e.g. 2x1) now work correctly on square grids
|
||||||
|
- When modifying difficult terrain that a token has already moved over, this the movement history of the token won't change anymore (this was a regression introduced in 1.8.0)
|
||||||
|
- Fixed a bug that prevented pausing/unpausing the game when no scene was active
|
||||||
|
|
||||||
|
### API
|
||||||
|
- Added `dragRuler.getColorForDistanceAndToken` API endpoint that allows other modules to receive the highlight color for a specified distance with a given token.
|
||||||
|
|
||||||
|
|
||||||
## 1.8.2
|
## 1.8.2
|
||||||
### Compatibility
|
### Compatibility
|
||||||
- The generic speed provider defaults have been updated for lance 1.0 (thanks to BoltsJ!)
|
- The generic speed provider defaults have been updated for lance 1.0 (thanks to BoltsJ!)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[](https://ko-fi.com/staebchenfisch)
|
[](https://ko-fi.com/staebchenfisch)
|
||||||
|
|
||||||
# Drag Ruler
|
# Drag Ruler
|
||||||
This module shows a ruler when you drag a token or measurement template to infrom you how far you've dragged it from it's start point. Additionally, if you're using a grid, the spaces the token will travel though will be colored depending on your tokens speed. By default three colors are being used: green for spaces that your token can reach by walking normally are colored green, spaces that can only be reached by dashing will be colored red and spaces that cannot be reached with the token's speed will be colored red. If you're using a gridless map the ruler color will change to convey this information.
|
This module shows a ruler when you drag a token or measurement template to inform you how far you've dragged it from its start point. Additionally, if you're using a grid, the spaces the token will travel though will be colored depending on your tokens speed. By default, three colors are being used: green for spaces that your token can reach by walking normally are colored green, spaces that can only be reached by dashing will be colored yellow and spaces that cannot be reached with the token's speed will be colored red. If you're using a gridless map the ruler color will change to convey this information.
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
@@ -33,18 +33,20 @@ During combat, Drag Ruler will remember the path a token has taken during it's t
|
|||||||
|
|
||||||
|
|
||||||
## Game systems with Drag Ruler integration
|
## Game systems with Drag Ruler integration
|
||||||
Drag Ruler will work with all Foundry VTT game systems. However some game systems offer a special integration via the [Drag Ruler API](#api), that allows Drag Ruler to take the rules of the game system into account when dispaying speeds (such as weight carried or conditions that apply to the character), offering a smoother experience. While some game systems offer this integration natively, for other game systems there are modules providing the integration. If the integration is provided via a module you need to install and activate both Drag Ruler and the integration module to benefit from the integration.
|
Drag Ruler will work with all Foundry VTT game systems. However, some game systems offer a special integration via the [Drag Ruler API](#api), that allows Drag Ruler to take the rules of the game system into account when dispaying speeds (such as weight carried or conditions that apply to the character), offering a smoother experience. While some game systems offer this integration natively, for other game systems there are modules providing the integration. If the integration is provided via a module you need to install and activate both Drag Ruler and the integration module to benefit from the integration.
|
||||||
|
|
||||||
The game systems that offer Drag Ruler integration are:
|
The game systems that offer Drag Ruler integration are:
|
||||||
- Cypher System (starting with version 1.13.0)
|
- Cypher System (starting with version 1.13.0)
|
||||||
- GURPS 4th Edition Game Aid (Unofficial) (starting with version 0.9.1)
|
- GURPS 4th Edition Game Aid (Unofficial) (starting with version 0.9.1)
|
||||||
- Ironclaw Second Edition (starting with version 0.2.2)
|
- Ironclaw Second Edition (starting with version 0.2.2)
|
||||||
- Lancer (via the module [Lancer Speed Provider](https://foundryvtt.com/packages/lancer-speed-provider))
|
- Lancer (via the module [Lancer Speed Provider](https://foundryvtt.com/packages/lancer-speed-provider))
|
||||||
|
- Level Up: Advanced 5th Edition (Official) (via the module [A5E Drag Ruler Integration](https://foundryvtt.com/packages/a5edragruler))
|
||||||
- Pathfinder 1 (starting with version 0.77.3)
|
- Pathfinder 1 (starting with version 0.77.3)
|
||||||
- Pathfinder 2e (via the module [PF2E Drag Ruler Integration](https://foundryvtt.com/packages/pf2e-dragruler/))
|
- Pathfinder 2e (via the module [PF2E Drag Ruler Integration](https://foundryvtt.com/packages/pf2e-dragruler/))
|
||||||
- Shadowrun 5th Edition (via the module [Drag Ruler Integration for Shadowrun 5E](https://foundryvtt.com/packages/drag-ruler-integration-for-shadowrun-5e))
|
- Shadowrun 5th Edition (via the module [Drag Ruler Integration for Shadowrun 5E](https://foundryvtt.com/packages/drag-ruler-integration-for-shadowrun-5e))
|
||||||
- Starfinder (via the module [Starfinder Drag Ruler Integration](https://foundryvtt.com/packages/starfinder-drag-ruler))
|
- Starfinder (via the module [Starfinder Drag Ruler Integration](https://foundryvtt.com/packages/starfinder-drag-ruler))
|
||||||
- Stargate RPG (starting with version 1.6.0)
|
- Stargate RPG (starting with version 1.6.0)
|
||||||
|
- Symbaroum (via the module [Symbaroum drag ruler integration](https://foundryvtt.com/packages/symbaroum-drag-ruler-integration))
|
||||||
- Tagmar RPG (starting with version 1.1.4)
|
- Tagmar RPG (starting with version 1.1.4)
|
||||||
- TheWitcherTRPG (starting with version 0.0.62)
|
- TheWitcherTRPG (starting with version 0.0.62)
|
||||||
- Tormenta20 (starting with version 1.1.37)
|
- Tormenta20 (starting with version 1.1.37)
|
||||||
|
|||||||
+25
-3
@@ -29,6 +29,19 @@
|
|||||||
"dash": "sprinten"
|
"dash": "sprinten"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"keybindings": {
|
||||||
|
"cancelDrag": "Ziehen beenden",
|
||||||
|
"createWaypoint": "Wegpunkt erstellen",
|
||||||
|
"deleteWaypoint": "Wegpunkt löschen",
|
||||||
|
"disableSnap": {
|
||||||
|
"name": "Raster deaktivieren",
|
||||||
|
"hint": "Während diese Taste gedrückt ist wird das Raster temporär deaktiviert"
|
||||||
|
},
|
||||||
|
"moveWithoutAnimation": {
|
||||||
|
"name": "Token animation deaktivieren",
|
||||||
|
"hint": "Wenn diese Taste gedrückt wird, während ein Token fallen gelassen wird, bewegt es sich ohne Animation zum Zielort."
|
||||||
|
}
|
||||||
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"alwaysShowSpeedForPCs": {
|
"alwaysShowSpeedForPCs": {
|
||||||
"name": "Geschwindigkeit von Spielercharakteren für jeden anzeigen",
|
"name": "Geschwindigkeit von Spielercharakteren für jeden anzeigen",
|
||||||
@@ -42,6 +55,15 @@
|
|||||||
"name": "Bewegungsverlauf während des Kampfes aktivieren",
|
"name": "Bewegungsverlauf während des Kampfes aktivieren",
|
||||||
"hint": "Wenn diesen Option aktiviert ist merkt sich Drag Ruler die Bewegungen, die während einer Runde eines Kampfes gemacht wurden und zeigt diese an, wenn das Token weiterbewegt wird."
|
"hint": "Wenn diesen Option aktiviert ist merkt sich Drag Ruler die Bewegungen, die während einer Runde eines Kampfes gemacht wurden und zeigt diese an, wenn das Token weiterbewegt wird."
|
||||||
},
|
},
|
||||||
|
"rightClickAction": {
|
||||||
|
"name": "Aktion bei Rechtsklick",
|
||||||
|
"hint": "Was soll getan werden, wenn die rechte Maustaste während des Ziehens gedrückt wird?",
|
||||||
|
"choices": {
|
||||||
|
"create": "Wegpunkt erstellen",
|
||||||
|
"delete": "Wegpunkt löschen",
|
||||||
|
"cancel": "Ziehen beenden"
|
||||||
|
}
|
||||||
|
},
|
||||||
"showGMRulerToPlayers": {
|
"showGMRulerToPlayers": {
|
||||||
"name": "Lineal des Spielleiters bei Spielern anzeigen",
|
"name": "Lineal des Spielleiters bei Spielern anzeigen",
|
||||||
"hint": "Wenn diese Option deaktiviert ist wird das Lineal des Spielleiters bei den anderen Spielern nicht angezeigt."
|
"hint": "Wenn diese Option deaktiviert ist wird das Lineal des Spielleiters bei den anderen Spielern nicht angezeigt."
|
||||||
@@ -78,9 +100,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"swapSpacebarRightClick": {
|
"useGridlessraster": {
|
||||||
"name": "Leertaste und Rechtsklick tauschen",
|
"name": "Geschwindigkeitsraster aktivieren",
|
||||||
"hint": "Die Funktionen der Leertaste und des Rechtsklicks sind, während eine Spielfigur bewegt wird, vertauscht. Wenn diese Option aktiviert wird können mit Rechtsklick Wegpunkte gesetzt werden und mit der Leertaste werden sie wieder gelöscht."
|
"hint": "Lässt Spielfiguren auf gitterlosen Szenen an deren Geschwindigkeitsgrenzen einrasten."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-3
@@ -29,6 +29,19 @@
|
|||||||
"dash": "dash"
|
"dash": "dash"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"keybindings": {
|
||||||
|
"cancelDrag": "Cancel dragging",
|
||||||
|
"createWaypoint": "Create waypoint",
|
||||||
|
"deleteWaypoint": "Delete waypoint",
|
||||||
|
"disableSnap": {
|
||||||
|
"name": "Disable snapping",
|
||||||
|
"hint": "Snapping will be temporarily disabled while this key is being held down"
|
||||||
|
},
|
||||||
|
"moveWithoutAnimation": {
|
||||||
|
"name": "Disable token animation",
|
||||||
|
"hint": "When being held while dropping a token, the token will move to the target location without animating"
|
||||||
|
}
|
||||||
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"alwaysShowSpeedForPCs": {
|
"alwaysShowSpeedForPCs": {
|
||||||
"name": "Show PC speed to everyone",
|
"name": "Show PC speed to everyone",
|
||||||
@@ -42,6 +55,15 @@
|
|||||||
"name": "Enable movement history during combat",
|
"name": "Enable movement history during combat",
|
||||||
"hint": "If enabled, Drag Ruler will remember the path a token took during it's turn in combat and will display it when you pick the token back up."
|
"hint": "If enabled, Drag Ruler will remember the path a token took during it's turn in combat and will display it when you pick the token back up."
|
||||||
},
|
},
|
||||||
|
"rightClickAction": {
|
||||||
|
"name": "Right click action",
|
||||||
|
"hint": "What action shall be performed when right clicking while dragging a token?",
|
||||||
|
"choices": {
|
||||||
|
"create": "Create waypoint",
|
||||||
|
"delete": "Delete waypoint",
|
||||||
|
"cancel": "Cancel drag"
|
||||||
|
}
|
||||||
|
},
|
||||||
"showGMRulerToPlayers": {
|
"showGMRulerToPlayers": {
|
||||||
"name": "Show GM ruler to players",
|
"name": "Show GM ruler to players",
|
||||||
"hint": "If disabled the ruler of GMs will not be shown for non-GM players"
|
"hint": "If disabled the ruler of GMs will not be shown for non-GM players"
|
||||||
@@ -78,9 +100,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"swapSpacebarRightClick": {
|
"useGridlessRaster": {
|
||||||
"name": "Swap spacebar and right click",
|
"name": "Use speed based snapping",
|
||||||
"hint": "Swaps the functions of spacebar and right click during dragging. If enabled right click will place waypoints and spacebar will delete them"
|
"hint": "On Gridless scenes, this makes tokens snap to the token's speed ranges."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-3
@@ -33,6 +33,19 @@
|
|||||||
"dash": "correr"
|
"dash": "correr"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"keybindings": {
|
||||||
|
"cancelDrag": "Cancelar arrastre",
|
||||||
|
"createWaypoint": "Crear punto de ruta",
|
||||||
|
"deleteWaypoint": "Borrar punto de ruta",
|
||||||
|
"disableSnap": {
|
||||||
|
"name": "Deshabilitar ajuste",
|
||||||
|
"hint": "El ajuste a la rejilla se deshabilitará temporalmente mientras se presione esta tecla"
|
||||||
|
},
|
||||||
|
"moveWithoutAnimation": {
|
||||||
|
"name": "Deshabilitar animación de icono",
|
||||||
|
"hint": "Si al soltar un icono se presiona esta tecla, se deshabilitará la animación del icono al moverse al destino"
|
||||||
|
}
|
||||||
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"alwaysShowSpeedForPCs": {
|
"alwaysShowSpeedForPCs": {
|
||||||
"name": "Mostrar velocidad de los PJs a todo el mundo",
|
"name": "Mostrar velocidad de los PJs a todo el mundo",
|
||||||
@@ -46,6 +59,15 @@
|
|||||||
"name": "Habilitar historial de movimiento durante el combate",
|
"name": "Habilitar historial de movimiento durante el combate",
|
||||||
"hint": "Si se habilita, Drag Ruler recordará la ruta que ha seguido un icono en su turno y la mostrará al seleccionarlo de nuevo"
|
"hint": "Si se habilita, Drag Ruler recordará la ruta que ha seguido un icono en su turno y la mostrará al seleccionarlo de nuevo"
|
||||||
},
|
},
|
||||||
|
"rightClickAction": {
|
||||||
|
"name": "Acción del botón derecho",
|
||||||
|
"hint": "Qué acción se llevará a cabo cuando se haga clic derecho mientras se arrastra un icono",
|
||||||
|
"choices": {
|
||||||
|
"create": "Crear punto de ruta",
|
||||||
|
"delete": "Borrar punto de ruta",
|
||||||
|
"cancel": "Cancelar arrastre"
|
||||||
|
}
|
||||||
|
},
|
||||||
"showGMRulerToPlayers": {
|
"showGMRulerToPlayers": {
|
||||||
"name": "Mostrar regla del GM a los jugadores",
|
"name": "Mostrar regla del GM a los jugadores",
|
||||||
"hint": "Si se deshabilita, no se mostrará la regla de medición de los GMs al resto de usuarios"
|
"hint": "Si se deshabilita, no se mostrará la regla de medición de los GMs al resto de usuarios"
|
||||||
@@ -82,9 +104,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"swapSpacebarRightClick": {
|
"useGridlessRaster": {
|
||||||
"name": "Intercambiar barra espaciadora y clic-derecho",
|
"name": "Usar ajuste a la velocidad",
|
||||||
"hint": "Cambia el funcionamiento de la barra espaciadora y el clic-derecho del ratón mientras se arrastra un icono. Si está habilitado, clic-derecho establecerá puntos en la ruta y la barra espaciadora los borrará"
|
"hint": "Cuando no se use rejilla en la escena, este ajuste hace que los iconos se ajusten a sus rangos de velocidad. Se puede deshabilitar temporalmente pulsando la tecla Mayús mientras se arrastra"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
{
|
||||||
|
"drag-ruler": {
|
||||||
|
"dependencies": {
|
||||||
|
"ok": "OK",
|
||||||
|
"terrain-ruler": {
|
||||||
|
"title": "Comment mesurer un terrain difficile avec Drag Ruler",
|
||||||
|
"text": "Vous avez le module {moduleName} activé. Drag Ruler est capable de mesurer un terrain difficile qui a été placé à l'aide de ce module. Pour rendre cela possible, Drag Ruler utilise le module Terrain Ruler. Si Terrain Ruler est installé et activé Drag Ruler commencera automatiquement à respecter le terrain difficile dans ses mesures.",
|
||||||
|
"neverShowAgain": "Ne plus jamais afficher cela"
|
||||||
|
},
|
||||||
|
"socketlib": {
|
||||||
|
"title": "Module Socketlib manquant",
|
||||||
|
"text": "Drag Ruler nécessite que le module socketlib fonctionne correctement. Veuillez activer le module socketlib dans ce monde."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"resetMovementHistory": "Réinitialiser l'historique des mouvements",
|
||||||
|
"genericSpeedProvider": {
|
||||||
|
"settings": {
|
||||||
|
"dashMultiplier": {
|
||||||
|
"name": "Multiplicateur de courses",
|
||||||
|
"hint": "Cela peut être utilisé pour donner aux jetons une vitesse secondaire pendant la coloration du chemin mesuré. Réglez-le sur 0 pour désactiver la vitesse secondaire."
|
||||||
|
},
|
||||||
|
"speedAttribute": {
|
||||||
|
"name": "Attribut de vitesse",
|
||||||
|
"hint": "L'attribut qui définit la vitesse de marche d'un jeton. Il est utilisé lors de la coloration du chemin mesuré." }
|
||||||
|
},
|
||||||
|
"speeds": {
|
||||||
|
"walk": "marche",
|
||||||
|
"dash": "course"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"alwaysShowSpeedForPCs": {
|
||||||
|
"name": "Afficher la vitesse du PJ à tout le monde",
|
||||||
|
"hint": "Si activé, la coloration basée sur la vitesse de l'acteur pour les personnages joueurs sera montrée à tout le monde, même s'ils n'ont pas la permission d'observateur pour la feuille de personnage."
|
||||||
|
},
|
||||||
|
"autoStartMeasurement": {
|
||||||
|
"name": "Démarrer automatiquement la mesure",
|
||||||
|
"hint": "Si activé, Drag Ruler commencera à mesurer dès que le jeton est glissé. S'il est désactivé, Drag Ruler restera inactif et ne commencera à mesurer qu'une fois que le bouton pour ajouter un waypoint est enfoncé."
|
||||||
|
},
|
||||||
|
"enableMovementHistory": {
|
||||||
|
"name": "Activer l'historique des mouvements pendant le combat",
|
||||||
|
"hint": "Si activé, Drag Ruler se souviendra du chemin emprunté par un jeton pendant son tour de combat et l'affichera lorsque vous récupérerez le jeton."
|
||||||
|
},
|
||||||
|
"showGMRulerToPlayers": {
|
||||||
|
"name": "Afficher la règle MJ aux joueurs",
|
||||||
|
"hint": "Si désactivé, la règle des MJ ne sera pas affichée pour les joueurs non-MJ"
|
||||||
|
},
|
||||||
|
"speedProviderSettings": {
|
||||||
|
"name": "Paramètres du système de vitesse",
|
||||||
|
"hint": "Les paramètres du système de vitesse contiennent tous les paramètres spécifiques au système de jeu.",
|
||||||
|
"button": "Paramètres du système de vitesse",
|
||||||
|
"windowTitle": "Paramètres du système de vitesse",
|
||||||
|
"headers": {
|
||||||
|
"speedProvider": "système de vitesse",
|
||||||
|
"speedProviderSettings": "Paramètres spécifiques au système de vitesse"
|
||||||
|
},
|
||||||
|
"activeProvider": {
|
||||||
|
"name": "système de vitesse actuellement actif",
|
||||||
|
"hint": "Les paramètres indiqués ci-dessous dépendent du système de vitesse actif. Si le MJ sélectionne un système de vitesse différent, les paramètres disponibles peuvent changer."
|
||||||
|
},
|
||||||
|
"noSettings": "Ce système de vitesse n'offre aucune option de configuration.",
|
||||||
|
"color": {
|
||||||
|
"name": "Couleur pour {colorName}",
|
||||||
|
"hint": "La couleur qui sera utilisée pour colorier les carrés qui sont dans la plage {colorName}",
|
||||||
|
"unreachable": {
|
||||||
|
"name": "injoignable",
|
||||||
|
"hint": "La couleur des espaces qui ne sont pas accessibles par le jeton déplacé"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"speedProvider": {
|
||||||
|
"name": "système de paramètres de vitesse",
|
||||||
|
"indice": "Sélectionnez qui fournit les informations de vitesse pour les jetons lors de la coloration. Drag Ruler offre un système de vitesse générique qui fournit des fonctionnalités de base et devrait fonctionner pour tous les systèmes de jeu s'il est correctement configuré. Plus de systèmes de vitesse peuvent être mis à disposition via les systèmes de jeu et les modules installés . La sélection d'un autre système de vitesse que le système de vitesse générique peut offrir une meilleure intégration dans les règles du système de jeu que vous utilisez. Les options ci-dessous dépendent du système de vitesse sélectionné ici.",
|
||||||
|
"choices": {
|
||||||
|
"module": "Module {name}",
|
||||||
|
"native": "Générique",
|
||||||
|
"system": "Systéme {name}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"useGridlessRaster": {
|
||||||
|
"name": "Use speed based snapping",
|
||||||
|
"hint": "On Gridless scenes, this makes tokens snap to the token's speed ranges. This can be temporarily disabled by pressing Shift during drag."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
-3
@@ -1,5 +1,19 @@
|
|||||||
{
|
{
|
||||||
|
"Localization Provided By": "touge",
|
||||||
"drag-ruler": {
|
"drag-ruler": {
|
||||||
|
"dependencies": {
|
||||||
|
"ok": "OK",
|
||||||
|
"terrain-ruler": {
|
||||||
|
"title": "Drag Rulerで移動困難地形を測定する",
|
||||||
|
"text": "「{moduleName}」モジュールが有効化されました。Drag Rulerは、同モジュールによって設定された移動困難地形を測定できます。これには「Terrain Ruler」モジュールが必要です。有効化すると、自動的に移動困難地形を考慮した測定を行います",
|
||||||
|
"neverShowAgain": "再表示しない"
|
||||||
|
},
|
||||||
|
"socketlib": {
|
||||||
|
"title": "「Socketlib」が見つかりません",
|
||||||
|
"text": "Drag Rulerの正常動作には「Socketlib」モジュールが必要です。このワールドで「Socketlib」を有効にしてください。"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"resetMovementHistory": "移動履歴のリセット",
|
||||||
"genericSpeedProvider": {
|
"genericSpeedProvider": {
|
||||||
"settings": {
|
"settings": {
|
||||||
"dashMultiplier": {
|
"dashMultiplier": {
|
||||||
@@ -21,6 +35,14 @@
|
|||||||
"name": "プレイヤーキャラクターの移動速度を全員に公開する",
|
"name": "プレイヤーキャラクターの移動速度を全員に公開する",
|
||||||
"hint": "有効にすると、アクターの観察者(Observer)権限を持たない人にも,移動範囲の色分けが表示されるようになります。"
|
"hint": "有効にすると、アクターの観察者(Observer)権限を持たない人にも,移動範囲の色分けが表示されるようになります。"
|
||||||
},
|
},
|
||||||
|
"autoStartMeasurement": {
|
||||||
|
"name": "自動計測",
|
||||||
|
"hint": "有効化時、Drag Rulerはトークンがドラッグされた時点で計測を初めます。無効化の場合、ドラッグしてもDrag Rulerは起動せず、中間地点をおいたときにのみ起動します。"
|
||||||
|
},
|
||||||
|
"enableMovementHistory": {
|
||||||
|
"name": "戦闘中の移動履歴を有効にする",
|
||||||
|
"hint": "有効にすると、Drag Rulerは戦闘ターン中にコマが辿った経路を記憶するようになります。これはコマの再選択時に再表示されます。"
|
||||||
|
},
|
||||||
"showGMRulerToPlayers": {
|
"showGMRulerToPlayers": {
|
||||||
"name": "GMのルーラーをプレイヤーに見せる",
|
"name": "GMのルーラーをプレイヤーに見せる",
|
||||||
"hint": "無効の場合、GMのルーラーはプレイヤーに表示されません。"
|
"hint": "無効の場合、GMのルーラーはプレイヤーに表示されません。"
|
||||||
@@ -57,9 +79,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"swapSpacebarRightClick": {
|
"useGridlessRaster": {
|
||||||
"name": "スペースキーと右クリックを入れ替える",
|
"name": "移動速度制限",
|
||||||
"hint": "ドラッグ中のスペースキーと右クリックの機能を入れ替えます。有効にすると右クリックがウェイポイントの配置、スペースキーが削除になります。"
|
"hint": "グリッドの無いシーンでは、コマがドラッグできる範囲を移動速度ぶんまで制限します。Shiftキーを押すことで一時的にこの制限を無視できます。"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,10 +73,6 @@
|
|||||||
"system": "시스템 {name}"
|
"system": "시스템 {name}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"swapSpacebarRightClick": {
|
|
||||||
"name": "스페이스바와 우클릭 스왑",
|
|
||||||
"hint": "드래그 도중 스페이스바의 기능을 우클릭 기능과 바꾼다. 활성화된 경우 드래그시 우클릭을 사용하면 경유지가 배치되고, 스페이스바가 해당 경유지를 삭제한다."
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,10 +56,6 @@
|
|||||||
"system": "系統 {name}"
|
"system": "系統 {name}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"swapSpacebarRightClick": {
|
|
||||||
"name": "交換空格鍵並鼠標右鍵",
|
|
||||||
"hint": "交換空格鍵和右鍵點擊在拖動過程中的功能。如果啟用,右鍵單擊將放置航點,空格鍵將刪除它們。"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-9
@@ -2,9 +2,9 @@
|
|||||||
"name": "drag-ruler",
|
"name": "drag-ruler",
|
||||||
"title": "Drag Ruler",
|
"title": "Drag Ruler",
|
||||||
"description": "When dragging a token displays a ruler showing how far you've moved that token.",
|
"description": "When dragging a token displays a ruler showing how far you've moved that token.",
|
||||||
"version": "1.8.2",
|
"version": "1.10.3",
|
||||||
"minimumCoreVersion" : "0.8.5",
|
"minimumCoreVersion" : "9.245",
|
||||||
"compatibleCoreVersion" : "0.8.9",
|
"compatibleCoreVersion" : "9",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Manuel Vögele",
|
"name": "Manuel Vögele",
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"esmodules": [
|
"esmodules": [
|
||||||
|
"src/libwrapper_shim.js",
|
||||||
"src/main.js",
|
"src/main.js",
|
||||||
"src/socket.js"
|
"src/socket.js"
|
||||||
],
|
],
|
||||||
@@ -30,6 +31,16 @@
|
|||||||
"name": "English",
|
"name": "English",
|
||||||
"path": "lang/en.json"
|
"path": "lang/en.json"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"lang": "es",
|
||||||
|
"name": "Español",
|
||||||
|
"path": "lang/es.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lang": "fr",
|
||||||
|
"name": "Français",
|
||||||
|
"path": "lang/fr.json"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"lang": "ja",
|
"lang": "ja",
|
||||||
"name": "日本語",
|
"name": "日本語",
|
||||||
@@ -44,11 +55,6 @@
|
|||||||
"lang": "zh-tw",
|
"lang": "zh-tw",
|
||||||
"name": "正體中文",
|
"name": "正體中文",
|
||||||
"path": "lang/zh-tw.json"
|
"path": "lang/zh-tw.json"
|
||||||
},
|
|
||||||
{
|
|
||||||
"lang": "es",
|
|
||||||
"name": "Español",
|
|
||||||
"path": "lang/es.json"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
@@ -59,7 +65,7 @@
|
|||||||
],
|
],
|
||||||
"socket": true,
|
"socket": true,
|
||||||
"url": "https://github.com/manuelVo/foundryvtt-drag-ruler",
|
"url": "https://github.com/manuelVo/foundryvtt-drag-ruler",
|
||||||
"download": "https://github.com/manuelVo/foundryvtt-drag-ruler/archive/v1.8.2.zip",
|
"download": "https://github.com/manuelVo/foundryvtt-drag-ruler/archive/v1.10.3.zip",
|
||||||
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-drag-ruler/master/module.json",
|
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-drag-ruler/master/module.json",
|
||||||
"readme": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/README.md",
|
"readme": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/README.md",
|
||||||
"changelog": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/CHANGELOG.md",
|
"changelog": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/CHANGELOG.md",
|
||||||
|
|||||||
+3
-2
@@ -121,7 +121,7 @@ export function getColorForDistanceAndToken(distance, token, ranges=null) {
|
|||||||
ranges = getRangesFromSpeedProvider(token);
|
ranges = getRangesFromSpeedProvider(token);
|
||||||
}
|
}
|
||||||
if (ranges.length === 0)
|
if (ranges.length === 0)
|
||||||
return this.color;
|
return null;
|
||||||
const currentRange = ranges.reduce((minRange, currentRange) => {
|
const currentRange = ranges.reduce((minRange, currentRange) => {
|
||||||
if (distance <= currentRange.range && currentRange.range < minRange.range)
|
if (distance <= currentRange.range && currentRange.range < minRange.range)
|
||||||
return currentRange;
|
return currentRange;
|
||||||
@@ -131,10 +131,11 @@ export function getColorForDistanceAndToken(distance, token, ranges=null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getMovedDistanceFromToken(token) {
|
export function getMovedDistanceFromToken(token) {
|
||||||
|
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active;
|
||||||
const history = getMovementHistory(token);
|
const history = getMovementHistory(token);
|
||||||
const segments = Ruler.dragRulerGetRaysFromWaypoints(history, {x: token.x, y: token.y}).map(ray => {return {ray}});
|
const segments = Ruler.dragRulerGetRaysFromWaypoints(history, {x: token.x, y: token.y}).map(ray => {return {ray}});
|
||||||
const shape = getTokenShape(token);
|
const shape = getTokenShape(token);
|
||||||
const distances = measureDistances(segments, token, shape);
|
const distances = measureDistances(segments, token, shape, {enableTerrainRuler: terrainRulerAvailable});
|
||||||
// Sum up the distances
|
// Sum up the distances
|
||||||
return distances.reduce((acc, val) => acc + val, 0);
|
return distances.reduce((acc, val) => acc + val, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ export function highlightMeasurementTerrainRuler(ray, startDistance, tokenShape=
|
|||||||
|
|
||||||
export function measureDistances(segments, entity, shape, options={}) {
|
export function measureDistances(segments, entity, shape, options={}) {
|
||||||
const opts = duplicate(options)
|
const opts = duplicate(options)
|
||||||
|
if (canvas.grid.diagonalRule === "EUCL") {
|
||||||
|
opts.ignoreGrid = true;
|
||||||
|
opts.gridSpaes = false;
|
||||||
|
}
|
||||||
if (opts.enableTerrainRuler) {
|
if (opts.enableTerrainRuler) {
|
||||||
opts.gridSpaces = true;
|
opts.gridSpaces = true;
|
||||||
const firstNewSegmentIndex = segments.findIndex(segment => !segment.ray.dragRulerVisitedSpaces);
|
const firstNewSegmentIndex = segments.findIndex(segment => !segment.ray.dragRulerVisitedSpaces);
|
||||||
@@ -62,9 +65,6 @@ export function checkDependencies() {
|
|||||||
if (game.modules.get("enhanced-terrain-layer")?.active) {
|
if (game.modules.get("enhanced-terrain-layer")?.active) {
|
||||||
enabledTerrainModule = game.modules.get("enhanced-terrain-layer").data.title;
|
enabledTerrainModule = game.modules.get("enhanced-terrain-layer").data.title;
|
||||||
}
|
}
|
||||||
else if (game.modules.get("TerrainLayer")?.active) {
|
|
||||||
enabledTerrainModule = game.modules.get("TerrainLayer").data.title;
|
|
||||||
}
|
|
||||||
if (enabledTerrainModule) {
|
if (enabledTerrainModule) {
|
||||||
new Dialog({
|
new Dialog({
|
||||||
title: game.i18n.localize("drag-ruler.dependencies.terrain-ruler.title"),
|
title: game.i18n.localize("drag-ruler.dependencies.terrain-ruler.title"),
|
||||||
|
|||||||
+24
-13
@@ -1,9 +1,10 @@
|
|||||||
import {highlightMeasurementTerrainRuler, measureDistances} from "./compatibility.js";
|
import {highlightMeasurementTerrainRuler, measureDistances} from "./compatibility.js";
|
||||||
import {getGridPositionFromPixels} from "./foundry_fixes.js";
|
import {getGridPositionFromPixels} from "./foundry_fixes.js";
|
||||||
import {Line} from "./geometry.js";
|
import {Line} from "./geometry.js";
|
||||||
|
import {disableSnap, moveWithoutAnimation} from "./keybindings.js";
|
||||||
import {trackRays} from "./movement_tracking.js"
|
import {trackRays} from "./movement_tracking.js"
|
||||||
import {recalculate} from "./socket.js";
|
import {recalculate} from "./socket.js";
|
||||||
import {applyTokenSizeOffset, getSnapPointForEntity, getSnapPointForToken, getTokenShape, highlightTokenShape, zip} from "./util.js";
|
import {applyTokenSizeOffset, enumeratedZip, getSnapPointForEntity, getSnapPointForToken, getTokenShape, highlightTokenShape, sum} from "./util.js";
|
||||||
|
|
||||||
// This is a modified version of Ruler.moveToken from foundry 0.7.9
|
// This is a modified version of Ruler.moveToken from foundry 0.7.9
|
||||||
export async function moveEntities(draggedEntity, selectedEntities) {
|
export async function moveEntities(draggedEntity, selectedEntities) {
|
||||||
@@ -69,7 +70,7 @@ async function animateEntities(entities, draggedEntity, draggedRays, wasPaused)
|
|||||||
});
|
});
|
||||||
|
|
||||||
const isToken = draggedEntity instanceof Token;
|
const isToken = draggedEntity instanceof Token;
|
||||||
const animate = isToken && !game.keyboard.isDown("Alt");
|
const animate = isToken && !moveWithoutAnimation;
|
||||||
const startWaypoint = animate ? 0 : entityAnimationData[0].rays.length - 1;
|
const startWaypoint = animate ? 0 : entityAnimationData[0].rays.length - 1;
|
||||||
|
|
||||||
// This is a flag of the "Monk's Active Tile Triggers" module that signals that the movement should be cancelled early
|
// This is a flag of the "Monk's Active Tile Triggers" module that signals that the movement should be cancelled early
|
||||||
@@ -130,7 +131,7 @@ function scheduleMeasurement(destination, event) {
|
|||||||
const mt = event._measureTime || 0;
|
const mt = event._measureTime || 0;
|
||||||
const originalEvent = event.data.originalEvent;
|
const originalEvent = event.data.originalEvent;
|
||||||
if (Date.now() - mt > measurementInterval) {
|
if (Date.now() - mt > measurementInterval) {
|
||||||
this.measure(destination, {snap: !originalEvent.shiftKey});
|
this.measure(destination, {snap: !disableSnap});
|
||||||
event._measureTime = Date.now();
|
event._measureTime = Date.now();
|
||||||
this._state = Ruler.STATES.MEASURING;
|
this._state = Ruler.STATES.MEASURING;
|
||||||
cancelScheduledMeasurement.call(this);
|
cancelScheduledMeasurement.call(this);
|
||||||
@@ -164,11 +165,16 @@ export function measure(destination, options={}) {
|
|||||||
options.gridSpaces = canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS;
|
options.gridSpaces = canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (canvas.grid.diagonalRule === "EUCL") {
|
||||||
|
options.gridSpaces = false;
|
||||||
|
options.ignoreGrid = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(options.ignoreGrid === undefined) {
|
if(options.ignoreGrid === undefined) {
|
||||||
options.ignoreGrid = false;
|
options.ignoreGrid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
options.enableTerrainRuler = isToken && game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.active || canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS);
|
options.enableTerrainRuler = isToken && game.modules.get("terrain-ruler")?.active;
|
||||||
|
|
||||||
const waypoints = this.waypoints.concat([destination]);
|
const waypoints = this.waypoints.concat([destination]);
|
||||||
// Move the waypoints to the center of the grid if a size is used that measures from edge to edge
|
// Move the waypoints to the center of the grid if a size is used that measures from edge to edge
|
||||||
@@ -231,7 +237,7 @@ export function measure(destination, options={}) {
|
|||||||
rulerColor = this.dragRulerGetColorForDistance(totalDistance);
|
rulerColor = this.dragRulerGetColorForDistance(totalDistance);
|
||||||
else
|
else
|
||||||
rulerColor = this.color
|
rulerColor = this.color
|
||||||
for (const [s, cs] of zip(segments.reverse(), centeredSegments.reverse())) {
|
for (const [i, s, cs] of enumeratedZip([...segments].reverse(), [...centeredSegments].reverse())) {
|
||||||
const { label, text, last } = cs;
|
const { label, text, last } = cs;
|
||||||
|
|
||||||
// Draw line segment
|
// Draw line segment
|
||||||
@@ -264,10 +270,13 @@ export function measure(destination, options={}) {
|
|||||||
|
|
||||||
// Highlight grid positions
|
// Highlight grid positions
|
||||||
if (isToken && canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS && options.gridSpaces) {
|
if (isToken && canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS && options.gridSpaces) {
|
||||||
if (options.enableTerrainRuler)
|
if (options.enableTerrainRuler) {
|
||||||
highlightMeasurementTerrainRuler.call(this, cs.ray, cs.startDistance, shape, opacityMultiplier)
|
highlightMeasurementTerrainRuler.call(this, cs.ray, cs.startDistance, shape, opacityMultiplier)
|
||||||
else
|
}
|
||||||
highlightMeasurementNative.call(this, cs.ray, cs.startDistance, shape, opacityMultiplier);
|
else {
|
||||||
|
const previousSegments = centeredSegments.slice(0, segments.length - 1 - i);
|
||||||
|
highlightMeasurementNative.call(this, cs.ray, previousSegments, shape, opacityMultiplier);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,7 +289,7 @@ export function measure(destination, options={}) {
|
|||||||
return segments;
|
return segments;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function highlightMeasurementNative(ray, startDistance, tokenShape=[{x: 0, y: 0}], alpha=1) {
|
export function highlightMeasurementNative(ray, previousSegments, tokenShape=[{x: 0, y: 0}], alpha=1) {
|
||||||
const spacer = canvas.scene.data.gridType === CONST.GRID_TYPES.SQUARE ? 1.41 : 1;
|
const spacer = canvas.scene.data.gridType === CONST.GRID_TYPES.SQUARE ? 1.41 : 1;
|
||||||
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(canvas.grid.w, canvas.grid.h))), 1);
|
||||||
const tMax = Array.fromRange(nMax+1).map(t => t / nMax);
|
const tMax = Array.fromRange(nMax+1).map(t => t / nMax);
|
||||||
@@ -299,8 +308,9 @@ export function highlightMeasurementNative(ray, startDistance, tokenShape=[{x: 0
|
|||||||
|
|
||||||
// Highlight the grid position
|
// Highlight the grid position
|
||||||
let [xg, yg] = canvas.grid.grid.getPixelsFromGridPosition(x1, y1);
|
let [xg, yg] = canvas.grid.grid.getPixelsFromGridPosition(x1, y1);
|
||||||
const subDistance = canvas.grid.measureDistances([{ray: new Ray(ray.A, {x: xg, y: yg})}], {gridSpaces: true})[0]
|
const pathUntilSpace = previousSegments.concat([{ray: new Ray(ray.A, {x: xg, y: yg})}]);
|
||||||
const color = this.dragRulerGetColorForDistance(startDistance + subDistance);
|
const distance = sum(canvas.grid.measureDistances(pathUntilSpace, {gridSpaces: true}));
|
||||||
|
const color = this.dragRulerGetColorForDistance(distance);
|
||||||
const snapPoint = getSnapPointForToken(...canvas.grid.getTopLeft(x, y), this.draggedEntity);
|
const snapPoint = getSnapPointForToken(...canvas.grid.getTopLeft(x, y), this.draggedEntity);
|
||||||
const [snapX, snapY] = getGridPositionFromPixels(snapPoint.x + 1, snapPoint.y + 1);
|
const [snapX, snapY] = getGridPositionFromPixels(snapPoint.x + 1, snapPoint.y + 1);
|
||||||
|
|
||||||
@@ -312,8 +322,9 @@ export function highlightMeasurementNative(ray, startDistance, tokenShape=[{x: 0
|
|||||||
let {x, y} = ray.project(th);
|
let {x, y} = ray.project(th);
|
||||||
let [x1h, y1h] = canvas.grid.grid.getGridPositionFromPixels(x, y);
|
let [x1h, y1h] = canvas.grid.grid.getGridPositionFromPixels(x, y);
|
||||||
let [xgh, ygh] = canvas.grid.grid.getPixelsFromGridPosition(x1h, y1h);
|
let [xgh, ygh] = canvas.grid.grid.getPixelsFromGridPosition(x1h, y1h);
|
||||||
const subDistance = canvas.grid.measureDistances([{ray: new Ray(ray.A, {x: xgh, y: ygh})}], {gridSpaces: true})[0]
|
const pathUntilSpace = previousSegments.concat([{ray: new Ray(ray.A, {x: xgh, y: ygh})}]);
|
||||||
const color = this.dragRulerGetColorForDistance(startDistance + subDistance);
|
const distance = sum(canvas.grid.measureDistances(pathUntilSpace, {gridSpaces: true}));
|
||||||
|
const color = this.dragRulerGetColorForDistance(distance);
|
||||||
const snapPoint = getSnapPointForToken(...canvas.grid.getTopLeft(x, y), this.draggedEntity);
|
const snapPoint = getSnapPointForToken(...canvas.grid.getTopLeft(x, y), this.draggedEntity);
|
||||||
const [snapX, snapY] = getGridPositionFromPixels(snapPoint.x + 1, snapPoint.y + 1);
|
const [snapX, snapY] = getGridPositionFromPixels(snapPoint.x + 1, snapPoint.y + 1);
|
||||||
highlightTokenShape.call(this, {x: snapX, y: snapY}, tokenShape, color, alpha);
|
highlightTokenShape.call(this, {x: snapX, y: snapY}, tokenShape, color, alpha);
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import {settingsKey} from "./settings.js";
|
||||||
|
import {getMeasurePosition, setSnapParameterOnOptions} from "./util.js";
|
||||||
|
|
||||||
|
export let disableSnap = false;
|
||||||
|
export let moveWithoutAnimation = false;
|
||||||
|
|
||||||
|
export function registerKeybindings() {
|
||||||
|
game.keybindings.register(settingsKey, "cancelDrag", {
|
||||||
|
name: "drag-ruler.keybindings.cancelDrag",
|
||||||
|
onDown: cancelDrag,
|
||||||
|
uneditable: [{
|
||||||
|
key: "Escape",
|
||||||
|
}],
|
||||||
|
precedence: -1,
|
||||||
|
});
|
||||||
|
|
||||||
|
game.keybindings.register(settingsKey, "createWaypoint", {
|
||||||
|
name: "drag-ruler.keybindings.createWaypoint",
|
||||||
|
onDown: handleCreateWaypoint,
|
||||||
|
editable: [{
|
||||||
|
key: "Space"
|
||||||
|
}],
|
||||||
|
precedence: -1,
|
||||||
|
});
|
||||||
|
|
||||||
|
game.keybindings.register(settingsKey, "deleteWaypoint", {
|
||||||
|
name: "drag-ruler.keybindings.deleteWaypoint",
|
||||||
|
onDown: handleDeleteWaypoint,
|
||||||
|
precedence: -1,
|
||||||
|
});
|
||||||
|
|
||||||
|
game.keybindings.register(settingsKey, "disableSnap", {
|
||||||
|
name: "drag-ruler.keybindings.disableSnap.name",
|
||||||
|
hint: "drag-ruler.keybindings.disableSnap.hint",
|
||||||
|
onDown: handleDisableSnap,
|
||||||
|
onUp: handleDisableSnap,
|
||||||
|
editable: [{
|
||||||
|
key: "ShiftLeft",
|
||||||
|
}],
|
||||||
|
precedence: -1,
|
||||||
|
});
|
||||||
|
|
||||||
|
game.keybindings.register(settingsKey, "moveWithoutAnimation", {
|
||||||
|
name: "drag-ruler.keybindings.moveWithoutAnimation.name",
|
||||||
|
hint: "drag-ruler.keybindings.moveWithoutAnimation.hint",
|
||||||
|
onDown: handleMoveWithoutAnimation,
|
||||||
|
onUp: handleMoveWithoutAnimation,
|
||||||
|
editable: [{
|
||||||
|
key: "AltLeft",
|
||||||
|
}],
|
||||||
|
precedence: -1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDeleteWaypoint() {
|
||||||
|
const ruler = canvas.controls.ruler;
|
||||||
|
if (!ruler?.draggedEntity)
|
||||||
|
return false;
|
||||||
|
ruler.dragRulerDeleteWaypoint();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCreateWaypoint() {
|
||||||
|
const ruler = canvas.controls.ruler;
|
||||||
|
// .draggedEntity is used here because .isDragRuler only returns true once the ruler started measuring
|
||||||
|
// Ruler can end up being undefined here if no canvas is active
|
||||||
|
if (!ruler?.draggedEntity)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
let options = {};
|
||||||
|
setSnapParameterOnOptions(ruler, options);
|
||||||
|
|
||||||
|
if (ruler._state === Ruler.STATES.INACTIVE) {
|
||||||
|
ruler.dragRulerStart(options);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ruler.dragRulerAddWaypoint(getMeasurePosition(), options);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelDrag() {
|
||||||
|
const ruler = canvas.controls.ruler;
|
||||||
|
if (!ruler?.draggedEntity)
|
||||||
|
return false;
|
||||||
|
ruler.dragRulerAbortDrag();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDisableSnap(event) {
|
||||||
|
disableSnap = !event.up;
|
||||||
|
|
||||||
|
const ruler = canvas.controls.ruler;
|
||||||
|
if (!ruler?.isDragRuler)
|
||||||
|
return false;
|
||||||
|
if (ruler._state !== Ruler.STATES.MEASURING)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ruler.measure(getMeasurePosition(), {snap: !disableSnap});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleMoveWithoutAnimation(event) {
|
||||||
|
moveWithoutAnimation = !event.up;
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright © 2021 fvtt-lib-wrapper Rui Pinheiro
|
||||||
|
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// A shim for the libWrapper library
|
||||||
|
export let libWrapper = undefined;
|
||||||
|
|
||||||
|
export const VERSIONS = [1,11,0];
|
||||||
|
export const TGT_SPLIT_RE = new RegExp("([^.[]+|\\[('([^'\\\\]|\\\\.)+?'|\"([^\"\\\\]|\\\\.)+?\")\\])", 'g');
|
||||||
|
export const TGT_CLEANUP_RE = new RegExp("(^\\['|'\\]$|^\\[\"|\"\\]$)", 'g');
|
||||||
|
|
||||||
|
// Main shim code
|
||||||
|
Hooks.once('init', () => {
|
||||||
|
// Check if the real module is already loaded - if so, use it
|
||||||
|
if(globalThis.libWrapper && !(globalThis.libWrapper.is_fallback ?? true)) {
|
||||||
|
libWrapper = globalThis.libWrapper;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback implementation
|
||||||
|
libWrapper = class {
|
||||||
|
static get is_fallback() { return true };
|
||||||
|
|
||||||
|
static get WRAPPER() { return 'WRAPPER' };
|
||||||
|
static get MIXED() { return 'MIXED' };
|
||||||
|
static get OVERRIDE() { return 'OVERRIDE' };
|
||||||
|
|
||||||
|
static register(package_id, target, fn, type="MIXED", {chain=undefined}={}) {
|
||||||
|
const is_setter = target.endsWith('#set');
|
||||||
|
target = !is_setter ? target : target.slice(0, -4);
|
||||||
|
const split = target.match(TGT_SPLIT_RE).map((x)=>x.replace(/\\(.)/g, '$1').replace(TGT_CLEANUP_RE,''));
|
||||||
|
const root_nm = split.splice(0,1)[0];
|
||||||
|
|
||||||
|
let obj, fn_name;
|
||||||
|
if(split.length == 0) {
|
||||||
|
obj = globalThis;
|
||||||
|
fn_name = root_nm;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const _eval = eval;
|
||||||
|
fn_name = split.pop();
|
||||||
|
obj = split.reduce((x,y)=>x[y], globalThis[root_nm] ?? _eval(root_nm));
|
||||||
|
}
|
||||||
|
|
||||||
|
let iObj = obj;
|
||||||
|
let descriptor = null;
|
||||||
|
while(iObj) {
|
||||||
|
descriptor = Object.getOwnPropertyDescriptor(iObj, fn_name);
|
||||||
|
if(descriptor) break;
|
||||||
|
iObj = Object.getPrototypeOf(iObj);
|
||||||
|
}
|
||||||
|
if(!descriptor || descriptor?.configurable === false) throw `libWrapper Shim: '${target}' does not exist, could not be found, or has a non-configurable descriptor.`;
|
||||||
|
|
||||||
|
let original = null;
|
||||||
|
const wrapper = (chain ?? (type.toUpperCase?.() != 'OVERRIDE' && type != 3)) ? function() { return fn.call(this, original.bind(this), ...arguments); } : function() { return fn.apply(this, arguments); };
|
||||||
|
|
||||||
|
if(!is_setter) {
|
||||||
|
if(descriptor.value) {
|
||||||
|
original = descriptor.value;
|
||||||
|
descriptor.value = wrapper;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
original = descriptor.get;
|
||||||
|
descriptor.get = wrapper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(!descriptor.set) throw `libWrapper Shim: '${target}' does not have a setter`;
|
||||||
|
original = descriptor.set;
|
||||||
|
descriptor.set = wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
descriptor.configurable = true;
|
||||||
|
Object.defineProperty(obj, fn_name, descriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
+117
-145
@@ -1,25 +1,27 @@
|
|||||||
"use strict"
|
"use strict"
|
||||||
|
|
||||||
import {currentSpeedProvider, getColorForDistanceAndToken, getMovedDistanceFromToken, initApi, registerModule, registerSystem} from "./api.js";
|
import {getColorForDistanceAndToken, getMovedDistanceFromToken, getRangesFromSpeedProvider, initApi, registerModule, registerSystem} from "./api.js";
|
||||||
import {checkDependencies, getHexSizeSupportTokenGridCenter} from "./compatibility.js";
|
import {checkDependencies, getHexSizeSupportTokenGridCenter} from "./compatibility.js";
|
||||||
import {moveEntities, onMouseMove} from "./foundry_imports.js"
|
import {moveEntities, onMouseMove} from "./foundry_imports.js"
|
||||||
|
import {disableSnap, registerKeybindings} from "./keybindings.js";
|
||||||
|
import {libWrapper} from "./libwrapper_shim.js";
|
||||||
import {performMigrations} from "./migration.js"
|
import {performMigrations} from "./migration.js"
|
||||||
import {DragRulerRuler} from "./ruler.js";
|
import {removeLastHistoryEntryIfAt, resetMovementHistory} from "./movement_tracking.js";
|
||||||
import {getMovementHistory, removeLastHistoryEntryIfAt, resetMovementHistory} from "./movement_tracking.js";
|
import {extendRuler} from "./ruler.js";
|
||||||
import {registerSettings, settingsKey} from "./settings.js"
|
import {registerSettings, RightClickAction, settingsKey} from "./settings.js"
|
||||||
import {recalculate} from "./socket.js";
|
import {recalculate} from "./socket.js";
|
||||||
import {SpeedProvider} from "./speed_provider.js"
|
import {SpeedProvider} from "./speed_provider.js"
|
||||||
import {isClose, setSnapParameterOnOptions} from "./util.js";
|
import {setSnapParameterOnOptions} from "./util.js";
|
||||||
|
|
||||||
Hooks.once("init", () => {
|
Hooks.once("init", () => {
|
||||||
registerSettings()
|
registerSettings()
|
||||||
|
registerKeybindings()
|
||||||
initApi()
|
initApi()
|
||||||
hookDragHandlers(Token);
|
hookDragHandlers(Token);
|
||||||
hookDragHandlers(MeasuredTemplate);
|
hookDragHandlers(MeasuredTemplate);
|
||||||
hookKeyboardManagerFunctions()
|
libWrapper.register("drag-ruler", "TokenLayer.prototype.undoHistory", tokenLayerUndoHistory, "WRAPPER");
|
||||||
hookLayerFunctions();
|
|
||||||
|
|
||||||
Ruler = DragRulerRuler;
|
extendRuler();
|
||||||
|
|
||||||
window.dragRuler = {
|
window.dragRuler = {
|
||||||
getColorForDistanceAndToken,
|
getColorForDistanceAndToken,
|
||||||
@@ -57,48 +59,28 @@ Hooks.on("getCombatTrackerEntryContext", function (html, menu) {
|
|||||||
menu.splice(1, 0, entry);
|
menu.splice(1, 0, entry);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function forwardIfUnahndled(newFn) {
|
||||||
|
return function(oldFn, ...args) {
|
||||||
|
const eventHandled = newFn(...args);
|
||||||
|
if (!eventHandled)
|
||||||
|
oldFn(...args);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function hookDragHandlers(entityType) {
|
function hookDragHandlers(entityType) {
|
||||||
const originalDragLeftStartHandler = entityType.prototype._onDragLeftStart
|
const entityName = entityType.name
|
||||||
entityType.prototype._onDragLeftStart = function(event) {
|
libWrapper.register("drag-ruler", `${entityName}.prototype._onDragLeftStart`, onEntityLeftDragStart, "WRAPPER");
|
||||||
originalDragLeftStartHandler.call(this, event)
|
if (entityType === Token)
|
||||||
onEntityLeftDragStart.call(this, event)
|
libWrapper.register("drag-ruler", `${entityName}.prototype._onDragLeftMove`, onEntityLeftDragMoveSnap, "WRAPPER");
|
||||||
|
else
|
||||||
|
libWrapper.register("drag-ruler", `${entityName}.prototype._onDragLeftMove`, onEntityLeftDragMove, "WRAPPER");
|
||||||
|
libWrapper.register("drag-ruler", `${entityName}.prototype._onDragLeftDrop`, forwardIfUnahndled(onEntityDragLeftDrop), "MIXED");
|
||||||
|
libWrapper.register("drag-ruler", `${entityName}.prototype._onDragLeftCancel`, forwardIfUnahndled(onEntityDragLeftCancel), "MIXED");
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalDragLeftMoveHandler = entityType.prototype._onDragLeftMove
|
async function tokenLayerUndoHistory(wrapped) {
|
||||||
entityType.prototype._onDragLeftMove = function (event) {
|
|
||||||
originalDragLeftMoveHandler.call(this, event)
|
|
||||||
onEntityLeftDragMove.call(this, event)
|
|
||||||
}
|
|
||||||
|
|
||||||
const originalDragLeftDropHandler = entityType.prototype._onDragLeftDrop
|
|
||||||
entityType.prototype._onDragLeftDrop = function (event) {
|
|
||||||
const eventHandled = onEntityDragLeftDrop.call(this, event)
|
|
||||||
if (!eventHandled)
|
|
||||||
originalDragLeftDropHandler.call(this, event)
|
|
||||||
}
|
|
||||||
|
|
||||||
const originalDragLeftCancelHandler = entityType.prototype._onDragLeftCancel
|
|
||||||
entityType.prototype._onDragLeftCancel = function (event) {
|
|
||||||
const eventHandled = onEntityDragLeftCancel.call(this, event)
|
|
||||||
if (!eventHandled)
|
|
||||||
originalDragLeftCancelHandler.call(this, event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function hookKeyboardManagerFunctions() {
|
|
||||||
const originalHandleKeys = KeyboardManager.prototype._handleKeys
|
|
||||||
KeyboardManager.prototype._handleKeys = function (event, key, up) {
|
|
||||||
const eventHandled = handleKeys.call(this, event, key, up)
|
|
||||||
if (!eventHandled)
|
|
||||||
originalHandleKeys.call(this, event, key, up)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function hookLayerFunctions() {
|
|
||||||
const originalTokenLayerUndoHistory = TokenLayer.prototype.undoHistory;
|
|
||||||
TokenLayer.prototype.undoHistory = function () {
|
|
||||||
const historyEntry = this.history[this.history.length - 1];
|
const historyEntry = this.history[this.history.length - 1];
|
||||||
return originalTokenLayerUndoHistory.call(this).then((returnValue) => {
|
const returnValue = await wrapped();
|
||||||
if (historyEntry.type === "update") {
|
if (historyEntry.type === "update") {
|
||||||
for (const entry of historyEntry.data) {
|
for (const entry of historyEntry.data) {
|
||||||
const token = canvas.tokens.get(entry._id);
|
const token = canvas.tokens.get(entry._id);
|
||||||
@@ -106,78 +88,10 @@ function hookLayerFunctions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleKeys(event, key, up) {
|
function onEntityLeftDragStart(wrapped, event) {
|
||||||
if (event.repeat || this.hasFocus)
|
wrapped(event);
|
||||||
return false
|
|
||||||
|
|
||||||
const lowercaseKey = key.toLowerCase();
|
|
||||||
|
|
||||||
if (lowercaseKey === "x") return onKeyX(up)
|
|
||||||
if (lowercaseKey === "shift") return onKeyShift(up)
|
|
||||||
if (lowercaseKey === "space") return onKeySpace(up);
|
|
||||||
if (lowercaseKey === "escape") return onKeyEscape(up);
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
function onKeyX(up) {
|
|
||||||
if (up)
|
|
||||||
return false
|
|
||||||
const ruler = canvas.controls.ruler;
|
|
||||||
if (!ruler.isDragRuler)
|
|
||||||
return false
|
|
||||||
|
|
||||||
ruler.dragRulerDeleteWaypoint();
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
function onKeyShift(up) {
|
|
||||||
const ruler = canvas.controls.ruler
|
|
||||||
if (!ruler.isDragRuler)
|
|
||||||
return false
|
|
||||||
if (ruler._state !== Ruler.STATES.MEASURING)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const mousePosition = canvas.app.renderer.plugins.interaction.mouse.getLocalPosition(canvas.tokens)
|
|
||||||
const rulerOffset = ruler.rulerOffset
|
|
||||||
const measurePosition = {x: mousePosition.x + rulerOffset.x, y: mousePosition.y + rulerOffset.y}
|
|
||||||
ruler.measure(measurePosition, {snap: up})
|
|
||||||
}
|
|
||||||
|
|
||||||
function onKeySpace(up) {
|
|
||||||
const ruler = canvas.controls.ruler;
|
|
||||||
if (!ruler.draggedEntity)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (ruler._state !== Ruler.STATES.INACTIVE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const swapSpacebarRightClick = game.settings.get(settingsKey, "swapSpacebarRightClick");
|
|
||||||
let options = {};
|
|
||||||
setSnapParameterOnOptions(ruler, options);
|
|
||||||
|
|
||||||
if (!up) {
|
|
||||||
if (swapSpacebarRightClick)
|
|
||||||
ruler.dragRulerAbortDrag();
|
|
||||||
else
|
|
||||||
startDragRuler.call(ruler.draggedEntity, options);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function onKeyEscape(up) {
|
|
||||||
const ruler = canvas.controls.ruler;
|
|
||||||
if (!ruler.draggedEntity)
|
|
||||||
return false;
|
|
||||||
if (!up)
|
|
||||||
ruler.dragRulerAbortDrag();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function onEntityLeftDragStart(event) {
|
|
||||||
const isToken = this instanceof Token;
|
const isToken = this instanceof Token;
|
||||||
const ruler = canvas.controls.ruler
|
const ruler = canvas.controls.ruler
|
||||||
ruler.draggedEntity = this;
|
ruler.draggedEntity = this;
|
||||||
@@ -190,32 +104,17 @@ function onEntityLeftDragStart(event) {
|
|||||||
if (game.settings.get(settingsKey, "autoStartMeasurement")) {
|
if (game.settings.get(settingsKey, "autoStartMeasurement")) {
|
||||||
let options = {};
|
let options = {};
|
||||||
setSnapParameterOnOptions(ruler, options);
|
setSnapParameterOnOptions(ruler, options);
|
||||||
startDragRuler.call(this, options, false);
|
ruler.dragRulerStart(options, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function startDragRuler(options, measureImmediately=true) {
|
function onEntityLeftDragMoveSnap(wrapped, event) {
|
||||||
const isToken = this instanceof Token;
|
applyGridlessSnapping.call(this, event);
|
||||||
if (isToken && !currentSpeedProvider.usesRuler(this))
|
onEntityLeftDragMove.call(this, wrapped, event);
|
||||||
return;
|
|
||||||
const ruler = canvas.controls.ruler;
|
|
||||||
ruler.clear();
|
|
||||||
ruler._state = Ruler.STATES.STARTING;
|
|
||||||
let entityCenter;
|
|
||||||
if (isToken && canvas.grid.isHex && game.modules.get("hex-size-support")?.active && CONFIG.hexSizeSupport.getAltSnappingFlag(this))
|
|
||||||
entityCenter = getHexSizeSupportTokenGridCenter(this);
|
|
||||||
else
|
|
||||||
entityCenter = this.center;
|
|
||||||
if (isToken && game.settings.get(settingsKey, "enableMovementHistory"))
|
|
||||||
ruler.dragRulerAddWaypointHistory(getMovementHistory(this));
|
|
||||||
ruler.dragRulerAddWaypoint(entityCenter, {snap: false});
|
|
||||||
const mousePosition = canvas.app.renderer.plugins.interaction.mouse.getLocalPosition(canvas.tokens);
|
|
||||||
const destination = {x: mousePosition.x + ruler.rulerOffset.x, y: mousePosition.y + ruler.rulerOffset.y};
|
|
||||||
if (measureImmediately)
|
|
||||||
ruler.measure(destination, options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onEntityLeftDragMove(event) {
|
function onEntityLeftDragMove(wrapped, event) {
|
||||||
|
wrapped(event);
|
||||||
const ruler = canvas.controls.ruler
|
const ruler = canvas.controls.ruler
|
||||||
if (ruler.isDragRuler)
|
if (ruler.isDragRuler)
|
||||||
onMouseMove.call(ruler, event)
|
onMouseMove.call(ruler, event)
|
||||||
@@ -244,24 +143,97 @@ function onEntityDragLeftCancel(event) {
|
|||||||
if (!ruler.draggedEntity || ruler._state === Ruler.STATES.MOVING)
|
if (!ruler.draggedEntity || ruler._state === Ruler.STATES.MOVING)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
const swapSpacebarRightClick = game.settings.get(settingsKey, "swapSpacebarRightClick");
|
const rightClickAction = game.settings.get(settingsKey, "rightClickAction");
|
||||||
let options = {};
|
let options = {};
|
||||||
setSnapParameterOnOptions(ruler, options);
|
setSnapParameterOnOptions(ruler, options);
|
||||||
|
|
||||||
if (ruler._state === Ruler.STATES.INACTIVE) {
|
if (ruler._state === Ruler.STATES.INACTIVE) {
|
||||||
if (!swapSpacebarRightClick)
|
if (rightClickAction !== RightClickAction.CREATE_WAYPOINT)
|
||||||
return false;
|
return false;
|
||||||
startDragRuler.call(this, options);
|
ruler.dragRulerStart(options);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
else if (ruler._state === Ruler.STATES.MEASURING) {
|
else if (ruler._state === Ruler.STATES.MEASURING) {
|
||||||
if (!swapSpacebarRightClick) {
|
switch (rightClickAction) {
|
||||||
ruler.dragRulerDeleteWaypoint(event, options);
|
case RightClickAction.CREATE_WAYPOINT:
|
||||||
}
|
|
||||||
else {
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
ruler.dragRulerAddWaypoint(ruler.destination, options);
|
ruler.dragRulerAddWaypoint(ruler.destination, options);
|
||||||
|
break;
|
||||||
|
case RightClickAction.DELETE_WAYPOINT:
|
||||||
|
ruler.dragRulerDeleteWaypoint(event, options);
|
||||||
|
break;
|
||||||
|
case RightClickAction.ABORT_DRAG:
|
||||||
|
ruler.dragRulerAbortDrag();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyGridlessSnapping(event) {
|
||||||
|
const ruler = canvas.controls.ruler;
|
||||||
|
if (!game.settings.get(settingsKey, "useGridlessRaster"))
|
||||||
|
return;
|
||||||
|
if (!ruler.isDragRuler)
|
||||||
|
return;
|
||||||
|
if (disableSnap)
|
||||||
|
return;
|
||||||
|
if (canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const rasterWidth = 35 / canvas.stage.scale.x;
|
||||||
|
const tokenX = event.data.destination.x;
|
||||||
|
const tokenY = event.data.destination.y;
|
||||||
|
const destination = {x: tokenX + ruler.rulerOffset.x, y: tokenY + ruler.rulerOffset.y};
|
||||||
|
const ranges = getRangesFromSpeedProvider(ruler.draggedEntity);
|
||||||
|
|
||||||
|
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active;
|
||||||
|
if (terrainRulerAvailable) {
|
||||||
|
const segments = Ruler.dragRulerGetRaysFromWaypoints(ruler.waypoints, destination).map(ray => {return {ray}});
|
||||||
|
const pinpointDistances = new Map();
|
||||||
|
for (const range of ranges) {
|
||||||
|
pinpointDistances.set(range.range, null);
|
||||||
|
}
|
||||||
|
terrainRuler.measureDistances(segments, {pinpointDistances});
|
||||||
|
const targetDistance = Array.from(pinpointDistances.entries())
|
||||||
|
.filter(([_key, val]) => val)
|
||||||
|
.reduce((value, current) => value[0] > current[0] ? value : current, [0, null]);
|
||||||
|
const rasterLocation = targetDistance[1];
|
||||||
|
if (rasterLocation) {
|
||||||
|
const deltaX = destination.x - rasterLocation.x;
|
||||||
|
const deltaY = destination.y - rasterLocation.y;
|
||||||
|
const rasterDistance = Math.hypot(deltaX, deltaY);
|
||||||
|
if (rasterDistance < rasterWidth) {
|
||||||
|
event.data.destination.x = rasterLocation.x - ruler.rulerOffset.x;
|
||||||
|
event.data.destination.y = rasterLocation.y - ruler.rulerOffset.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let waypointDistance = 0;
|
||||||
|
let origin = event.data.origin;
|
||||||
|
if (ruler.waypoints.length > 1) {
|
||||||
|
const segments = Ruler.dragRulerGetRaysFromWaypoints(ruler.waypoints, destination).map(ray => {return {ray}});
|
||||||
|
origin = segments.pop().ray.A;
|
||||||
|
waypointDistance = canvas.grid.measureDistances(segments).reduce((a, b) => a + b);
|
||||||
|
origin = {x: origin.x - ruler.rulerOffset.x, y: origin.y - ruler.rulerOffset.y};
|
||||||
|
}
|
||||||
|
|
||||||
|
const deltaX = tokenX - origin.x;
|
||||||
|
const deltaY = tokenY - origin.y;
|
||||||
|
const distance = Math.hypot(deltaX, deltaY);
|
||||||
|
// targetRange will be the largest range that's still smaller than distance
|
||||||
|
let targetDistance = ranges
|
||||||
|
.map(range => range.range)
|
||||||
|
.map(range => range - waypointDistance)
|
||||||
|
.map(range => range * canvas.dimensions.size / canvas.dimensions.distance)
|
||||||
|
.filter(range => range < distance)
|
||||||
|
.reduce((a, b) => Math.max(a, b), 0);
|
||||||
|
if (targetDistance) {
|
||||||
|
if (distance < targetDistance + rasterWidth) {
|
||||||
|
event.data.destination.x = origin.x + deltaX * targetDistance / distance;
|
||||||
|
event.data.destination.y = origin.y + deltaY * targetDistance / distance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-19
@@ -1,27 +1,43 @@
|
|||||||
import {settingsKey} from "./settings.js"
|
import {RightClickAction, settingsKey} from "./settings.js"
|
||||||
|
|
||||||
const currentDataVersion = "1.3.0"
|
const currentDataVersion = "1.10.0"
|
||||||
|
|
||||||
export function performMigrations() {
|
export async function performMigrations() {
|
||||||
if (!game.user.isGM)
|
if (game.user.isGM)
|
||||||
return
|
await performWorldMigraionts()
|
||||||
|
await performClientMigrations()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function performWorldMigraionts() {
|
||||||
|
let dataVersion = game.settings.get(settingsKey, "dataVersion");
|
||||||
|
|
||||||
|
if (dataVersion === currentDataVersion)
|
||||||
|
return;
|
||||||
|
|
||||||
let dataVersion = game.settings.get(settingsKey, "dataVersion")
|
|
||||||
if (dataVersion === "fresh install") {
|
if (dataVersion === "fresh install") {
|
||||||
// Migration from unnamed version. TODO Remove this in a future version
|
|
||||||
let speedAttribute = game.settings.storage.get("world").get(`${settingsKey}.speedAttribute`)
|
|
||||||
if (speedAttribute)
|
|
||||||
speedAttribute = speedAttribute.slice(1, speedAttribute.length - 1)
|
|
||||||
const speedAttributeDefault = game.settings.get(settingsKey, "speedProviders.native.setting.speedAttribute")
|
|
||||||
if (speedAttribute !== speedAttributeDefault)
|
|
||||||
game.settings.set(settingsKey, "speedProviders.native.setting.speedAttribute", speedAttribute)
|
|
||||||
|
|
||||||
let dashMultiplier = game.settings.storage.get("world").get(`${settingsKey}.dashMultiplier`)
|
|
||||||
const dashMultiplierDefault = game.settings.get(settingsKey, "speedProviders.native.setting.dashMultiplier")
|
|
||||||
if (dashMultiplier !== dashMultiplierDefault)
|
|
||||||
game.settings.set(settingsKey, "speedProviders.native.setting.dashMultiplier", dashMultiplier)
|
|
||||||
// End of unnamed version migration code
|
|
||||||
game.settings.set(settingsKey, "dataVersion", currentDataVersion)
|
game.settings.set(settingsKey, "dataVersion", currentDataVersion)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dataVersion === "1.3.0") {
|
||||||
|
dataVersion = "1.10.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
game.settings.set(settingsKey, "dataVersion", dataVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function performClientMigrations() {
|
||||||
|
let dataVersion = game.settings.get(settingsKey, "clientDataVersion");
|
||||||
|
|
||||||
|
if (dataVersion === "fresh install") {
|
||||||
|
// Start of migration from unnamed version (< 1.10.0). TODO Remove in a future version
|
||||||
|
const swapSpacebarRightClick = game.settings.storage.get("client").getItem(`${settingsKey}.swapSpacebarRightClick`);
|
||||||
|
if (swapSpacebarRightClick) {
|
||||||
|
game.settings.set(settingsKey, "rightClickAction", RightClickAction.CREATE_WAYPOINT);
|
||||||
|
await game.keybindings.set(settingsKey, "createWaypoint", []);
|
||||||
|
await game.keybindings.set(settingsKey, "deleteWaypoint", [{key: "Space"}]);
|
||||||
|
}
|
||||||
|
// End of migration from unnamed version
|
||||||
|
game.settings.set(settingsKey, "clientDataVersion", currentDataVersion)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,14 +49,14 @@ function calculateUpdate(combat, token, rays) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the passed waypoints to the combatant
|
// Add the passed waypoints to the combatant
|
||||||
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.active || canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS);
|
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active;
|
||||||
const dragRulerFlags = combatant.data.flags.dragRuler;
|
const dragRulerFlags = combatant.data.flags.dragRuler;
|
||||||
const waypoints = dragRulerFlags.passedWaypoints;
|
const waypoints = dragRulerFlags.passedWaypoints;
|
||||||
for (const ray of rays) {
|
for (const ray of rays) {
|
||||||
// Ignore rays that have the same start and end coordinates
|
// Ignore rays that have the same start and end coordinates
|
||||||
if (ray.A.x !== ray.B.x || ray.A.y !== ray.B.y) {
|
if (ray.A.x !== ray.B.x || ray.A.y !== ray.B.y) {
|
||||||
if (terrainRulerAvailable) {
|
if (terrainRulerAvailable) {
|
||||||
measureDistances([{ray}], token, getTokenShape(token), {terrainRulerInitialState: waypoints[waypoints.length - 1]?.dragRulerFinalState});
|
measureDistances([{ray}], token, getTokenShape(token), {terrainRulerInitialState: waypoints[waypoints.length - 1]?.dragRulerFinalState, enableTerrainRuler: terrainRulerAvailable});
|
||||||
ray.A.dragRulerVisitedSpaces = ray.terrainRulerVisitedSpaces;
|
ray.A.dragRulerVisitedSpaces = ray.terrainRulerVisitedSpaces;
|
||||||
ray.A.dragRulerFinalState = ray.terrainRulerFinalState;
|
ray.A.dragRulerFinalState = ray.terrainRulerFinalState;
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-15
@@ -1,10 +1,12 @@
|
|||||||
import {getColorForDistanceAndToken, getRangesFromSpeedProvider} from "./api.js";
|
import {currentSpeedProvider, getColorForDistanceAndToken, getRangesFromSpeedProvider} from "./api.js";
|
||||||
|
import {getHexSizeSupportTokenGridCenter} from "./compatibility.js";
|
||||||
import {cancelScheduledMeasurement, measure} from "./foundry_imports.js"
|
import {cancelScheduledMeasurement, measure} from "./foundry_imports.js"
|
||||||
import {getMovementHistory} from "./movement_tracking.js";
|
import {getMovementHistory} from "./movement_tracking.js";
|
||||||
import {settingsKey} from "./settings.js";
|
import {settingsKey} from "./settings.js";
|
||||||
import {getSnapPointForEntity, setSnapParameterOnOptions} from "./util.js";
|
import {getSnapPointForEntity} from "./util.js";
|
||||||
|
|
||||||
export class DragRulerRuler extends Ruler {
|
export function extendRuler() {
|
||||||
|
class DragRulerRuler extends Ruler {
|
||||||
// Functions below are overridden versions of functions in Ruler
|
// Functions below are overridden versions of functions in Ruler
|
||||||
constructor(user, {color=null}={}) {
|
constructor(user, {color=null}={}) {
|
||||||
super(user, {color});
|
super(user, {color});
|
||||||
@@ -21,19 +23,9 @@ export class DragRulerRuler extends Ruler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async moveToken(event) {
|
async moveToken(event) {
|
||||||
// This function is invoked by left clicking
|
// Disable moveToken if Drag Ruler is active
|
||||||
if (!this.isDragRuler)
|
if (!this.isDragRuler)
|
||||||
return await super.moveToken(event);
|
return await super.moveToken(event);
|
||||||
|
|
||||||
let options = {};
|
|
||||||
setSnapParameterOnOptions(this, options);
|
|
||||||
|
|
||||||
if (!game.settings.get(settingsKey, "swapSpacebarRightClick")) {
|
|
||||||
this.dragRulerAddWaypoint(this.destination, options);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.dragRulerDeleteWaypoint(event, options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
@@ -166,8 +158,34 @@ export class DragRulerRuler extends Ruler {
|
|||||||
if (!(this.draggedEntity.actor.data.type === "character" && game.settings.get(settingsKey, "alwaysShowSpeedForPCs")))
|
if (!(this.draggedEntity.actor.data.type === "character" && game.settings.get(settingsKey, "alwaysShowSpeedForPCs")))
|
||||||
return this.color;
|
return this.color;
|
||||||
}
|
}
|
||||||
|
distance = Math.round(distance * 100) / 100;
|
||||||
if (!this.dragRulerRanges)
|
if (!this.dragRulerRanges)
|
||||||
this.dragRulerRanges = getRangesFromSpeedProvider(this.draggedEntity);
|
this.dragRulerRanges = getRangesFromSpeedProvider(this.draggedEntity);
|
||||||
return getColorForDistanceAndToken(distance, this.draggedEntity, this.dragRulerRanges);
|
return getColorForDistanceAndToken(distance, this.draggedEntity, this.dragRulerRanges) ?? this.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
dragRulerStart(options, measureImmediately=true) {
|
||||||
|
const entity = this.draggedEntity;
|
||||||
|
const isToken = entity instanceof Token;
|
||||||
|
if (isToken && !currentSpeedProvider.usesRuler(entity))
|
||||||
|
return;
|
||||||
|
const ruler = canvas.controls.ruler;
|
||||||
|
ruler.clear();
|
||||||
|
ruler._state = Ruler.STATES.STARTING;
|
||||||
|
let entityCenter;
|
||||||
|
if (isToken && canvas.grid.isHex && game.modules.get("hex-size-support")?.active && CONFIG.hexSizeSupport.getAltSnappingFlag(entity))
|
||||||
|
entityCenter = getHexSizeSupportTokenGridCenter(entity);
|
||||||
|
else
|
||||||
|
entityCenter = entity.center;
|
||||||
|
if (isToken && game.settings.get(settingsKey, "enableMovementHistory"))
|
||||||
|
ruler.dragRulerAddWaypointHistory(getMovementHistory(entity));
|
||||||
|
ruler.dragRulerAddWaypoint(entityCenter, {snap: false});
|
||||||
|
const mousePosition = canvas.app.renderer.plugins.interaction.mouse.getLocalPosition(canvas.tokens);
|
||||||
|
const destination = {x: mousePosition.x + ruler.rulerOffset.x, y: mousePosition.y + ruler.rulerOffset.y};
|
||||||
|
if (measureImmediately)
|
||||||
|
ruler.measure(destination, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ruler = DragRulerRuler;
|
||||||
|
}
|
||||||
|
|||||||
+31
-5
@@ -3,6 +3,12 @@ import {SpeedProvider} from "./speed_provider.js"
|
|||||||
|
|
||||||
export const settingsKey = "drag-ruler";
|
export const settingsKey = "drag-ruler";
|
||||||
|
|
||||||
|
export const RightClickAction = Object.freeze({
|
||||||
|
CREATE_WAYPOINT: 0,
|
||||||
|
DELETE_WAYPOINT: 1,
|
||||||
|
ABORT_DRAG:2,
|
||||||
|
});
|
||||||
|
|
||||||
export function registerSettings() {
|
export function registerSettings() {
|
||||||
game.settings.register(settingsKey, "dataVersion", {
|
game.settings.register(settingsKey, "dataVersion", {
|
||||||
scope: "world",
|
scope: "world",
|
||||||
@@ -11,6 +17,26 @@ export function registerSettings() {
|
|||||||
default: "fresh install"
|
default: "fresh install"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
game.settings.register(settingsKey, "clientDataVersion", {
|
||||||
|
scope: "client",
|
||||||
|
config: false,
|
||||||
|
type: String,
|
||||||
|
default: "fresh install"
|
||||||
|
});
|
||||||
|
|
||||||
|
game.settings.register(settingsKey, "rightClickAction", {
|
||||||
|
name: "drag-ruler.settings.rightClickAction.name",
|
||||||
|
hint: "drag-ruler.settings.rightClickAction.hint",
|
||||||
|
config: true,
|
||||||
|
type: Number,
|
||||||
|
default: RightClickAction.DELETE_WAYPOINT,
|
||||||
|
choices: {
|
||||||
|
0: "drag-ruler.settings.rightClickAction.choices.create",
|
||||||
|
1: "drag-ruler.settings.rightClickAction.choices.delete",
|
||||||
|
2: "drag-ruler.settings.rightClickAction.choices.cancel",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
game.settings.register(settingsKey, "autoStartMeasurement", {
|
game.settings.register(settingsKey, "autoStartMeasurement", {
|
||||||
name: "drag-ruler.settings.autoStartMeasurement.name",
|
name: "drag-ruler.settings.autoStartMeasurement.name",
|
||||||
hint: "drag-ruler.settings.autoStartMeasurement.hint",
|
hint: "drag-ruler.settings.autoStartMeasurement.hint",
|
||||||
@@ -20,14 +46,14 @@ export function registerSettings() {
|
|||||||
default: true,
|
default: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
game.settings.register(settingsKey, "swapSpacebarRightClick", {
|
game.settings.register(settingsKey, "useGridlessRaster", {
|
||||||
name: "drag-ruler.settings.swapSpacebarRightClick.name",
|
name: "drag-ruler.settings.useGridlessRaster.name",
|
||||||
hint: "drag-ruler.settings.swapSpacebarRightClick.hint",
|
hint: "drag-ruler.settings.useGridlessRaster.hint",
|
||||||
scope: "client",
|
scope: "client",
|
||||||
config: true,
|
config: true,
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: true,
|
||||||
})
|
});
|
||||||
|
|
||||||
game.settings.register(settingsKey, "alwaysShowSpeedForPCs", {
|
game.settings.register(settingsKey, "alwaysShowSpeedForPCs", {
|
||||||
name: "drag-ruler.settings.alwaysShowSpeedForPCs.name",
|
name: "drag-ruler.settings.alwaysShowSpeedForPCs.name",
|
||||||
|
|||||||
@@ -63,9 +63,9 @@ export class SpeedProvider {
|
|||||||
* (1 is regular cost, 2 costs double, 3 costs triple, ...)
|
* (1 is regular cost, 2 costs double, 3 costs triple, ...)
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* - options: An object used to configure TerrainLayer's cost calculation. Ex: If options.ignoreGrid is set to true, then Euclidean measurement can be forced on a gridded map.
|
* - options: An object used to configure Enhanced Terrain Layer's cost calculation. Ex: If options.ignoreGrid is set to true, then Euclidean measurement can be forced on a gridded map.
|
||||||
*
|
*
|
||||||
* This function is only called if the TerrainLayer and TerrainRuler modules are enabled.
|
* This function is only called if the Enhanced Terrain Layer and Terrain Ruler modules are enabled.
|
||||||
*
|
*
|
||||||
* Implementing this method is optional and only needs to be done if you want to provide a custom cost function (for example to allow tokens to ignore difficult terrain)
|
* Implementing this method is optional and only needs to be done if you want to provide a custom cost function (for example to allow tokens to ignore difficult terrain)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
export function getDefaultSpeedAttribute() {
|
export function getDefaultSpeedAttribute() {
|
||||||
switch (game.system.id) {
|
switch (game.system.id) {
|
||||||
case "CoC7":
|
case "CoC7":
|
||||||
|
|||||||
+65
-17
@@ -1,4 +1,5 @@
|
|||||||
import {getPixelsFromGridPosition} from "./foundry_fixes.js"
|
import {getPixelsFromGridPosition} from "./foundry_fixes.js"
|
||||||
|
import { disableSnap } from "./keybindings.js";
|
||||||
|
|
||||||
export function* zip(it1, it2) {
|
export function* zip(it1, it2) {
|
||||||
for (let i = 0;i < Math.min(it1.length, it2.length);i++) {
|
for (let i = 0;i < Math.min(it1.length, it2.length);i++) {
|
||||||
@@ -6,11 +7,24 @@ export function* zip(it1, it2) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function* enumeratedZip(it1, it2) {
|
||||||
|
let i = 0;
|
||||||
|
for (const [v1, v2] of zip(it1, it2)) {
|
||||||
|
yield [i, v1, v2];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sum(arr) {
|
||||||
|
return arr.reduce((a, b) => a + b, 0);
|
||||||
|
}
|
||||||
|
|
||||||
export function getSnapPointForToken(x, y, token) {
|
export function getSnapPointForToken(x, y, token) {
|
||||||
if (canvas.grid.type === CONST.GRID_TYPES.GRIDLESS) {
|
if (canvas.grid.type === CONST.GRID_TYPES.GRIDLESS) {
|
||||||
return new PIXI.Point(x, y);
|
return new PIXI.Point(x, y);
|
||||||
}
|
}
|
||||||
if (canvas.grid.isHex && game.modules.get("hex-size-support")?.active && CONFIG.hexSizeSupport.getAltSnappingFlag(token)) {
|
if (canvas.grid.isHex) {
|
||||||
|
if (game.modules.get("hex-size-support")?.active && CONFIG.hexSizeSupport.getAltSnappingFlag(token)) {
|
||||||
if (token.document.getFlag("hex-size-support", "borderSize") % 2 === 0) {
|
if (token.document.getFlag("hex-size-support", "borderSize") % 2 === 0) {
|
||||||
const snapPoint = CONFIG.hexSizeSupport.findVertexSnapPoint(x, y, token, canvas.grid.grid)
|
const snapPoint = CONFIG.hexSizeSupport.findVertexSnapPoint(x, y, token, canvas.grid.grid)
|
||||||
return new PIXI.Point(snapPoint.x, snapPoint.y)
|
return new PIXI.Point(snapPoint.x, snapPoint.y)
|
||||||
@@ -19,24 +33,51 @@ export function getSnapPointForToken(x, y, token) {
|
|||||||
return new PIXI.Point(...canvas.grid.getCenter(x, y))
|
return new PIXI.Point(...canvas.grid.getCenter(x, y))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Tiny tokens can snap to the cells corners
|
else {
|
||||||
if (!canvas.grid.isHex && token.data.width <= 0.5) {
|
return new PIXI.Point(...canvas.grid.getCenter(x, y));
|
||||||
const [topLeftX, topLeftY] = canvas.grid.getTopLeft(x, y);
|
|
||||||
const offsetX = x - topLeftX;
|
|
||||||
const offsetY = y - topLeftY;
|
|
||||||
const subGridWidth = Math.floor(canvas.grid.w / 2);
|
|
||||||
const subGridHeight = Math.floor(canvas.grid.h / 2);
|
|
||||||
const subGridPosX = Math.floor(offsetX / subGridWidth);
|
|
||||||
const subGridPosY = Math.floor(offsetY / subGridHeight);
|
|
||||||
return new PIXI.Point(topLeftX + (subGridPosX + 0.5) * subGridWidth, topLeftY + (subGridPosY + 0.5) * subGridHeight);
|
|
||||||
}
|
}
|
||||||
// Hex tokens, tokens with odd multipliers (1x1, 3x3, ...) and tokens smaller than 1x1 but bigger than 0.5x0.5 snap to the center of the grid cell
|
}
|
||||||
if (canvas.grid.isHex || Math.round(token.data.width) % 2 === 1 || token.data.width < 1) {
|
|
||||||
return new PIXI.Point(...canvas.grid.getCenter(x, y))
|
const [topLeftX, topLeftY] = canvas.grid.getTopLeft(x, y);
|
||||||
|
let cellX, cellY;
|
||||||
|
if (token.data.width % 2 === 0)
|
||||||
|
cellX = x - canvas.grid.h / 2;
|
||||||
|
else
|
||||||
|
cellX = x;
|
||||||
|
if (token.data.height % 2 === 0)
|
||||||
|
cellY = y - canvas.grid.h / 2;
|
||||||
|
else
|
||||||
|
cellY = y;
|
||||||
|
const [centerX, centerY] = canvas.grid.getCenter(cellX, cellY);
|
||||||
|
let snapX, snapY;
|
||||||
|
// Tiny tokens can snap to the cells corners
|
||||||
|
if (token.data.width <= 0.5) {
|
||||||
|
const offsetX = x - topLeftX;
|
||||||
|
const subGridWidth = Math.floor(canvas.grid.w / 2);
|
||||||
|
const subGridPosX = Math.floor(offsetX / subGridWidth);
|
||||||
|
snapX = topLeftX + (subGridPosX + 0.5) * subGridWidth;
|
||||||
|
}
|
||||||
|
// Tokens with odd multipliers (1x1, 3x3, ...) and tokens smaller than 1x1 but bigger than 0.5x0.5 snap to the center of the grid cell
|
||||||
|
else if (Math.round(token.data.width) % 2 === 1 || token.data.width < 1) {
|
||||||
|
snapX = centerX;
|
||||||
}
|
}
|
||||||
// All remaining tokens (those with even or fractional multipliers on square grids) snap to the intersection points of the grid
|
// All remaining tokens (those with even or fractional multipliers on square grids) snap to the intersection points of the grid
|
||||||
const [snappedX, snappedY] = canvas.grid.getCenter(x - canvas.grid.w / 2, y - canvas.grid.h / 2)
|
else {
|
||||||
return new PIXI.Point(snappedX + canvas.grid.w / 2, snappedY + canvas.grid.h / 2)
|
snapX = centerX + canvas.grid.w / 2;
|
||||||
|
}
|
||||||
|
if (token.data.height <= 0.5) {
|
||||||
|
const offsetY = y - topLeftY;
|
||||||
|
const subGridHeight = Math.floor(canvas.grid.h / 2);
|
||||||
|
const subGridPosY = Math.floor(offsetY / subGridHeight);
|
||||||
|
snapY = topLeftY + (subGridPosY + 0.5) * subGridHeight;
|
||||||
|
}
|
||||||
|
else if (Math.round(token.data.height) % 2 === 1 || token.data.height < 1) {
|
||||||
|
snapY = centerY;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
snapY = centerY + canvas.grid.h / 2;
|
||||||
|
}
|
||||||
|
return new PIXI.Point(snapX, snapY);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSnapPointForMeasuredTemplate(x, y) {
|
export function getSnapPointForMeasuredTemplate(x, y) {
|
||||||
@@ -207,10 +248,17 @@ export function setSnapParameterOnOptions(sourceObject, options) {
|
|||||||
sourceObject.snapOverride = undefined; // remove it to prevent any lingering data issues
|
sourceObject.snapOverride = undefined; // remove it to prevent any lingering data issues
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
options.snap = !game.keyboard._downKeys.has("Shift");
|
options.snap = !disableSnap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isClose(a, b, delta) {
|
export function isClose(a, b, delta) {
|
||||||
return Math.abs(a - b) <= delta;
|
return Math.abs(a - b) <= delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getMeasurePosition() {
|
||||||
|
const mousePosition = canvas.app.renderer.plugins.interaction.mouse.getLocalPosition(canvas.tokens);
|
||||||
|
const rulerOffset = canvas.controls.ruler.rulerOffset;
|
||||||
|
const measurePosition = {x: mousePosition.x + rulerOffset.x, y: mousePosition.y + rulerOffset.y};
|
||||||
|
return measurePosition;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user