Begin working on an attempt to make the required setting, but be blocked by Foundry for listening to open/close events on the prose-mirror editor
This commit is contained in:
parent
703dc83681
commit
f8c21ac8d8
6 changed files with 82 additions and 1 deletions
|
|
@ -9,6 +9,10 @@
|
||||||
"canPlayersManageAttributes": {
|
"canPlayersManageAttributes": {
|
||||||
"name": "Players Can Manage Attributes",
|
"name": "Players Can Manage Attributes",
|
||||||
"hint": "This allows players who have edit access to a document to be able to edit what attributes those characters have via the attribute editor"
|
"hint": "This allows players who have edit access to a document to be able to edit what attributes those characters have via the attribute editor"
|
||||||
|
},
|
||||||
|
"openSheetInEdit": {
|
||||||
|
"name": "Open Sheets in Edit Mode",
|
||||||
|
"hint": "This makes the default when you open an Actor sheet for the first time each session to put the text editor into edit mode instead of read-only mode. On subsequent opens, the sheet"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sheet-names": {
|
"sheet-names": {
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,33 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
return super._initializeApplicationOptions(options);
|
return super._initializeApplicationOptions(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @type {boolean | null} */
|
||||||
|
#inEditMode = null;
|
||||||
|
async _onFirstRender(context, options) {
|
||||||
|
super._onFirstRender(context, options);
|
||||||
|
console.log(`_onFirstRender`)
|
||||||
|
this.#inEditMode ??= game.settings.get(__ID__, `openSheetInEdit`) ?? false;
|
||||||
|
this.element.querySelectorAll(`prose-mirror`).forEach(editor => {
|
||||||
|
editor.open = this.#inEditMode;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
async _onRender(context, options) {
|
||||||
|
super._onRender(context, options);
|
||||||
|
|
||||||
|
if (options.parts?.includes(`content`)) {
|
||||||
|
const el = this.element.querySelector(`prose-mirror[name="system.content"]`);
|
||||||
|
el?.addEventListener(`open`, () => {
|
||||||
|
console.log(`event: open`);
|
||||||
|
this.#inEditMode = true;
|
||||||
|
});
|
||||||
|
el?.addEventListener(`close`, () => {
|
||||||
|
console.log(`event: close`);
|
||||||
|
this.#inEditMode = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
_getHeaderControls() {
|
_getHeaderControls() {
|
||||||
const controls = super._getHeaderControls();
|
const controls = super._getHeaderControls();
|
||||||
|
|
||||||
|
|
@ -125,7 +152,9 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
ctx.attrs = attrs.toSorted(attributeSorter);
|
ctx.attrs = attrs.toSorted(attributeSorter);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @type {boolean | null} */
|
||||||
async _prepareContent(ctx) {
|
async _prepareContent(ctx) {
|
||||||
|
|
||||||
const TextEditor = foundry.applications.ux.TextEditor.implementation;
|
const TextEditor = foundry.applications.ux.TextEditor.implementation;
|
||||||
ctx.enriched = {
|
ctx.enriched = {
|
||||||
system: {
|
system: {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import { TAFItem } from "../documents/Item.mjs";
|
||||||
import { TAFTokenDocument } from "../documents/Token.mjs";
|
import { TAFTokenDocument } from "../documents/Token.mjs";
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
|
import { registerUserSettings } from "../settings/user.mjs";
|
||||||
import { registerWorldSettings } from "../settings/world.mjs";
|
import { registerWorldSettings } from "../settings/world.mjs";
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
|
|
@ -41,6 +42,7 @@ Hooks.on(`init`, () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
registerWorldSettings();
|
registerWorldSettings();
|
||||||
|
registerUserSettings();
|
||||||
|
|
||||||
registerSockets();
|
registerSockets();
|
||||||
registerCustomComponents();
|
registerCustomComponents();
|
||||||
|
|
|
||||||
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__, `openSheetInEdit`, {
|
||||||
|
name: `taf.settings.openSheetInEdit.name`,
|
||||||
|
hint: `taf.settings.openSheetInEdit.hint`,
|
||||||
|
config: true,
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
scope: `user`,
|
||||||
|
});
|
||||||
|
};
|
||||||
34
scripts/macros/testRequest.mjs
Normal file
34
scripts/macros/testRequest.mjs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
const rolls = {};
|
||||||
|
|
||||||
|
const response = await taf.QueryManager.query(
|
||||||
|
{
|
||||||
|
id: `test-data-request`,
|
||||||
|
question: `Test Data`,
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
type: `input`,
|
||||||
|
inputType: `number`,
|
||||||
|
key: `statBase`,
|
||||||
|
label: `Stat Base`,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSubmit: async (userID, answers) => {
|
||||||
|
|
||||||
|
rolls[userID] = [];
|
||||||
|
|
||||||
|
const diceHTML = [];
|
||||||
|
for (let i = 0; i < answers.statBase; i++) {
|
||||||
|
const rolled = Math.floor(Math.random() * 6) + 1;
|
||||||
|
rolls[userID].push(rolled);
|
||||||
|
diceHTML.push(`<li class="roll dice d6">${rolled}</li>`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const content = `Rolls:<div class="dice-tooltip"><ol class="dice-rolls">${diceHTML.join(`\n`)}</ol></div>`;
|
||||||
|
|
||||||
|
await taf.QueryManager.notify(userID, content);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log({ response, rolls });
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
value="{{system.content}}"
|
value="{{system.content}}"
|
||||||
collaborate="true"
|
collaborate="true"
|
||||||
data-document-uuid="{{actor.uuid}}"
|
data-document-uuid="{{actor.uuid}}"
|
||||||
toggled="true"
|
toggled
|
||||||
>
|
>
|
||||||
{{{ enriched.system.content }}}
|
{{{ enriched.system.content }}}
|
||||||
</prose-mirror>
|
</prose-mirror>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue