jkdsjkdsj
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"id": "dragonroll-foundry",
|
"id": "dragonroll-foundry",
|
||||||
"title": "Dragonroll Foundry API",
|
"title": "Dragonroll Foundry API",
|
||||||
"description": "Links a Foundry world to a Dragonroll campaign and exposes a client-side API for world data.",
|
"description": "Links a Foundry world to a Dragonroll campaign and exposes a client-side API for world data.",
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"library": true,
|
"library": true,
|
||||||
"compatibility": {
|
"compatibility": {
|
||||||
"minimum": "12",
|
"minimum": "12",
|
||||||
|
|||||||
@@ -1432,7 +1432,7 @@ async function applyDragonrollNotePage(page, entry) {
|
|||||||
const title = notePageTitle(entry);
|
const title = notePageTitle(entry);
|
||||||
const html = notePageHtml(entry.content);
|
const html = notePageHtml(entry.content);
|
||||||
const updates = {};
|
const updates = {};
|
||||||
if (String(page.title?.text ?? page.title ?? "") !== title) updates["title.text"] = title;
|
if (String(page.name ?? "") !== title) updates.name = title;
|
||||||
if (String(page.text?.content ?? "") !== html) updates["text.content"] = html;
|
if (String(page.text?.content ?? "") !== html) updates["text.content"] = html;
|
||||||
if (!dragonrollNoteId(page)) updates[`flags.${MODULE_ID}.noteId`] = String(entry._id);
|
if (!dragonrollNoteId(page)) updates[`flags.${MODULE_ID}.noteId`] = String(entry._id);
|
||||||
if (Object.keys(updates).length) await page.update(updates);
|
if (Object.keys(updates).length) await page.update(updates);
|
||||||
@@ -1440,7 +1440,9 @@ async function applyDragonrollNotePage(page, entry) {
|
|||||||
|
|
||||||
async function createDragonrollNotePage(journal, entry) {
|
async function createDragonrollNotePage(journal, entry) {
|
||||||
const pages = await journal.createEmbeddedDocuments("JournalEntryPage", [{
|
const pages = await journal.createEmbeddedDocuments("JournalEntryPage", [{
|
||||||
title: { text: notePageTitle(entry) },
|
// A page's display title is its `name`; `title` only holds the table-of-contents
|
||||||
|
// flags (`show`/`level`). Missing `name` fails the document's validation.
|
||||||
|
name: notePageTitle(entry),
|
||||||
text: { content: notePageHtml(entry.content) },
|
text: { content: notePageHtml(entry.content) },
|
||||||
flags: { [MODULE_ID]: { noteId: String(entry._id) } },
|
flags: { [MODULE_ID]: { noteId: String(entry._id) } },
|
||||||
}], { renderSheet: false });
|
}], { renderSheet: false });
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ function makeWorld({ markdown = true } = {}) {
|
|||||||
const page = {
|
const page = {
|
||||||
id: `page-${state.nextId++}`,
|
id: `page-${state.nextId++}`,
|
||||||
documentName: "JournalEntryPage",
|
documentName: "JournalEntryPage",
|
||||||
title: data.title,
|
name: data.name,
|
||||||
text: { content: data.text?.content ?? "" },
|
text: { content: data.text?.content ?? "" },
|
||||||
flags: data.flags ?? {},
|
flags: data.flags ?? {},
|
||||||
writes: 0,
|
writes: 0,
|
||||||
@@ -285,6 +285,8 @@ function makeWorld({ markdown = true } = {}) {
|
|||||||
async update(update) { return writeFoundryPaths(this, update); },
|
async update(update) { return writeFoundryPaths(this, update); },
|
||||||
async createEmbeddedDocuments(documentName, docs) {
|
async createEmbeddedDocuments(documentName, docs) {
|
||||||
assert.equal(documentName, "JournalEntryPage", "the notes' pages are journal pages");
|
assert.equal(documentName, "JournalEntryPage", "the notes' pages are journal pages");
|
||||||
|
// Foundry's own page validation refuses a page without a name.
|
||||||
|
for (const doc of docs) assert.ok(doc.name, "a journal page needs a non-empty name");
|
||||||
const created = docs.map((doc) => makePage(this, doc));
|
const created = docs.map((doc) => makePage(this, doc));
|
||||||
pages.push(...created);
|
pages.push(...created);
|
||||||
return created;
|
return created;
|
||||||
@@ -428,7 +430,7 @@ test("the campaign's notes become pages of one Dragonroll journal", async () =>
|
|||||||
assert.equal(world.journals().length, 1, "one journal carries the campaign's notes");
|
assert.equal(world.journals().length, 1, "one journal carries the campaign's notes");
|
||||||
const journal = world.journals()[0];
|
const journal = world.journals()[0];
|
||||||
assert.equal(journal.name, "Dragonroll");
|
assert.equal(journal.name, "Dragonroll");
|
||||||
assert.deepEqual(journal.pages.contents.map((page) => [page.title.text, page.text.content]), [
|
assert.deepEqual(journal.pages.contents.map((page) => [page.name, page.text.content]), [
|
||||||
["Session 1", "<marked>**The start**</marked>"],
|
["Session 1", "<marked>**The start**</marked>"],
|
||||||
["Tavern Brawl", "<marked>A rope, a chandelier.</marked>"],
|
["Tavern Brawl", "<marked>A rope, a chandelier.</marked>"],
|
||||||
], "each note is a page, its markdown rendered by Foundry's own renderer");
|
], "each note is a page, its markdown rendered by Foundry's own renderer");
|
||||||
@@ -440,6 +442,19 @@ test("the campaign's notes become pages of one Dragonroll journal", async () =>
|
|||||||
], "and the campaign remembers each note's page");
|
], "and the campaign remembers each note's page");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("reconciling again does not double the journal or its pages", async () => {
|
||||||
|
const world = await makeWorld().linkedSetup();
|
||||||
|
world.remoteNotes = [sessionNote(), tavernNote()];
|
||||||
|
|
||||||
|
await world.runIntervals();
|
||||||
|
await world.runIntervals();
|
||||||
|
await world.runIntervals();
|
||||||
|
|
||||||
|
assert.equal(world.journals().length, 1, "the journal is made once, not per reconcile");
|
||||||
|
assert.equal(world.journals()[0].pages.contents.length, 2, "and each note stands as the one page it was given");
|
||||||
|
assert.equal(world.mapNoteRequests().length, 2, "an already-mapped note is not mapped again");
|
||||||
|
});
|
||||||
|
|
||||||
test("an existing journal named Dragonroll is used, not doubled", async () => {
|
test("an existing journal named Dragonroll is used, not doubled", async () => {
|
||||||
const world = await makeWorld().linkedSetup();
|
const world = await makeWorld().linkedSetup();
|
||||||
const gmsOwn = world.addJournal("Dragonroll");
|
const gmsOwn = world.addJournal("Dragonroll");
|
||||||
@@ -448,7 +463,7 @@ test("an existing journal named Dragonroll is used, not doubled", async () => {
|
|||||||
await world.runIntervals();
|
await world.runIntervals();
|
||||||
|
|
||||||
assert.equal(world.journals().length, 1, "the journal the world already had is the notes' one");
|
assert.equal(world.journals().length, 1, "the journal the world already had is the notes' one");
|
||||||
assert.deepEqual(gmsOwn.pages.contents.map((page) => page.title.text), ["Session 1"]);
|
assert.deepEqual(gmsOwn.pages.contents.map((page) => page.name), ["Session 1"]);
|
||||||
assert.equal(gmsOwn.getFlag(MODULE_ID, "notesJournal"), true, "and it is marked, so renaming it keeps the notes' home findable");
|
assert.equal(gmsOwn.getFlag(MODULE_ID, "notesJournal"), true, "and it is marked, so renaming it keeps the notes' home findable");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -463,7 +478,7 @@ test("a note edited in Dragonroll rewrites its page", async () => {
|
|||||||
|
|
||||||
const journal = world.journals()[0];
|
const journal = world.journals()[0];
|
||||||
assert.equal(journal.pages.contents.length, 1, "the note still stands as the same single page");
|
assert.equal(journal.pages.contents.length, 1, "the note still stands as the same single page");
|
||||||
assert.deepEqual(journal.pages.contents[0].title.text, "Session 1 — revisited");
|
assert.deepEqual(journal.pages.contents[0].name, "Session 1 — revisited");
|
||||||
assert.equal(journal.pages.contents[0].text.content, "<marked>**A different start**</marked>");
|
assert.equal(journal.pages.contents[0].text.content, "<marked>**A different start**</marked>");
|
||||||
assert.equal(world.mapNoteRequests().length, 1, "the pairing the world reads back needs no remapping");
|
assert.equal(world.mapNoteRequests().length, 1, "the pairing the world reads back needs no remapping");
|
||||||
});
|
});
|
||||||
@@ -474,11 +489,11 @@ test("a note deleted in Dragonroll takes its page with it", async () => {
|
|||||||
await world.runIntervals();
|
await world.runIntervals();
|
||||||
|
|
||||||
const journal = world.journals()[0];
|
const journal = world.journals()[0];
|
||||||
const gmsPage = world.addPage(journal, { title: { text: "My own notes" }, text: { content: "not from Dragonroll" } });
|
const gmsPage = world.addPage(journal, { name: "My own notes", text: { content: "not from Dragonroll" } });
|
||||||
world.remoteNotes = world.remoteNotes.filter((note) => note._id !== "note-2");
|
world.remoteNotes = world.remoteNotes.filter((note) => note._id !== "note-2");
|
||||||
await world.runIntervals();
|
await world.runIntervals();
|
||||||
|
|
||||||
assert.deepEqual(journal.pages.contents.map((page) => page.title.text), ["Session 1", "My own notes"],
|
assert.deepEqual(journal.pages.contents.map((page) => page.name), ["Session 1", "My own notes"],
|
||||||
"the deleted note's page goes; the GM's own page stays");
|
"the deleted note's page goes; the GM's own page stays");
|
||||||
assert.ok(journal.pages.contents.includes(gmsPage));
|
assert.ok(journal.pages.contents.includes(gmsPage));
|
||||||
});
|
});
|
||||||
@@ -497,13 +512,13 @@ test("pages already in step with the campaign are not rewritten", async () => {
|
|||||||
test("the campaign's page mapping claims a page whose flag was lost", async () => {
|
test("the campaign's page mapping claims a page whose flag was lost", async () => {
|
||||||
const world = await makeWorld().linkedSetup();
|
const world = await makeWorld().linkedSetup();
|
||||||
const journal = world.addJournal("Dragonroll");
|
const journal = world.addJournal("Dragonroll");
|
||||||
const orphan = world.addPage(journal, { title: { text: "Old name" }, text: { content: "old" } });
|
const orphan = world.addPage(journal, { name: "Old name", text: { content: "old" } });
|
||||||
|
|
||||||
world.remoteNotes = [{ _id: "note-1", title: "Session 1", content: "**The start**", foundryPageId: orphan.id }];
|
world.remoteNotes = [{ _id: "note-1", title: "Session 1", content: "**The start**", foundryPageId: orphan.id }];
|
||||||
await world.runIntervals();
|
await world.runIntervals();
|
||||||
|
|
||||||
assert.equal(journal.pages.contents.length, 1, "no second page under the same title");
|
assert.equal(journal.pages.contents.length, 1, "no second page under the same title");
|
||||||
assert.equal(orphan.title.text, "Session 1");
|
assert.equal(orphan.name, "Session 1");
|
||||||
assert.equal(orphan.getFlag(MODULE_ID, "noteId"), "note-1", "and the page is marked again");
|
assert.equal(orphan.getFlag(MODULE_ID, "noteId"), "note-1", "and the page is marked again");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user