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.

100 lines
3.4 KiB

1 year ago
  1. import { CharacterSheetContext, getSetting, ModuleSetting, QuickInsert, setSetting } from './quick-insert.js';
  2. import './vendor.js';
  3. // Savage Worlds Adventure Edition integration
  4. const SYSTEM_NAME = "swade";
  5. const defaultSheetFilters = {
  6. skill: "swade.skills",
  7. hindrance: "swade.hindrances",
  8. edge: "swade.edges",
  9. ability: "",
  10. weapon: "",
  11. armor: "",
  12. shield: "",
  13. gear: "",
  14. "character.choice": "",
  15. "vehicle.choice": "",
  16. mod: "",
  17. "vehicle-weapon": "",
  18. };
  19. class SwadeSheetContext extends CharacterSheetContext {
  20. constructor(documentSheet, anchor, sheetType, insertType, equipped) {
  21. super(documentSheet, anchor);
  22. this.equipped = false;
  23. this.equipped = Boolean(equipped);
  24. if (sheetType && insertType) {
  25. const sheetFilters = getSetting(ModuleSetting.FILTERS_SHEETS).baseFilters;
  26. this.filter =
  27. sheetFilters[`${sheetType}.${insertType}`] || sheetFilters[insertType];
  28. }
  29. }
  30. onSubmit(item) {
  31. const res = super.onSubmit(item);
  32. if (this.equipped && res) {
  33. res.then((items) => {
  34. const item = items.length && items[0];
  35. if (!item)
  36. return;
  37. //@ts-ignore
  38. if (item?.data?.equippable) {
  39. item.update({ "data.equipped": true });
  40. }
  41. });
  42. }
  43. return res;
  44. }
  45. }
  46. function sheetSwadeRenderHook(app, sheetType) {
  47. if (app.element.find(".quick-insert-link").length > 0) {
  48. return;
  49. }
  50. // Legacy sheets
  51. const link = `<a class="quick-insert-link" title="Quick Insert"><i class="fas fa-search"></i></a>`;
  52. app.element.find("a.item-create").each((i, el) => {
  53. const type = el.dataset.type || "";
  54. const equipped = el.dataset.equipped === "true";
  55. const linkEl = $(link);
  56. $(el).after(linkEl);
  57. linkEl.on("click", () => {
  58. const context = new SwadeSheetContext(app, linkEl, sheetType, type, equipped);
  59. QuickInsert.open(context);
  60. });
  61. });
  62. // New character sheet
  63. app.element.find("button.item-create").each((i, el) => {
  64. const type = el.dataset.type || "";
  65. const linkEl = $(link);
  66. $(el).after(linkEl);
  67. linkEl.on("click", () => {
  68. const context = new SwadeSheetContext(app, linkEl, sheetType, type);
  69. QuickInsert.open(context);
  70. });
  71. });
  72. }
  73. function init() {
  74. if (game.user?.isGM) {
  75. const customFilters = getSetting(ModuleSetting.FILTERS_SHEETS).baseFilters;
  76. setSetting(ModuleSetting.FILTERS_SHEETS, {
  77. baseFilters: {
  78. ...defaultSheetFilters,
  79. ...customFilters,
  80. },
  81. });
  82. }
  83. Hooks.on("renderCharacterSheet", (app) => {
  84. getSetting(ModuleSetting.FILTERS_SHEETS_ENABLED) &&
  85. sheetSwadeRenderHook(app, "character");
  86. });
  87. Hooks.on("renderSwadeNPCSheet", (app) => {
  88. getSetting(ModuleSetting.FILTERS_SHEETS_ENABLED) &&
  89. sheetSwadeRenderHook(app, "npc");
  90. });
  91. Hooks.on("renderSwadeVehicleSheet", (app) => {
  92. getSetting(ModuleSetting.FILTERS_SHEETS_ENABLED) &&
  93. sheetSwadeRenderHook(app, "vehicle");
  94. });
  95. console.log("Quick Insert | swade system extensions initiated");
  96. }
  97. export { SYSTEM_NAME, SwadeSheetContext, defaultSheetFilters, init, sheetSwadeRenderHook };
  98. //# sourceMappingURL=swade.js.map