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.

81 lines
2.5 KiB

  1. import { TVA_CONFIG, updateSettings } from '../scripts/settings.js';
  2. import { SEARCH_TYPE } 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', { search: 'Invisible Image', searchType: SEARCH_TYPE.TOKEN });
  45. }
  46. async _updateObject(event, formData) {
  47. const mappings = this.object.document.getFlag('token-variants', 'userMappings') || {};
  48. if (formData.invisibleImage !== TVA_CONFIG.invisibleImage) {
  49. updateSettings({ invisibleImage: decodeURI(formData.invisibleImage) });
  50. }
  51. delete formData.invisibleImage;
  52. const affectedImages = [this.img];
  53. for (const [userId, apply] of Object.entries(formData)) {
  54. if (apply) {
  55. if (mappings[userId] && mappings[userId] !== this.img) affectedImages.push(mappings[userId]);
  56. mappings[userId] = this.img;
  57. } else if (mappings[userId] === this.img) {
  58. delete mappings[userId];
  59. mappings['-=' + userId] = null;
  60. }
  61. }
  62. if (Object.keys(mappings).filter((userId) => !userId.startsWith('-=')).length === 0) {
  63. await this.object.document.unsetFlag('token-variants', 'userMappings');
  64. } else {
  65. await this.object.document.setFlag('token-variants', 'userMappings', mappings);
  66. }
  67. for (const img of affectedImages) {
  68. this.regenStyle(this.object, img);
  69. }
  70. }
  71. }