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.

137 lines
5.1 KiB

1 year ago
  1. class AutomatedEvocationsCustomBindings extends FormApplication {
  2. constructor() {
  3. super();
  4. }
  5. static get defaultOptions() {
  6. return {
  7. ...super.defaultOptions,
  8. title: game.i18n.localize("AE.custombindings.bindingstitle"),
  9. id: "companionManager-custombindings",
  10. template: `modules/automated-evocations/templates/custombindings.hbs`,
  11. resizable: true,
  12. width: 300,
  13. height: window.innerHeight > 400 ? 400 : window.innerHeight - 100,
  14. dragDrop: [{ dragSelector: null, dropSelector: null }],
  15. };
  16. }
  17. getData() {
  18. return {
  19. customautospells: game.settings.get(AECONSTS.MN, "customautospells")
  20. }
  21. }
  22. activateListeners(html) {
  23. html.on("click", ".fa-trash", async (event) => {
  24. const binding = event.currentTarget.closest("li").dataset.binding;
  25. const customautospells = game.settings.get(AECONSTS.MN, "customautospells");
  26. delete customautospells[binding];
  27. await game.settings.set(AECONSTS.MN, "customautospells", customautospells);
  28. this.render(true);
  29. });
  30. html.on("click", ".fa-edit", async (event) => {
  31. const binding = event.currentTarget.closest("li").dataset.binding;
  32. new AutomatedEvocationsCustomBindingsConfig(binding).render(true);
  33. });
  34. html.on("click", ".add-binding", async (event) => {
  35. const binding = "New Binding";
  36. const customautospells = game.settings.get(AECONSTS.MN, "customautospells");
  37. customautospells[binding] = [];
  38. await game.settings.set(AECONSTS.MN, "customautospells", customautospells);
  39. this.render(true);
  40. });
  41. html.on("change submit", "input", async (event) => {
  42. const binding = event.currentTarget.closest("li").dataset.binding;
  43. const customautospells = game.settings.get(AECONSTS.MN, "customautospells");
  44. customautospells[event.currentTarget.value] = customautospells[binding];
  45. delete customautospells[binding];
  46. await game.settings.set(AECONSTS.MN, "customautospells", customautospells);
  47. this.render(true);
  48. });
  49. }
  50. }
  51. class AutomatedEvocationsCustomBindingsConfig extends FormApplication {
  52. constructor(binding) {
  53. super();
  54. this._binding = binding;
  55. }
  56. static get defaultOptions() {
  57. return {
  58. ...super.defaultOptions,
  59. title: game.i18n.localize("AE.custombindings.bindingtitle"),
  60. id: "companionManager-custombinding-config",
  61. template: `modules/automated-evocations/templates/custombindingconfig.hbs`,
  62. resizable: true,
  63. width: 300,
  64. height: window.innerHeight > 400 ? 400 : window.innerHeight - 100,
  65. dragDrop: [{ dragSelector: null, dropSelector: null }],
  66. };
  67. }
  68. getData() {
  69. const animations = {};
  70. for(let [key, value] of Object.entries(AECONSTS.animations)) {
  71. animations[key] = {};
  72. for(let a of value) {
  73. const aKey = a.key;
  74. animations[key][aKey] = a.name;
  75. }
  76. }
  77. return {
  78. binding: game.settings.get(AECONSTS.MN, "customautospells")[this._binding],
  79. animations
  80. }
  81. }
  82. activateListeners(html) {
  83. html.on("click", ".fa-trash", async (event) => {
  84. const binding = game.settings.get(AECONSTS.MN, "customautospells")[this._binding];
  85. const index = event.currentTarget.closest("li").dataset.index;
  86. binding.splice(index, 1);
  87. const newBindings = game.settings.get(AECONSTS.MN, "customautospells");
  88. newBindings[this._binding] = binding;
  89. await game.settings.set(AECONSTS.MN, "customautospells",newBindings);
  90. this.render(true);
  91. });
  92. html.on("click", ".add-binding", async (event) => {
  93. const binding = game.settings.get(AECONSTS.MN, "customautospells")[this._binding];
  94. binding.push({creature: "Creature Name" ,number: 1});
  95. const newBindings = game.settings.get(AECONSTS.MN, "customautospells");
  96. newBindings[this._binding] = binding;
  97. await game.settings.set(AECONSTS.MN, "customautospells", newBindings);
  98. this.render(true);
  99. });
  100. html.on("change submit", "input, select", async (event) => {
  101. this.saveData(true);
  102. });
  103. }
  104. async saveData(render = true) {
  105. const newBinding = [];
  106. for(let li of this.element.find("li")) {
  107. if(li.className === "add-binding") continue;
  108. const creature = li.querySelector("input[type=text]").value;
  109. const animation = li.querySelector("select").value;
  110. const number = parseInt(li.querySelector("input[type=number]").value);
  111. newBinding.push({creature, number, animation});
  112. }
  113. const newBindings = game.settings.get(AECONSTS.MN, "customautospells");
  114. newBindings[this._binding] = newBinding;
  115. await game.settings.set(AECONSTS.MN, "customautospells", newBindings);
  116. if(render) this.render(true);
  117. }
  118. async close() {
  119. await this.saveData(false);
  120. await super.close();
  121. Object.values(ui.windows).forEach((window) => {
  122. if (window instanceof AutomatedEvocationsCustomBindings) {
  123. window.render(true);
  124. }
  125. });
  126. }
  127. }