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.

135 lines
4.2 KiB

  1. import { TVA_CONFIG, updateSettings } from '../scripts/settings.js';
  2. import { getFileName } from '../scripts/utils.js';
  3. import { showArtSelect } from '../token-variants.mjs';
  4. export default class MissingImageConfig extends FormApplication {
  5. constructor() {
  6. super({}, {});
  7. }
  8. static get defaultOptions() {
  9. return mergeObject(super.defaultOptions, {
  10. id: 'token-variants-missing-images',
  11. classes: ['sheet'],
  12. template: 'modules/token-variants/templates/missingImageConfig.html',
  13. resizable: true,
  14. minimizable: false,
  15. title: 'Define Missing Images',
  16. width: 560,
  17. height: 'auto',
  18. });
  19. }
  20. async getData(options) {
  21. const data = super.getData(options);
  22. if (!this.missingImages)
  23. this.missingImages = deepClone(TVA_CONFIG.compendiumMapper.missingImages);
  24. data.missingImages = this.missingImages;
  25. data.documents = ['all', 'Actor', 'Cards', 'Item', 'Macro', 'RollTable'];
  26. return data;
  27. }
  28. _processFormData(formData) {
  29. if (!Array.isArray(formData.document)) {
  30. formData.document = [formData.document];
  31. formData.image = [formData.image];
  32. }
  33. const missingImages = [];
  34. for (let i = 0; i < formData.document.length; i++) {
  35. missingImages.push({ document: formData.document[i], image: formData.image[i] });
  36. }
  37. return missingImages;
  38. }
  39. /**
  40. * @param {JQuery} html
  41. */
  42. activateListeners(html) {
  43. super.activateListeners(html);
  44. html.on('click', '.add-row', () => {
  45. const formData = this._getSubmitData();
  46. this.missingImages = this._processFormData(formData);
  47. this.missingImages.push({ document: 'all', image: CONST.DEFAULT_TOKEN });
  48. this.render();
  49. });
  50. html.on('click', '.delete-row', (event) => {
  51. const formData = this._getSubmitData();
  52. this.missingImages = this._processFormData(formData);
  53. const index = $(event.target).closest('li')[0].dataset.index;
  54. this.missingImages.splice(index, 1);
  55. this.render();
  56. });
  57. html.on('click', '.file-picker', (event) => {
  58. new FilePicker({
  59. type: 'imagevideo',
  60. callback: (path) => {
  61. $(event.target).closest('li').find('[name="image"]').val(path);
  62. $(event.target).closest('li').find('img').attr('src', path);
  63. },
  64. }).render();
  65. });
  66. html.on('click', '.duplicate-picker', (event) => {
  67. let content = `<select style="width: 100%;" name="compendium">`;
  68. game.packs.forEach((pack) => {
  69. content += `<option value='${pack.collection}'>${pack.title}</option>`;
  70. });
  71. content += `</select>`;
  72. new Dialog({
  73. title: `Compendiums`,
  74. content: content,
  75. buttons: {
  76. yes: {
  77. icon: "<i class='far fa-search'></i>",
  78. label: 'Search for Duplicates',
  79. callback: (html) => {
  80. const found = new Set();
  81. const duplicates = new Set();
  82. const compendium = game.packs.get(html.find("[name='compendium']").val());
  83. compendium.index.forEach((k) => {
  84. if (found.has(k.img)) {
  85. duplicates.add(k.img);
  86. }
  87. found.add(k.img);
  88. });
  89. if (!duplicates.size) {
  90. ui.notifications.info('No duplicates found in: ' + compendium.title);
  91. }
  92. const images = Array.from(duplicates).map((img) => {
  93. return { path: img, name: getFileName(img) };
  94. });
  95. const allImages = new Map();
  96. allImages.set('Duplicates', images);
  97. showArtSelect('Duplicates', {
  98. allImages,
  99. callback: (img) => {
  100. $(event.target).closest('li').find('[name="image"]').val(img);
  101. $(event.target).closest('li').find('img').attr('src', img);
  102. },
  103. });
  104. },
  105. },
  106. },
  107. default: 'yes',
  108. }).render(true);
  109. });
  110. }
  111. async _updateObject(event, formData) {
  112. updateSettings({
  113. compendiumMapper: { missingImages: this._processFormData(formData) },
  114. });
  115. }
  116. }