diff --git a/scripts/brt-main.js b/scripts/brt-main.js index ba52e7fd..b27ca772 100644 --- a/scripts/brt-main.js +++ b/scripts/brt-main.js @@ -2,10 +2,12 @@ import { BetterRT } from './better-table-view.js'; import { BRTCONFIG } from './core/config.js'; import { i18n } from './core/utils.js'; import { BetterTables } from './better-tables.js'; +import VersionCheck from './versioning/version-check.mjs'; +import renderWelcomeScreen from "./versioning/welcome-screen.mjs"; // CONFIG.debug.hooks = true; -Hooks.on("init", function () { +Hooks.on("init", () => { /** checks if the first argument is equal to any of the subsequent arguments */ Handlebars.registerHelper('ifcontain', function () { let options = arguments[arguments.length - 1]; @@ -19,6 +21,12 @@ Hooks.on("init", function () { game.betterTables = new BetterTables(); }); +Hooks.on("ready", () => { + if (VersionCheck.check(BRTCONFIG.NAMESPACE) && game.user.isGM) { + renderWelcomeScreen(); + } +}); + Hooks.on("renderRollTableConfig", BetterRT.enhanceRollTableView); Hooks.on("preUpdateRollTable", BetterRT.preUpdateRollTable); diff --git a/scripts/versioning/version-check.mjs b/scripts/versioning/version-check.mjs new file mode 100644 index 00000000..c2d906d0 --- /dev/null +++ b/scripts/versioning/version-check.mjs @@ -0,0 +1,38 @@ +/** + * Version check function from Forien Unedintified item module + */ +export default class VersionCheck { + static _r = false; + + static _reg(mN) { + if (this._r) return; + + game.settings.register(mN, 'version', { + name: `${mN} Version`, + default: "0.0.0", + type: String, + scope: 'client', + }); + + this._r = true; + } + + static check(mN) { + if (!this._r) this._reg(mN); + + let mV = this.get(mN); + let oV = game.settings.get(mN, "version"); + + return isNewerVersion(mV, oV); + }; + + static set(mN, v) { + if (!this._r) this._reg(mN); + + game.settings.set(mN, "version", v); + } + + static get(mN) { + return game.modules.get(mN).data.version; + } +} diff --git a/scripts/versioning/welcome-screen.mjs b/scripts/versioning/welcome-screen.mjs new file mode 100644 index 00000000..d67ea4bd --- /dev/null +++ b/scripts/versioning/welcome-screen.mjs @@ -0,0 +1,41 @@ +import { BRTCONFIG } from '../core/config.js'; +import VersionCheck from "./version-check.mjs"; + +/** + * Based on https://github.com/Moerill/mess + * modified by Forien + */ +class WelcomeScreen extends Application { + static get defaultOptions() { + let title = game.modules.get(BRTCONFIG.NAMESPACE).data.title; + return mergeObject(super.defaultOptions, { + template: `modules/${BRTCONFIG.NAMESPACE}/templates/welcome-screen.html`, + resizable: true, + width: 450, + height: 636, + classes: ["welcome-screen"], + title: `${title} - Welcome Screen` + }); + } + + getData(options = {}) { + options = super.getData(options);; + options.isChecked = !VersionCheck.check(BRTCONFIG.NAMESPACE); + return options; + } + + activateListeners(html) { + super.activateListeners(html); + + html.find('.show-again').on('change', event => { + let version = "0.0.0"; + if (event.currentTarget.checked) + version = VersionCheck.get(BRTCONFIG.NAMESPACE); + VersionCheck.set(BRTCONFIG.NAMESPACE, version) + }) + } +} + +export default function renderWelcomeScreen() { + (new WelcomeScreen()).render(true); +} diff --git a/templates/welcome-screen.html b/templates/welcome-screen.html new file mode 100644 index 00000000..36541cc8 --- /dev/null +++ b/templates/welcome-screen.html @@ -0,0 +1,37 @@ + + + +

Welcome to Better RollTables!

+

Check the README or wiki for more info on the module features

+

Youtube Better Tables Overview!

+

Bugs or Suggestions?

+

Add an issue on Github or drop me a line on Discord!

+ +

Ultrakorne#6240

+ +

+

My Tip Jar: Paypal

+ +

Patchnotes

+

v1.4.0

+ +

v1.3.0

+ \ No newline at end of file