Add warning system for updates.

This commit is contained in:
walcutt 2025-01-28 21:22:23 -05:00
parent 4b3ccaa4a4
commit 996c59ef12
2 changed files with 93 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import { HenchCard, HenchCardDataModel } from "./module/cards/hench-card.mjs"; import { HenchCard, HenchCardDataModel } from "./module/cards/hench-card.mjs";
import { HenchCards, HenchCardsDataModel } from "./module/cards/hench-cards.mjs"; import { HenchCards, HenchCardsDataModel } from "./module/cards/hench-cards.mjs";
import { BossDataModel, HenchDataModel } from "./module/data-models.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 { HenchActorSheet } from "./module/sheets/hench-actor-sheet.mjs";
import { HenchCardsSheet } from "./module/sheets/hench-cards-sheet.mjs"; import { HenchCardsSheet } from "./module/sheets/hench-cards-sheet.mjs";
@ -101,4 +102,24 @@ Hooks.once("init", () => {
// remove other card stack types... // remove other card stack types...
CardStacks.unregisterSheet('core', CardsHand); CardStacks.unregisterSheet('core', CardsHand);
CardStacks.unregisterSheet('core', CardsPile); 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);
}); });

View File

@ -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:
<ul>
<li> You create new character sheets for Henches and Bosses, and delete the old ones. </li>
<li> You delete and recreate your deck, or update the Ace of Diamonds and add a joker. </li>
</ul>`,
},
};
function getWarningsSinceVersion(oldVersion) {
const next_v = updateMap[oldVersion];
if(next_v) {
const next_w = updateWarnings[next_v];
if(next_w) {
return [...getWarningsSinceVersion(next_v), next_w];
} else {
return getWarningsSinceVersion(next_v);
}
} else {
return [];
}
}
export function showUpdateWarningDialogue(oldVersion) {
const warnings = getWarningsSinceVersion(oldVersion);
if(warnings?.length > 0) {
const header = ``;
const content = warnings.reduce((prev, next) => {
return prev + `
<div>
<h2>${next.title}</h2>
<p>${next.content}</p>
</div>`;
}, header);
const dialogue = new Dialog({
title: 'Update Notice',
content: content,
buttons: {
one: {
label: 'OK',
callback: () => null,
}
},
default: "one",
});
dialogue.render(true);
return dialogue;
}
}