From 7ab88dfee5ce923ca660b317d5f133a123f8cdc7 Mon Sep 17 00:00:00 2001 From: ardittristan Date: Mon, 27 Jul 2020 23:55:19 +0200 Subject: [PATCH] add popup for when colorsettings is installed but not enabled --- CHANGELOG.md | 4 ++++ colorSetting.js | 43 ++++++++++++++++++++++++++++++++----------- module.json | 2 +- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39cc674..daa9e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.4.1 + +* Added one-time popup that asks the user if they want to enable colorsettings if it is installed but not enabled (when running as included library). + ## 2.4.0 * Deprecated the use of `id="permanent"` in favor of `data-permanent` diff --git a/colorSetting.js b/colorSetting.js index bca2a67..e7c17c2 100644 --- a/colorSetting.js +++ b/colorSetting.js @@ -254,9 +254,9 @@ class colorPickerInput extends HTMLInputElement { }); } - if(this.dataset.responsiveColor !== undefined && this.value != undefined && this.value.length != 0 && this.value.startsWith("#") && this.value.match(/[^A-Fa-f0-9#]+/g) == null) { - this.style.backgroundColor = this.value - this.style.color = getTextColor(this.value) + if (this.dataset.responsiveColor !== undefined && this.value != undefined && this.value.length != 0 && this.value.startsWith("#") && this.value.match(/[^A-Fa-f0-9#]+/g) == null) { + this.style.backgroundColor = this.value; + this.style.color = getTextColor(this.value); } } @@ -322,18 +322,18 @@ class colorPickerButton extends HTMLButtonElement { this._makePicker = this._makePicker.bind(this); this.visible = false; // check if picker should be always shown. - + this.addEventListener("click", (event) => { - event.preventDefault() + event.preventDefault(); if (!this.visible) { this.visible = true; this._makePicker(); } }); - if(this.dataset.responsiveColor !== undefined && this.value != undefined && this.value.length != 0 && this.value.startsWith("#") && this.value.match(/[^A-Fa-f0-9#]+/g) == null) { - this.style.backgroundColor = this.value - this.style.color = getTextColor(this.value) + if (this.dataset.responsiveColor !== undefined && this.value != undefined && this.value.length != 0 && this.value.startsWith("#") && this.value.match(/[^A-Fa-f0-9#]+/g) == null) { + this.style.backgroundColor = this.value; + this.style.color = getTextColor(this.value); } } @@ -350,7 +350,7 @@ class colorPickerButton extends HTMLButtonElement { parent: this.parentElement, cancelButton: true, onDone: (color) => { - + this.picker.destroy(); this.visible = false; Hooks.call('pickerDone', @@ -367,7 +367,7 @@ class colorPickerButton extends HTMLButtonElement { } }); - jQuery(this.picker.domElement).insertAfter(this) + jQuery(this.picker.domElement).insertAfter(this); if (this.picker._domCancel) { this.picker._domCancel.textContent = " Eye Dropper"; @@ -521,9 +521,30 @@ Hooks.once('init', function () { /** @type {String} */ const scriptLocation = getRunningScript()(); if (!scriptLocation.includes("modules/colorsettings/")) { - if (game.modules.get("colorsettings")) { + if (game.modules.has("colorsettings")) { if (game.modules.get("colorsettings").active) { return; + } else { + game.settings.register("colorsettings", "autoEnable", { + config: false, + type: Boolean, + default: true + }) + Hooks.once("canvasReady", () => { + if (game.user.isGM && game.settings.get("colorsettings", "autoEnable")) { + Dialog.confirm({ + title: "Enable Color Settings module?", + content: "

You seem to have Color Settings installed already, do you want to enable it?

", + yes: () => game.settings.set("core", ModuleManagement.CONFIG_SETTING, { + ...game.settings.get("core", ModuleManagement.CONFIG_SETTING), + ...{ colorsettings: true } + }), + no: () => game.settings.set("colorsettings", "autoEnable", false), + defaultYes: false + }); + + } + }); } } diff --git a/module.json b/module.json index 5994f9a..4d01394 100644 --- a/module.json +++ b/module.json @@ -2,7 +2,7 @@ "name": "colorsettings", "title": "lib - Color Settings", "description": "Library that allows modules to add color settings and forms.", - "version": "2.4.0", + "version": "2.4.1", "author": "ardittristan#0001", "esmodules": ["colorSetting.js"], "socket": true,