diff --git a/CHANGELOG.md b/CHANGELOG.md index ced166b..4db61df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.2.2 + +- Changed settings from world to client, so users can save their settings now... + - *IMPORTANT* This will reset your settings! +- bumped compatibel core version + # v1.2.1 - Moved the GSAP import to be a relative instead of absolute path, to allow for it to work with FoundryInstances running with the routePrefix option. diff --git a/js/settings.js b/js/settings.js index b53727c..1db58a9 100644 --- a/js/settings.js +++ b/js/settings.js @@ -1,78 +1,78 @@ -export const moduleName = 'chat-notifications'; +export const moduleName = "chat-notifications"; export let maxMessages = 3; export let fadeOutDelay = 3; export class ChatNotificationSettings extends FormApplication { - static init() { - game.settings.registerMenu(moduleName, 'menu', { - name: '', - label: 'Settings', - icon: 'fas fa-mug-hot', + static init() { + game.settings.registerMenu(moduleName, "menu", { + name: "", + label: "Settings", + icon: "fas fa-mug-hot", type: ChatNotificationSettings, - restricted: false + restricted: false, }); game.settings.register(moduleName, game.user.id, { name: "User settings.", - scope: "world", + scope: "client", config: false, type: Object, default: { top: 0, left: 0, - direction: 'column', + direction: "column", maxMessages: 3, fadeOutDelay: 3, opacity: 1, - anchor: 'bottom' + anchor: "bottom", }, - onChange: data => { + onChange: (data) => { const el = document.querySelector(`.${moduleName}`); - el.style.setProperty('--top', data.top + '%'); - el.style.setProperty('--left', data.left + '%'); - el.style.setProperty('--direction', data.direction); + el.style.setProperty("--top", data.top + "%"); + el.style.setProperty("--left", data.left + "%"); + el.style.setProperty("--direction", data.direction); maxMessages = data.maxMessages; fadeOutDelay = data.fadeOutDelay; - } + }, }); const settingsData = game.settings.get(moduleName, game.user.id); maxMessages = settingsData.maxMessages; fadeOutDelay = settingsData.fadeOutDelay; const notifs = document.querySelector(`.${moduleName}`); - notifs.style.setProperty('--top', settingsData.top + '%'); - notifs.style.setProperty('--left', settingsData.left + '%'); - notifs.style.setProperty('--opacity', settingsData.opacity || 1); - notifs.style.setProperty('--direction', settingsData.direction); - if (settingsData.anchor === 'top') { - notifs.style.top = 'var(--top)'; + notifs.style.setProperty("--top", settingsData.top + "%"); + notifs.style.setProperty("--left", settingsData.left + "%"); + notifs.style.setProperty("--opacity", settingsData.opacity || 1); + notifs.style.setProperty("--direction", settingsData.direction); + if (settingsData.anchor === "top") { + notifs.style.top = "var(--top)"; notifs.style.bottom = null; } else { - notifs.style.bottom = 'var(--top)'; + notifs.style.bottom = "var(--top)"; notifs.style.top = null; } } - static get defaultOptions() { - return { - ...super.defaultOptions, - template: 'modules/chat-notifications/html/settings.html', - height: 'auto', - title: 'Hey, listen! - Chat Notification Settings', - width: 600, - classes: [moduleName, 'settings'], - tabs: [ - { - navSelector: '.tabs', - contentSelector: 'form', - initial: 'info' - } - ], - submitOnClose: true - } - } - - constructor(object = {}, options) { + static get defaultOptions() { + return { + ...super.defaultOptions, + template: "modules/chat-notifications/html/settings.html", + height: "auto", + title: "Hey, listen! - Chat Notification Settings", + width: 600, + classes: [moduleName, "settings"], + tabs: [ + { + navSelector: ".tabs", + contentSelector: "form", + initial: "info", + }, + ], + submitOnClose: true, + }; + } + + constructor(object = {}, options) { super(object, options); this._notifications = document.querySelector(`.${moduleName}`); } @@ -91,66 +91,67 @@ export class ChatNotificationSettings extends FormApplication { _clearPreview() { this._notifications.style.zIndex = null; - for (let child of Array.from(this._notifications.children)) - child.remove(); + for (let child of Array.from(this._notifications.children)) child.remove(); } _showPreview() { fadeOutDelay = -1; const notifications = this._notifications; - notifications.style.zIndex = this.form.closest('.app')?.style.zIndex - 1; - const log = document.getElementById('chat-log'); - - for (let i = 1; i <= maxMessages && i < log.children.length; i++) - notifications.appendChild(log.children[log.children.length - i].cloneNode(true)) + notifications.style.zIndex = this.form.closest(".app")?.style.zIndex - 1; + const log = document.getElementById("chat-log"); + for (let i = 1; i <= maxMessages && i < log.children.length; i++) + notifications.appendChild( + log.children[log.children.length - i].cloneNode(true) + ); } _updatePreview() { const html = this.form; - const top = html.querySelector('[name="top"]').value + '%'; - const left = html.querySelector('[name="left"]').value + '%'; - this._notifications.style.setProperty('--top', top); - this._notifications.style.setProperty('--left', left); + const top = html.querySelector('[name="top"]').value + "%"; + const left = html.querySelector('[name="left"]').value + "%"; + this._notifications.style.setProperty("--top", top); + this._notifications.style.setProperty("--left", left); const max = Number(html.querySelector('[name="maxMessages"]').value) || 3; if (max != maxMessages) { maxMessages = max; - this._clearPreview(); this._showPreview(); + this._clearPreview(); + this._showPreview(); } const direction = html.querySelector('[name="direction"]').value; - this._notifications.style.setProperty('--direction', direction); + this._notifications.style.setProperty("--direction", direction); const opacity = html.querySelector('[name="opacity"]').value; - this._notifications.style.setProperty('--opacity', opacity); + this._notifications.style.setProperty("--opacity", opacity); const anchor = html.querySelector('[name="anchor"]').value; - if (anchor === 'top') { - this._notifications.style.top = 'var(--top)'; + if (anchor === "top") { + this._notifications.style.top = "var(--top)"; this._notifications.style.bottom = null; } else { - this._notifications.style.bottom = 'var(--top)'; + this._notifications.style.bottom = "var(--top)"; this._notifications.style.top = null; } } - _getHeaderButtons() { - let btns = super._getHeaderButtons(); - btns[0].label = "Save & Close"; - return btns; - } + _getHeaderButtons() { + let btns = super._getHeaderButtons(); + btns[0].label = "Save & Close"; + return btns; + } - getSettingsData() { - return game.settings.get(moduleName, game.user.id); - } + getSettingsData() { + return game.settings.get(moduleName, game.user.id); + } - getData() { - let data = super.getData(); + getData() { + let data = super.getData(); data.settings = this.getSettingsData(); - return data; + return data; } - + _onWheelNumberEvent(ev) { const target = ev.currentTarget; let val = Number(target.value) || 0; @@ -160,18 +161,22 @@ export class ChatNotificationSettings extends FormApplication { this._updatePreview(); } - activateListeners(html) { + activateListeners(html) { super.activateListeners(html); - html[0].querySelectorAll('input[data-dtype="Number"]').forEach(e => { - e.addEventListener('wheel', this._onWheelNumberEvent.bind(this)); + html[0].querySelectorAll('input[data-dtype="Number"]').forEach((e) => { + e.addEventListener("wheel", this._onWheelNumberEvent.bind(this)); }); - html[0].querySelectorAll('input, select').forEach(e => e.addEventListener('change', this._updatePreview.bind(this))) - } + html[0] + .querySelectorAll("input, select") + .forEach((e) => + e.addEventListener("change", this._updatePreview.bind(this)) + ); + } - _updateObject(ev, formData) { + _updateObject(ev, formData) { const data = expandObject(formData); game.settings.set(moduleName, game.user.id, data); - } -} \ No newline at end of file + } +} diff --git a/module.json b/module.json index 3d15980..ab1ee9a 100644 --- a/module.json +++ b/module.json @@ -2,15 +2,15 @@ "name": "chat-notifications", "title": "Hey, listen! - Chat Notifications", "description": "This module shows notifications of the newest chat messages, when you're currently not viewing the chat tab.
Position, opacity, fade delay, ... is all customizable!", - "version": "1.2.1", + "version": "1.2.2", "author": "Moerill", "esmodules": ["js/index.js"], "styles": [ "chat-notifications.css" ], "minimumCoreVersion": "0.7.4", - "compatibleCoreVersion": "0.7.5", + "compatibleCoreVersion": "0.7.9", "manifest": "https://raw.githubusercontent.com/Moerill/fvtt-chat-notifications/master/module.json", - "download": "https://github.com/Moerill/fvtt-chat-notifications/releases/download/v1.2.1/v1.2.1.zip", + "download": "https://github.com/Moerill/fvtt-chat-notifications/releases/download/v1.2.2/v1.2.2.zip", "url": "https://github.com/Moerill/fvtt-chat-notifications" } \ No newline at end of file diff --git a/package.json b/package.json index 01fbc5f..be260e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "module-template", - "version": "1.2.1", + "version": "1.2.2", "description": "", "scripts": { "test": "echo \"Error: no test specified\" && exit 1"