Update the implementation to use an extended sheet class instead of a setting
This commit is contained in:
parent
f8c21ac8d8
commit
6f04910d2c
6 changed files with 20 additions and 49 deletions
|
|
@ -9,14 +9,11 @@
|
|||
"canPlayersManageAttributes": {
|
||||
"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"
|
||||
},
|
||||
"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": {
|
||||
"PlayerSheet": "Player Sheet"
|
||||
"PlayerSheet": "Player Sheet",
|
||||
"SingleModePlayerSheet": "Player Sheet (Always Editing)"
|
||||
},
|
||||
"misc": {
|
||||
"Key": "Key",
|
||||
|
|
|
|||
|
|
@ -64,33 +64,6 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
|||
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() {
|
||||
const controls = super._getHeaderControls();
|
||||
|
||||
|
|
@ -152,8 +125,9 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
|||
ctx.attrs = attrs.toSorted(attributeSorter);
|
||||
};
|
||||
|
||||
/** @type {boolean | null} */
|
||||
async _prepareContent(ctx) {
|
||||
// Whether or not the prose-mirror is toggled or always-edit
|
||||
ctx.toggled = true;
|
||||
|
||||
const TextEditor = foundry.applications.ux.TextEditor.implementation;
|
||||
ctx.enriched = {
|
||||
|
|
|
|||
8
module/apps/SingleModePlayerSheet.mjs
Normal file
8
module/apps/SingleModePlayerSheet.mjs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { PlayerSheet } from "./PlayerSheet.mjs";
|
||||
|
||||
export class SingleModePlayerSheet extends PlayerSheet {
|
||||
async _prepareContent(ctx) {
|
||||
await super._prepareContent(ctx);
|
||||
ctx.toggled = false;
|
||||
};
|
||||
};
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
// Apps
|
||||
import { PlayerSheet } from "../apps/PlayerSheet.mjs";
|
||||
import { SingleModePlayerSheet } from "../apps/SingleModePlayerSheet.mjs";
|
||||
|
||||
// Data Models
|
||||
import { PlayerData } from "../data/Player.mjs";
|
||||
|
|
@ -10,7 +11,6 @@ import { TAFItem } from "../documents/Item.mjs";
|
|||
import { TAFTokenDocument } from "../documents/Token.mjs";
|
||||
|
||||
// Settings
|
||||
import { registerUserSettings } from "../settings/user.mjs";
|
||||
import { registerWorldSettings } from "../settings/world.mjs";
|
||||
|
||||
// Utils
|
||||
|
|
@ -40,9 +40,13 @@ Hooks.on(`init`, () => {
|
|||
label: `taf.sheet-names.PlayerSheet`,
|
||||
},
|
||||
);
|
||||
foundry.documents.collections.Actors.registerSheet(
|
||||
__ID__,
|
||||
SingleModePlayerSheet,
|
||||
{ label: `taf.sheet-names.SingleModePlayerSheet` },
|
||||
);
|
||||
|
||||
registerWorldSettings();
|
||||
registerUserSettings();
|
||||
|
||||
registerSockets();
|
||||
registerCustomComponents();
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
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`,
|
||||
});
|
||||
};
|
||||
|
|
@ -6,11 +6,11 @@
|
|||
value="{{system.content}}"
|
||||
collaborate="true"
|
||||
data-document-uuid="{{actor.uuid}}"
|
||||
toggled
|
||||
{{ifThen toggled "toggled" ""}}
|
||||
>
|
||||
{{{ enriched.system.content }}}
|
||||
</prose-mirror>
|
||||
{{else}}
|
||||
{{{ enriched.system.content }}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue