Add the ArtBrowser open when using Foundry's editImage action
This commit is contained in:
parent
516c0d0c5e
commit
cf8c82784b
5 changed files with 47 additions and 1 deletions
25
module/hooks/getHeaderControlsDocumentSheetV2.mjs
Normal file
25
module/hooks/getHeaderControlsDocumentSheetV2.mjs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { ArtBrowser } from "../apps/ArtBrowser.mjs";
|
||||
import { __ID__ } from "../consts.mjs";
|
||||
|
||||
Hooks.on(`getHeaderControlsDocumentSheetV2`, (sheet) => {
|
||||
|
||||
const original = sheet.options.actions.editImage;
|
||||
sheet.options.actions.editImage = async (event, target) => {
|
||||
|
||||
if (!game.settings.get(__ID__, `openForEditImage`)) {
|
||||
return original.call(sheet, event, target);
|
||||
};
|
||||
|
||||
if (target.nodeName !== `IMG`) {
|
||||
throw new Error(`The editImage action is available only for IMG elements.`);
|
||||
};
|
||||
|
||||
const src = await ArtBrowser.select(1);
|
||||
if (!src) { return };
|
||||
target.src = src;
|
||||
if (sheet.options.form.submitOnChange) {
|
||||
const submit = new Event(`submit`, { cancelable: true });
|
||||
sheet.form.dispatchEvent(submit);
|
||||
};
|
||||
};
|
||||
});
|
||||
|
|
@ -2,12 +2,14 @@ import { api } from "../api.mjs";
|
|||
import { ArtSidebar } from "../apps/ArtSidebar.mjs";
|
||||
import { registerCustomComponents } from "../apps/elements/_index.mjs";
|
||||
import helpers from "../handlebarsHelpers/_index.mjs";
|
||||
import { registerUserSettings } from "../settings/user.mjs";
|
||||
|
||||
Hooks.on(`init`, () => {
|
||||
globalThis.tb = api;
|
||||
|
||||
Handlebars.registerHelper(helpers);
|
||||
registerUserSettings();
|
||||
registerCustomComponents();
|
||||
Handlebars.registerHelper(helpers);
|
||||
|
||||
// Art sidebar tab
|
||||
CONFIG.ui.sidebar.TABS.art = {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import "./hooks/init.mjs";
|
||||
import "./hooks/ready.mjs";
|
||||
import "./hooks/renderTokenApplication.mjs";
|
||||
import "./hooks/getHeaderControlsDocumentSheetV2.mjs";
|
||||
|
|
|
|||
12
module/settings/user.mjs
Normal file
12
module/settings/user.mjs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { __ID__ } from "../consts.mjs";
|
||||
|
||||
export function registerUserSettings() {
|
||||
game.settings.register(__ID__, `openForEditImage`, {
|
||||
name: `IT.settings.openForEditImage.name`,
|
||||
hint: `IT.settings.openForEditImage.hint`,
|
||||
scope: `user`,
|
||||
type: Boolean,
|
||||
default: true,
|
||||
config: true,
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue