Skip to content

Commit

Permalink
feat(notification): update notification (#1420)
Browse files Browse the repository at this point in the history
* sends a one-time message when the system migrates versions

#1396
  • Loading branch information
wrycu authored Apr 10, 2024
1 parent 20a2883 commit 6f9a674
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/swffg-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import RollBuilderFFG from "./dice/roll-builder.js";
import CrewSettings from "./settings/crew-settings.js";
import {register_dice_enricher, register_oggdude_tag_enricher, register_roll_tag_enricher} from "./helpers/journal.js";
import {drawAdversaryCount, drawMinionCount, registerTokenControls} from "./helpers/token.js";
import {handleUpdate} from "./swffg-migration.js";

/* -------------------------------------------- */
/* Foundry VTT Initialization */
Expand Down Expand Up @@ -630,6 +631,9 @@ Hooks.once("ready", async () => {
game.settings.set("starwarsffg", "token_configured", true);
}

// NOTE: the "currentVersion" will be updated in handleUpdate, preventing the code below from running in the future
// this is intended to encourage migrating code to this file to clean up the main file
await handleUpdate();

const currentVersion = game.settings.get("starwarsffg", "systemMigrationVersion");

Expand Down
39 changes: 39 additions & 0 deletions modules/swffg-migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Handles all logic related to migrating the system to a new version, including sending notifications
* @returns {Promise<void>}
*/
export async function handleUpdate() {
const registeredVersion = game.settings.get("starwarsffg", "systemMigrationVersion");
const runningVersion = game.system.version;
if (registeredVersion !== runningVersion) {
await handleMigration(runningVersion);
await sendChanges(runningVersion);
await game.settings.set("starwarsffg", "systemMigrationVersion", runningVersion);
}
}

/**
* Handles migration logic for the system
* @param oldVersion - version previously run (from the settings)
* @param newVersion - version currently running (from game.system.version)
* @returns {Promise<void>}
*/
async function handleMigration(oldVersion, newVersion) {
// migration handlers should be added here going forward
}

/**
* Sends a notification to all users in the game that the system has been updated
* @param newVersion - version currently running (from game.system.version)
* @returns {Promise<void>}
*/
async function sendChanges(newVersion) {
const template = "systems/starwarsffg/templates/notifications/new_version.html";
const html = await renderTemplate(template, { version: newVersion });
const messageData = {
user: game.user.id,
type: CONST.CHAT_MESSAGE_TYPES.OTHER,
content: html,
};
ChatMessage.create(messageData);
}
5 changes: 5 additions & 0 deletions styles/mandar.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ section {
background: #d8cbc0 url(../images/bgSheet.jpg) no-repeat;
}

.chat-message.message .message-content .updateNotification {
background: #d8cbc0;
border-radius: 10px;
}

.window-app .window-content::after {
content: "";
display: block;
Expand Down
13 changes: 13 additions & 0 deletions templates/notifications/new_version.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="updateNotification">
<h2>Star Wars FFG v{{ version }}</h2>
Hello! Welcome to a new version of the Star Wars FFG system. :)
<hr>
<div class="updateLinks">
Useful links:<br>
<a href="/~https://github.com/StarWarsFoundryVTT/StarWarsFFG/wiki/new%E2%80%90features%E2%80%90v{{ version }}">Changes to how you interact with the system</a><br>
<a href="/~https://github.com/StarWarsFoundryVTT/StarWarsFFG/blob/main/CHANGELOG.md">Full changelog</a><br>
<a href="/~https://github.com/StarWarsFoundryVTT/StarWarsFFG/wiki">System Wiki</a><br>
</div>
<hr>
This message will show once per version update.
</div>

0 comments on commit 6f9a674

Please sign in to comment.