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.

87 lines
2.7 KiB

  1. export default class FlagsConfig extends FormApplication {
  2. constructor(obj) {
  3. super({}, {});
  4. if (obj instanceof Tile) {
  5. this.objectToFlag = obj.document;
  6. this.isTile = true;
  7. } else {
  8. this.objectToFlag = game.actors.get(obj.document.actorId) || obj.document;
  9. }
  10. }
  11. static get defaultOptions() {
  12. return mergeObject(super.defaultOptions, {
  13. id: 'token-variants-token-flags',
  14. classes: ['sheet'],
  15. template: 'modules/token-variants/templates/flagsConfig.html',
  16. resizable: true,
  17. minimizable: false,
  18. title: 'Flags',
  19. width: 500,
  20. });
  21. }
  22. async getData(options) {
  23. const data = super.getData(options);
  24. const popups = this.objectToFlag.getFlag('token-variants', 'popups');
  25. const disableNameSearch = this.objectToFlag.getFlag('token-variants', 'disableNameSearch');
  26. const directory = this.objectToFlag.getFlag('token-variants', 'directory') || {};
  27. return mergeObject(data, {
  28. popups: popups,
  29. popupsSetFlag: popups != null,
  30. disableNameSearch: disableNameSearch,
  31. disableNameSearchSetFlag: disableNameSearch != null,
  32. directory: directory.path,
  33. directorySource: directory.source,
  34. directorySetFlag: !isEmpty(directory),
  35. tile: this.isTile,
  36. });
  37. }
  38. /**
  39. * @param {JQuery} html
  40. */
  41. activateListeners(html) {
  42. super.activateListeners(html);
  43. html.find('.controlFlag').click((e) => {
  44. $(e.target).siblings('.flag').prop('disabled', !e.target.checked);
  45. });
  46. html.find('.directory-fp').click((event) => {
  47. new FilePicker({
  48. type: 'folder',
  49. activeSource: 'data',
  50. callback: (path, fp) => {
  51. html.find('[name="directory"]').val(fp.result.target);
  52. $(event.target)
  53. .closest('button')
  54. .attr('title', 'Directory: ' + fp.result.target);
  55. const sourceEl = html.find('[name="directorySource"]');
  56. if (fp.activeSource === 's3') {
  57. sourceEl.val(`s3:${fp.result.bucket}`);
  58. } else {
  59. sourceEl.val(fp.activeSource);
  60. }
  61. },
  62. }).render(true);
  63. });
  64. }
  65. /**
  66. * @param {Event} event
  67. * @param {Object} formData
  68. */
  69. async _updateObject(event, formData) {
  70. if ('directory' in formData) {
  71. formData.directory = { path: formData.directory, source: formData.directorySource };
  72. }
  73. ['popups', 'disableNameSearch', 'directory'].forEach((flag) => {
  74. if (flag in formData) {
  75. this.objectToFlag.setFlag('token-variants', flag, formData[flag]);
  76. } else {
  77. this.objectToFlag.unsetFlag('token-variants', flag);
  78. }
  79. });
  80. }
  81. }