All user data for FoundryVTT. Includes worlds, systems, modules, and any asset in the "foundryuserdata" directory. Does NOT include the FoundryVTT installation itself.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
3.2 KiB

1 year ago
1 year ago
1 year ago
  1. import {movementTracking} from "./movementFunctions.js"
  2. Hooks.once("init", () => {
  3. //Wait until the game is initialized, then register the settings created previously.
  4. game.settings.register("pf2e-dragruler", "offTurnMovement", {
  5. name: game.i18n.localize("pf2e-dragruler.settings.offTurnMovement.name"),
  6. hint: game.i18n.localize("pf2e-dragruler.settings.offTurnMovement.hint"),
  7. scope: "world",
  8. config: true,
  9. type: Boolean,
  10. default: false
  11. })
  12. });
  13. Hooks.once("dragRuler.ready", (SpeedProvider) => {
  14. class PF2eSpeedProvider extends SpeedProvider {
  15. //Registers colours for up to four movement actions so colours can be customized for them, and sets defaults
  16. get colors(){
  17. return [
  18. {id: "FirstAction", default: 0x3222C7},
  19. {id: "SecondAction", default: 0xFFEC07},
  20. {id: "ThirdAction", default: 0xC033E0},
  21. {id: "FourthAction", default: 0x1BCAD8}
  22. ]
  23. };
  24. // Get the distance for each movement interval to give to drag ruler
  25. getRanges(token){
  26. var numactions = 3; //Use the actionCount function to determine how many actions that token gets each round.
  27. var movement = movementTracking(token); //Use the movementTracking function to get how far each movement range should be.
  28. const ranges = []; //create blank array to store the ranges in.
  29. if (numactions > 0 && movement.A1 > 0){
  30. //Set the ranges for each of our four actions to be given to the drag ruler.
  31. ranges.push({range: movement.A1, color: "FirstAction"},{range: movement.A2, color: "SecondAction"}, { range: movement.A3, color: "ThirdAction"},{range: movement.A4, color: "FourthAction"});
  32. //Remove ranges from the function until only the ranges equal to the number of legal actions remain.
  33. for (var i = numactions, len=ranges.length; i<len; i++){
  34. ranges.pop();
  35. };
  36. } else {ranges.push({range: 0, color: "FirstAction"})}; //Since ranges is empty if you've got no actions add a range for the first action of 0.
  37. return ranges;
  38. };
  39. };
  40. // When dragruler is ready to go give it all the PF2 specific stuff
  41. dragRuler.registerModule("pf2e-dragruler", PF2eSpeedProvider) //register the speed provider so its selectable from the drag ruler configuration.
  42. });
  43. Hooks.on('updateCombat', () => {
  44. if(game.user.isGM && game.settings.get("drag-ruler", "enableMovementHistory") && game.settings.get("pf2e-dragruler", "offTurnMovement")){
  45. const combat = game.combats.active; //set the current combat
  46. if(combat?.turns.length > 0){
  47. const previousCombatant = combat.turns[(combat.turn - 1) < 0 ? (combat.turns.length - 1) : (combat.turn - 1)];
  48. const nextCombatant = combat.turns[combat.turn]; //find the next combatant
  49. if(nextCombatant?.flags?.dragRuler){
  50. dragRuler.resetMovementHistory(combat, nextCombatant._id); //if movement history exists, clears it for the next combatant prior to acting. Gives a clean slate for the new turn, important for clearing out off turn movement.
  51. };
  52. if(previousCombatant?.flags?.dragRuler){
  53. dragRuler.resetMovementHistory(combat, previousCombatant._id); //if movement history exists, clears it for the next combatant prior to acting. Gives a clean slate for the new turn, important for clearing out off turn movement.
  54. };
  55. };
  56. };
  57. });