Store the data version for data migrations at some later point

This commit is contained in:
2020-12-05 00:37:43 +01:00
parent 177326dd61
commit 5c31a8abab
2 changed files with 24 additions and 0 deletions

21
main.js
View File

@@ -1,6 +1,7 @@
"use strict";
const settingsKey = "smart-doors";
const currentDataVersion = "1.0.0"
Hooks.once("init", () => {
registerSettings()
@@ -8,6 +9,10 @@ Hooks.once("init", () => {
hookWallConfigUpdate()
})
Hooks.once("ready", () => {
performMigrations()
})
// Tint the source door red when a locked alert is hovered
Hooks.on("renderChatMessage", (message, html, data) => {
// Tint the door that generated this message
@@ -236,8 +241,24 @@ function synchronizedDoorsRightClick() {
return true
}
function performMigrations() {
const dataVersion = game.settings.get(settingsKey, "dataVersion")
if (dataVersion === "fresh install")
{
game.settings.set(settingsKey, "dataVersion", currentDataVersion);
return;
}
if (dataVersion != currentDataVersion)
ui.notifications.error(game.i18n.localize("smart-doors.ui.messages.unknownVersion"), {permanent: true})
}
function registerSettings() {
game.settings.register(settingsKey, "dataVersion", {
scope: "world",
config: false,
type: String,
default: "fresh install"
})
game.settings.register(settingsKey, "lockedDoorAlert", {
name: "smart-doors.settings.lockedDoorAlert.name",
hint: "smart-doors.settings.lockedDoorAlert.hint",