Skip to content

Commit 5bbbe9a

Browse files
Added support for migrating notes from Simple Calendar
1 parent 3867f99 commit 5bbbe9a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/classes/applications/configuration-app.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
GameWorldTimeIntegrations,
1010
Icons,
1111
LeapYearRules,
12+
LegacyModuleName,
1213
ModuleName,
1314
MoonYearResetOptions,
1415
NoteReminderNotificationType,
@@ -1854,13 +1855,24 @@ export default class ConfigurationApp extends FormApplication {
18541855
const calendarId = (newCalId || importCalendar?.id || calId).replace("_temp", "");
18551856
for (let n = 0; n < data.notes[calId].length; n++) {
18561857
const journalEntryData = data.notes[calId][n];
1857-
const noteImportedIntoDifferentCalendar = !(journalEntryData.flags[ModuleName].noteData.calendarId === calendarId);
1858-
journalEntryData.flags[ModuleName].noteData.calendarId = calendarId;
1859-
journalEntryData.folder = NManager.noteDirectory?.id;
1860-
if (noteImportedIntoDifferentCalendar || !(<Game>game).journal?.has(journalEntryData._id)) {
1861-
await JournalEntry.create(journalEntryData, { keepId: !noteImportedIntoDifferentCalendar });
1862-
} else {
1863-
(<Game>game).journal?.get(journalEntryData._id)?.update(journalEntryData);
1858+
const noteData = journalEntryData.flags[ModuleName]?.noteData || journalEntryData.flags[LegacyModuleName]?.noteData;
1859+
if (noteData) {
1860+
const noteImportedIntoDifferentCalendar = !(noteData.calendarId === calendarId);
1861+
// add logic to determine if this entry came from the original version of SC, and if so, convert it to the new format
1862+
const isConverted = !journalEntryData.flags[ModuleName];
1863+
if (isConverted) {
1864+
journalEntryData.flags[ModuleName] = journalEntryData.flags[LegacyModuleName];
1865+
journalEntryData.flags["core"].sheetClass = ModuleName + ".NoteSheet";
1866+
journalEntryData.flags[LegacyModuleName] = undefined;
1867+
} else journalEntryData.flags[ModuleName].noteData = noteData;
1868+
1869+
journalEntryData.flags[ModuleName].noteData.calendarId = calendarId;
1870+
journalEntryData.folder = NManager.noteDirectory?.id;
1871+
if (noteImportedIntoDifferentCalendar || !(<Game>game).journal?.has(journalEntryData._id) || isConverted) {
1872+
await JournalEntry.create(journalEntryData, { keepId: !noteImportedIntoDifferentCalendar });
1873+
} else {
1874+
(<Game>game).journal?.get(journalEntryData._id)?.update(journalEntryData);
1875+
}
18641876
}
18651877
}
18661878
}

src/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* @internal
44
*/
55
export const ModuleName = "foundryvtt-simple-calendar-reborn";
6-
6+
/**
7+
* The original name of this module, used for backwards compatibility.
8+
* @internal
9+
*/
10+
export const LegacyModuleName = "foundryvtt-simple-calendar";
711
/**
812
* The name of the module specific socket
913
* @internal

0 commit comments

Comments
 (0)