diff --git a/hench.mjs b/hench.mjs index 09da92e..97da6f6 100644 --- a/hench.mjs +++ b/hench.mjs @@ -1,6 +1,7 @@ import { HenchCard, HenchCardDataModel } from "./module/cards/hench-card.mjs"; import { HenchCards, HenchCardsDataModel } from "./module/cards/hench-cards.mjs"; import { BossDataModel, HenchDataModel } from "./module/data-models.mjs"; +import { CURRENT_VERSION, showUpdateWarningDialogue } from "./module/helpers/update-helper.mjs"; import { HenchActorSheet } from "./module/sheets/hench-actor-sheet.mjs"; import { HenchCardsSheet } from "./module/sheets/hench-cards-sheet.mjs"; @@ -101,4 +102,24 @@ Hooks.once("init", () => { // remove other card stack types... CardStacks.unregisterSheet('core', CardsHand); CardStacks.unregisterSheet('core', CardsPile); + + // prepare version checker + game.settings.register('hench', 'version', { + name: 'Version', + scope: 'world', + config: true, + type: String, + }); +}); + +Hooks.once("ready", () => { + // update version and alert if updated + const existingVersion = game.settings.get('hench', 'version'); + + // TODO: don't alert on null/undefined after draft 1 cut. + if(existingVersion !== CURRENT_VERSION) { + showUpdateWarningDialogue(existingVersion); + } + + game.settings.set('hench', 'version', CURRENT_VERSION); }); \ No newline at end of file diff --git a/module/helpers/update-helper.mjs b/module/helpers/update-helper.mjs new file mode 100644 index 0000000..6854ba2 --- /dev/null +++ b/module/helpers/update-helper.mjs @@ -0,0 +1,72 @@ +export const versions = { + UNDEFINED: '', + DRAFT_0: '0', + DRAFT_1: '1', +}; + +export const CURRENT_VERSION = versions.DRAFT_1; + +const updateMap = { + [versions.UNDEFINED]: versions.DRAFT_0, + [versions.DRAFT_0]: versions.DRAFT_1, +}; + +const updateWarnings = { + [versions.DRAFT_1]: { + title: `Draft 1 Update!`, + content: `The module is now compatible with Draft 1. Due to these changes, we recommend: +
${next.content}
+