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.

109 lines
3.6 KiB

  1. export default class RandomizerConfig extends FormApplication {
  2. constructor(obj) {
  3. super({}, {});
  4. this.actor = game.actors.get(obj.actorId);
  5. }
  6. static get defaultOptions() {
  7. return mergeObject(super.defaultOptions, {
  8. id: 'token-variants-token-flags',
  9. classes: ['sheet'],
  10. template: 'modules/token-variants/templates/randomizerConfig.html',
  11. resizable: true,
  12. minimizable: false,
  13. title: 'Randomizer',
  14. width: 500,
  15. });
  16. }
  17. async getData(options) {
  18. const data = super.getData(options);
  19. const settings = this.actor.getFlag('token-variants', 'randomizerSettings') || {};
  20. data.randomizer = settings;
  21. data.hasSettings = !isEmpty(settings);
  22. data.nameForgeActive = game.modules.get('nameforge')?.active;
  23. if (data.randomizer.nameForge?.models && Array.isArray(data.randomizer.nameForge.models)) {
  24. data.randomizer.nameForge.models = data.randomizer.nameForge.models.join(',');
  25. }
  26. return data;
  27. }
  28. /**
  29. * @param {JQuery} html
  30. */
  31. activateListeners(html) {
  32. super.activateListeners(html);
  33. html.find('.selectNameForgeModels').click(this._selectNameForgeModels.bind(this));
  34. // Can't have both tokenName and actorName checkboxes checked at the same time
  35. const tokenName = html.find('input[name="randomizer.tokenName"]');
  36. const actorName = html.find('input[name="randomizer.actorName"]');
  37. tokenName.change(() => {
  38. if (tokenName.is(':checked')) actorName.prop('checked', false);
  39. });
  40. actorName.change(() => {
  41. if (actorName.is(':checked')) tokenName.prop('checked', false);
  42. });
  43. }
  44. _selectNameForgeModels(event) {
  45. const inputSelected = $(event.target).siblings('input');
  46. const selected = inputSelected.val().split(',');
  47. const genCheckbox = function (name, value) {
  48. return `
  49. <div class="form-group">
  50. <label>${name}</label>
  51. <div class="form-fields">
  52. <input type="checkbox" name="model" value="${value}" data-dtype="Boolean" ${
  53. selected?.find((v) => v === value) ? 'checked' : ''
  54. }>
  55. </div>
  56. </div>
  57. `;
  58. };
  59. let content = '<form style="overflow-y: scroll; height:400px;">';
  60. const models = game.modules.get('nameforge').models;
  61. for (const [k, v] of Object.entries(models.defaultModels)) {
  62. content += genCheckbox(v.name, 'defaultModels.' + k);
  63. }
  64. for (const [k, v] of Object.entries(models.userModels)) {
  65. content += genCheckbox(v.name, 'userModels.' + k);
  66. }
  67. content += `</form>`;
  68. new Dialog({
  69. title: `Name Forge Models`,
  70. content: content,
  71. buttons: {
  72. Ok: {
  73. label: `Select`,
  74. callback: async (html) => {
  75. const selectedModels = [];
  76. html.find('input[type="checkbox"]').each(function () {
  77. if (this.checked) selectedModels.push(this.value);
  78. });
  79. inputSelected.val(selectedModels.join(','));
  80. },
  81. },
  82. },
  83. }).render(true);
  84. }
  85. /**
  86. * @param {Event} event
  87. * @param {Object} formData
  88. */
  89. async _updateObject(event, formData) {
  90. if (event.submitter.value === 'remove') {
  91. await this.actor.unsetFlag('token-variants', 'randomizerSettings');
  92. } else {
  93. const expanded = expandObject(formData);
  94. if (expanded.randomizer.nameForge?.models) {
  95. expanded.randomizer.nameForge.models = expanded.randomizer.nameForge.models.split(',');
  96. }
  97. this.actor.setFlag('token-variants', 'randomizerSettings', expanded.randomizer);
  98. }
  99. }
  100. }