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.

97 lines
2.8 KiB

  1. export default class EditScriptConfig extends FormApplication {
  2. constructor(script, callback) {
  3. super({}, {});
  4. this.script = script;
  5. this.callback = callback;
  6. }
  7. static get defaultOptions() {
  8. return mergeObject(super.defaultOptions, {
  9. id: 'token-variants-config-script-edit',
  10. classes: ['sheet'],
  11. template: 'modules/token-variants/templates/configScriptEdit.html',
  12. resizable: true,
  13. minimizable: false,
  14. title: 'Scripts',
  15. width: 640,
  16. height: 640,
  17. });
  18. }
  19. async getData(options) {
  20. const data = super.getData(options);
  21. const script = this.script ? this.script : {};
  22. data.hasScript = !isEmpty(script);
  23. data.onApply = script.onApply;
  24. data.onRemove = script.onRemove;
  25. data.macroOnApply = script.macroOnApply;
  26. data.macroOnRemove = script.macroOnRemove;
  27. data.tmfxPreset = script.tmfxPreset;
  28. data.tmfxActive = game.modules.get('tokenmagic')?.active;
  29. if (data.tmfxActive) {
  30. data.tmfxPresets = TokenMagic.getPresets().map((p) => p.name);
  31. }
  32. data.ceActive = game.modules.get('dfreds-convenient-effects')?.active;
  33. if (data.ceActive) {
  34. data.ceEffect = script.ceEffect ?? { apply: true, remove: true };
  35. data.ceEffects = game.dfreds.effects.all.map((ef) => ef.name);
  36. }
  37. data.macros = game.macros.map((m) => m.name);
  38. return data;
  39. }
  40. /**
  41. * @param {JQuery} html
  42. */
  43. activateListeners(html) {
  44. super.activateListeners(html);
  45. // Override 'Tab' key to insert spaces
  46. html.on('keydown', '.command textarea', function (e) {
  47. if (e.key === 'Tab' && !e.shiftKey) {
  48. e.preventDefault();
  49. var start = this.selectionStart;
  50. var end = this.selectionEnd;
  51. this.value = this.value.substring(0, start) + ' ' + this.value.substring(end);
  52. this.selectionStart = this.selectionEnd = start + 2;
  53. return false;
  54. }
  55. });
  56. html.find('.remove').click(this._onRemove.bind(this));
  57. }
  58. async _onRemove(event) {
  59. if (this.callback) this.callback(null);
  60. this.close();
  61. }
  62. /**
  63. * @param {Event} event
  64. * @param {Object} formData
  65. */
  66. async _updateObject(event, formData) {
  67. formData = expandObject(formData);
  68. ['onApply', 'onRemove', 'macroOnApply', 'macroOnRemove'].forEach((k) => {
  69. formData[k] = formData[k].trim();
  70. });
  71. if (formData.ceEffect?.name) formData.ceEffect.name = formData.ceEffect.name.trim();
  72. if (
  73. !formData.onApply &&
  74. !formData.onRemove &&
  75. !formData.tmfxPreset &&
  76. !formData.ceEffect.name &&
  77. !formData.macroOnApply &&
  78. !formData.macroOnRemove
  79. ) {
  80. if (this.callback) this.callback(null);
  81. } else {
  82. if (this.callback) this.callback(formData);
  83. }
  84. }
  85. }