Skip to content

Commit b337ad9

Browse files
committed
v13 Legacy Journals Support
1 parent 54eb6f4 commit b337ad9

8 files changed

Lines changed: 59 additions & 46 deletions

File tree

lang/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"Notifications": {},
4646
"Labels": {
4747
"ShowIconBorder": "Show icon border?",
48-
"DisableAutoIcon": "Disable auto icon generation?",
48+
"DisableAutoIcon": "Disable NoteLicker auto icon generation?",
4949
"JumpToAnchor": "Jump to Page Anchor"
5050
},
5151
"Folders": {}

module-dev.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"readme": "https://github.com/MrPrimate/NoteLicker/blob/main/README.md",
1111
"changelog": "https://github.com/MrPrimate/NoteLicker/blob/main/CHANGELOG.md",
1212
"compatibility": {
13-
"minimum": "11",
14-
"verified": 12
13+
"minimum": "13",
14+
"verified": 13
1515
},
1616
"authors": [
1717
{

module-template.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"readme": "https://github.com/MrPrimate/NoteLicker/blob/main/README.md",
1111
"changelog": "https://github.com/MrPrimate/NoteLicker/blob/main/CHANGELOG.md",
1212
"compatibility": {
13-
"minimum": "11",
14-
"verified": 12
13+
"minimum": "13",
14+
"verified": 13
1515
},
1616
"authors": [
1717
{

src/hooks/anchorInjection.mjs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ function getOptions(page, current) {
1313
}
1414

1515
function addSlugField(element, slug, document) {
16-
const titleInput = element.querySelector("input[name='text']");
16+
const titleInput = element.querySelector("select[name='pageId']");
1717
const label = game.i18n.localize(`${CONSTANTS.SHORT_NAME}.Labels.JumpToAnchor`);
1818
const slugHTML = `<div class="form-group">
1919
<label>${label}</label>
2020
<div class="form-fields">
21-
<select name="slug" >${getOptions(document.page, slug)}</select>
21+
<select name="flags.${CONSTANTS.FLAG_NAME}.slugLink" >${getOptions(document.page, slug)}</select>
2222
</div>
2323
</div>`;
2424

@@ -46,7 +46,7 @@ function updateNotePage(noteConfig, slug) {
4646
const pageId = noteConfig.form.elements.pageId?.value;
4747
const journal = game.journal.get(journalId);
4848
const page = journal?.pages.get(pageId);
49-
noteConfig.form.elements["slug"].innerHTML = getOptions(page, slug);
49+
noteConfig.form.elements[`flags.${CONSTANTS.FLAG_NAME}.slugLink`].innerHTML = getOptions(page, slug);
5050
}
5151

5252
export function anchorInjection() {
@@ -73,10 +73,11 @@ export function anchorInjection() {
7373
});
7474

7575
// when we render a note we add the anchor links box
76-
Hooks.on("renderNoteConfig", (noteConfig, html, data) => {
76+
Hooks.on("renderNoteConfig", (noteConfig, form, data) => {
7777
const slug = getSlug(noteConfig.document);
78-
if (!noteConfig.element[0].querySelector("input[name='slug']")) {
79-
addSlugField(noteConfig.element[0], slug, data.document);
78+
79+
if (!form.querySelector(`input[name='flags.${CONSTANTS.FLAG_NAME}.slugLink']`)) {
80+
addSlugField(form, slug, data.document);
8081
if (!noteConfig._minimized) {
8182
const pos = noteConfig.position;
8283
pos.height = 'auto';
@@ -86,16 +87,18 @@ export function anchorInjection() {
8687
noteConfig.element[0].style.height = "auto";
8788
const isExistingNote = noteConfig.document.id !== null;
8889

89-
html.find("select[name='entryId']").change(() => updateNotePage(noteConfig, slug));
90-
html.find("select[name='pageId']").change(() => updateNotePage(noteConfig, slug));
90+
const entryIdSelect = form.querySelector("select[name='entryId']");
91+
const pageIdSelect = form.querySelector("select[name='pageId']");
92+
93+
entryIdSelect.addEventListener("change", () => updateNotePage(noteConfig, slug));
94+
pageIdSelect.addEventListener("change", () => updateNotePage(noteConfig, slug));
9195

9296
if (isExistingNote) {
93-
const closeHookId = Hooks.on("closeDocumentSheet", async (documentSheet, html) => {
97+
const closeHookId = Hooks.on("closeDocumentSheetV2", async (documentSheet) => {
9498
if (!(documentSheet instanceof NoteConfig)) return;
9599
if (noteConfig.document.id !== documentSheet.document.id) return;
96-
Hooks.off("closeNoteConfig", closeHookId);
97-
const slugInput = html[0].querySelector("select[name='slug']");
98-
const selectedSlug = slugInput?.value;
100+
Hooks.off("closeDocumentSheetV2", closeHookId);
101+
const selectedSlug = documentSheet.document.getFlag(CONSTANTS.FLAG_NAME, "slugLink");
99102
if (selectedSlug && selectedSlug.trim() !== "" && selectedSlug !== documentSheet.document.flags.ddb?.slugLink) {
100103
const update = setSlugProperties({ _id: documentSheet.document.id }, selectedSlug, documentSheet.document.label);
101104
await canvas.scene.updateEmbeddedDocuments("Note", [update]);
@@ -117,8 +120,8 @@ export function anchorInjection() {
117120

118121
// when we create from the side bar we fill in the input label name to match
119122
// the anchor name and set the slug value to the anchor slug
120-
Hooks.once("renderNoteConfig", (noteConfig, _html, app) => {
121-
const titleInput = noteConfig.element[0].querySelector("input[name='text']");
123+
Hooks.once("renderNoteConfig", (noteConfig, form, app) => {
124+
const titleInput = form.querySelector("input[name='text']");
122125
if (dropData.anchor.slug) {
123126
titleInput.setAttribute('value', dropData.anchor.name);
124127
updateNotePage(noteConfig, dropData.anchor.slug);

src/hooks/dynamicIcons.mjs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,35 @@ import utils from "../lib/utils.mjs";
66
export async function dynamicIcons() {
77
if (!utils.setting("ENABLE_DYNAMIC_ICONS")) return;
88

9-
Hooks.on("renderNoteConfig", (noteConfig, html, data) => {
10-
const sourceTexture = noteConfig.object?._source?.texture?.src;
11-
if (Icons.textureExists(noteConfig.object.texture.src) && sourceTexture) {
12-
noteConfig.object.texture.src = `${noteConfig.object._source.texture.src}`;
9+
Hooks.on("renderNoteConfig", (noteConfig, form, data) => {
10+
11+
const sourceTexture = noteConfig.document?.texture?.src;
12+
13+
const formGroupCustomElement = form.querySelector("[data-icon-custom]");
14+
const customItemElement = form.querySelector("input[name='icon.custom']");
15+
if (Icons.textureExists(noteConfig.document.texture.src) && sourceTexture) {
16+
noteConfig.object.texture.src = `${noteConfig.document._source.texture.src}`;
1317
const customIcon = !Object.values(CONFIG.JournalEntry.noteIcons).includes(sourceTexture);
14-
const icon = {
18+
data.icon = {
1519
selected: customIcon ? "" : sourceTexture,
1620
custom: customIcon ? sourceTexture : "",
1721
};
18-
data.icon = icon;
19-
if (customIcon) {
20-
html.find("input[name='icon.custom']")[0].value = sourceTexture;
21-
} else {
22-
html.find("input[name='icon.custom']")[0].value = "";
23-
html.find("select[name='icon.selected']")[0].value = sourceTexture;
22+
customItemElement.value = sourceTexture;
23+
if (!customIcon) {
24+
form.querySelector("input[name='icon.custom']").value = "";
2425
}
2526
}
27+
// formGroupCustomElement.hidden = "";
2628
// add disable selector
2729
const disableAutoIcon = Icons.disableAutoIcon(noteConfig.document);
28-
const globalGroup = html.find("input[name='icon.custom']").closest(".form-group");
30+
// const globalGroup = form.querySelector("input[name='icon.custom']").closest(".form-group");
2931
const label = game.i18n.localize(`${CONSTANTS.SHORT_NAME}.Labels.DisableAutoIcon`);
30-
globalGroup.after(`
31-
<div class="form-group">
32-
<label for="flags.${CONSTANTS.FLAG_NAME}.disableAutoIcon">${label}</label>
33-
<input type="checkbox" name="flags.${CONSTANTS.FLAG_NAME}.disableAutoIcon" data-dtype="Boolean" ${disableAutoIcon ? "checked" : ""}>
34-
</div>
35-
`);
32+
formGroupCustomElement.insertAdjacentHTML('afterend', `
33+
<div class="form-group">
34+
<label for="flags.${CONSTANTS.FLAG_NAME}.disableAutoIcon">${label}</label>
35+
<input type="checkbox" name="flags.${CONSTANTS.FLAG_NAME}.disableAutoIcon" id="flags.${CONSTANTS.FLAG_NAME}.disableAutoIcon" data-dtype="Boolean" ${disableAutoIcon ? "checked" : ""}>
36+
</div>
37+
`);
3638
noteConfig.setPosition({ height: "auto" });
3739
});
3840
}

src/hooks/noteWrapper.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import CONSTANTS from "../constants.mjs";
22
import Icons from "../lib/Icons.mjs";
33
import utils from "../lib/utils.mjs";
44

5-
class BorderlessControlIcon extends ControlIcon {
5+
class BorderlessControlIcon extends foundry.canvas.containers.ControlIcon {
66
async draw() {
77
if (this.destroyed) return this;
88

@@ -26,11 +26,19 @@ export function noteWrapper() {
2626
if (utils.setting("ENABLE_DYNAMIC_ICONS")) {
2727
/* eslint-disable no-invalid-this */
2828
libWrapper.register(CONSTANTS.FLAG_NAME, 'Note.prototype._draw', async function(wrapped, ...args) {
29+
30+
console.warn("Note.prototype._draw", {
31+
wrapped,
32+
args,
33+
this: this,
34+
notTextureExists: !Icons.textureExists(this.document?.texture?.src),
35+
notDisableAutoIcon: !Icons.disableAutoIcon(this.document),
36+
});
2937
if (utils.setting("ENABLE_DYNAMIC_ICONS")
3038
&& !Icons.textureExists(this.document?.texture?.src)
3139
&& !Icons.disableAutoIcon(this.document)
3240
) {
33-
const data = (this.text?.length > 0)
41+
const data = (this.document?.label?.length > 0)
3442
? await Icons.generateIconData(Icons.determineAnchorName(this))
3543
: undefined;
3644

src/lib/DirectoryPicker.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logger from "./logger.mjs";
22
import utils from "./utils.mjs";
33

4-
export class DirectoryPicker extends FilePicker {
4+
export class DirectoryPicker extends foundry.applications.apps.FilePicker.implementation {
55
constructor(options = {}) {
66
super(options);
77
}

src/lib/Icons.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ export default class Icons {
2828
}
2929

3030
static determineAnchorName(note) {
31-
const text = note.text;
31+
const name = note.document.label;
3232

33-
if (!text || text.trim() === "") return undefined;
33+
if (!name || name.trim() === "") return undefined;
3434

3535
const pageName = note.page?.name;
36-
if (!pageName) return text;
36+
if (!pageName) return name;
3737

38-
if (text.startsWith(`${pageName}:`)) {
38+
if (name.startsWith(`${pageName}:`)) {
3939
const reg = new RegExp(`^${pageName}:`);
40-
return text.replace(reg, "").trim();
40+
return name.replace(reg, "").trim();
4141
}
42-
return text;
42+
return name;
4343
}
4444

4545
static convertSvgToDataURL(svgText) {

0 commit comments

Comments
 (0)