diff --git a/lang/en.json b/lang/en.json index 92299a2..83e0149 100644 --- a/lang/en.json +++ b/lang/en.json @@ -11,6 +11,9 @@ } }, "ui": { + "messages": { + "unknownVersion": "Smart Doors migration failed with the error: Unkown Version. Please report this to the Smart Doors issue tracker. To prevent possible data loss don't use this plugin until this error is fixed." + }, "synchronizedDoors": { "description": "State changes of doors in the same synchronization group will be synchronized across scenes. Leave blank to disable synchronization for this door.", "groupName": "Synchronization Group" diff --git a/main.js b/main.js index 8e827a2..ea3b593 100644 --- a/main.js +++ b/main.js @@ -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",