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.

85 lines
2.6 KiB

  1. import { TVA_CONFIG, updateSettings } from '../scripts/settings.js';
  2. import { SEARCH_TYPE, decodeURISafely } from '../scripts/utils.js';
  3. import { insertArtSelectButton } from './artSelect.js';
  4. export default class UserList extends FormApplication {
  5. constructor(object, img, regenStyle) {
  6. super({}, {});
  7. this.object = object;
  8. this.img = img;
  9. this.regenStyle = regenStyle;
  10. }
  11. static get defaultOptions() {
  12. return mergeObject(super.defaultOptions, {
  13. id: 'token-variants-user-list',
  14. classes: ['sheet'],
  15. template: 'modules/token-variants/templates/userList.html',
  16. resizable: false,
  17. minimizable: false,
  18. title: 'User To Image',
  19. width: 300,
  20. });
  21. }
  22. async getData(options) {
  23. const data = super.getData(options);
  24. const mappings = this.object.document.getFlag('token-variants', 'userMappings') || {};
  25. let users = [];
  26. game.users.forEach((user) => {
  27. users.push({
  28. avatar: user.avatar,
  29. name: user.name,
  30. apply: user.id in mappings && mappings[user.id] === this.img,
  31. userId: user.id,
  32. color: user.color,
  33. });
  34. });
  35. data.users = users;
  36. data.invisibleImage = TVA_CONFIG.invisibleImage;
  37. return data;
  38. }
  39. /**
  40. * @param {JQuery} html
  41. */
  42. activateListeners(html) {
  43. super.activateListeners(html);
  44. insertArtSelectButton(html, 'invisibleImage', {
  45. search: 'Invisible Image',
  46. searchType: SEARCH_TYPE.TOKEN,
  47. });
  48. }
  49. async _updateObject(event, formData) {
  50. const mappings = this.object.document.getFlag('token-variants', 'userMappings') || {};
  51. if (formData.invisibleImage !== TVA_CONFIG.invisibleImage) {
  52. updateSettings({ invisibleImage: decodeURISafely(formData.invisibleImage) });
  53. }
  54. delete formData.invisibleImage;
  55. const affectedImages = [this.img];
  56. for (const [userId, apply] of Object.entries(formData)) {
  57. if (apply) {
  58. if (mappings[userId] && mappings[userId] !== this.img)
  59. affectedImages.push(mappings[userId]);
  60. mappings[userId] = this.img;
  61. } else if (mappings[userId] === this.img) {
  62. delete mappings[userId];
  63. mappings['-=' + userId] = null;
  64. }
  65. }
  66. if (Object.keys(mappings).filter((userId) => !userId.startsWith('-=')).length === 0) {
  67. await this.object.document.unsetFlag('token-variants', 'userMappings');
  68. } else {
  69. await this.object.document.setFlag('token-variants', 'userMappings', mappings);
  70. }
  71. for (const img of affectedImages) {
  72. this.regenStyle(this.object, img);
  73. }
  74. }
  75. }