From f7b42bcf11ea24b700486fe447c5d04c702a9504 Mon Sep 17 00:00:00 2001 From: Forien Date: Tue, 23 Jun 2020 13:33:16 +0200 Subject: [PATCH] v0.3.3 (#36) * Fixed editable inputs cutting off text after double quotation character * Added popup when attempting to close the Quest Form window without submitting. * Added option to link quests in rich text environments with `@Quest[id]` and `@Quest[quest name]`. Hacky way, might be unstable. * Added Configuration setting that allows GM turn off displaying Welcome Screen to players. Enabled by default * Added "Help" button in Quest Log's header that allows to open Welcome Screen at any time. --- changelog.md | 7 ++++ lang/en.json | 12 ++++++ lang/missing/de.json | 11 +++++- lang/missing/fr.json | 10 ++++- lang/missing/ja.json | 11 +++++- lang/missing/ko.json | 10 ++++- lang/pl.json | 9 +++++ module.json | 8 ++-- modules/api/hooks.js | 11 ++++++ modules/apps/quest-form.mjs | 39 +++++++++++++++++-- modules/apps/quest-log.mjs | 14 +++++++ modules/apps/quest-preview.mjs | 1 + .../entities/collection/quests-collection.mjs | 28 +++++++++++++ modules/entities/quest.mjs | 11 ++++++ modules/init.mjs | 11 +++++- modules/utility/config.mjs | 29 +++++++++----- modules/versioning/welcome-screen.mjs | 1 + templates/welcome-screen.html | 10 ++++- 18 files changed, 208 insertions(+), 25 deletions(-) create mode 100644 modules/entities/collection/quests-collection.mjs diff --git a/changelog.md b/changelog.md index fa660f61..05bec6b6 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,13 @@ ## v0.3.X +### v0.3.3 +* Fixed editable inputs cutting off text after double quotation character +* Added popup when attempting to close the Quest Form window without submitting. +* Added option to link quests in rich text environments with `@Quest[id]` and `@Quest[quest name]`. Hacky way, might be unstable. +* Added Configuration setting that allows GM turn off displaying Welcome Screen to players. Enabled by default +* Added "Help" button in Quest Log's header that allows to open Welcome Screen at any time. + ### v0.3.2 * Added French translation provided by Discord members rectulo and Naoki * Abstract Rewards now are a little transparent (0.9 opacity) and their text is in italic diff --git a/lang/en.json b/lang/en.json index 79adb286..89d30825 100644 --- a/lang/en.json +++ b/lang/en.json @@ -77,6 +77,14 @@ "Cancel": "Cancel" }, + "CloseDialog": { + "Title": "Leave Form", + "Header": "Are you sure?", + "Body": "Are you sure you want to close the form? Unsaved data will be lost.", + "Discard": "Discard changes", + "Cancel": "Cancel" + }, + "Notifications": { "CannotOpen": "Cannot open Quest Details. You may lack permissions, Quest might not exist anymore, or provided ID was invalid.", "UserCantOpen": "User {user} doesn't have permission to open this quest.", @@ -115,6 +123,10 @@ "EnableHint": "Decide how to position quests' titles in Quest Log's table.", "left": "Aligned to left", "center": "Centered" + }, + "playersWelcomeScreen": { + "Enable": "Display Welcome Screen to Players", + "EnableHint": "Uncheck to prevent players from seeing Welcome Screen on log in after an update. They might still see it by clicking 'help' icon in Quest Log." } }, diff --git a/lang/missing/de.json b/lang/missing/de.json index 4ea03dae..713a9d6d 100644 --- a/lang/missing/de.json +++ b/lang/missing/de.json @@ -3,6 +3,11 @@ "ForienQuestLog.Api.hooks.createOpenQuestMacro.name": "", "ForienQuestLog.Notifications.CannotOpen": "", "ForienQuestLog.Api.create.title": "", + "ForienQuestLog.CloseDialog.Title": "", + "ForienQuestLog.CloseDialog.Header": "", + "ForienQuestLog.CloseDialog.Body": "", + "ForienQuestLog.CloseDialog.Cancel": "", + "ForienQuestLog.CloseDialog.Discard": "", "ForienQuestLog.QuestPreview.InvalidQuestId": "", "ForienQuestLog.QuestPreview.HeaderButtons.Show": "", "ForienQuestLog.SampleReward": "", @@ -11,12 +16,14 @@ "ForienQuestLog.Api.reward.create.type": "", "ForienQuestLog.Api.reward.create.data": "", "ForienQuestLog.Api.task.create.name": "", - "ForienQuestLog.Settings.showFolder.Enable": "", - "ForienQuestLog.Settings.showFolder.EnableHint": "", "ForienQuestLog.Settings.availableQuests.Enable": "", "ForienQuestLog.Settings.availableQuests.EnableHint": "", "ForienQuestLog.Settings.allowPlayersDrag.Enable": "", "ForienQuestLog.Settings.allowPlayersDrag.EnableHint": "", + "ForienQuestLog.Settings.playersWelcomeScreen.Enable": "", + "ForienQuestLog.Settings.playersWelcomeScreen.EnableHint": "", + "ForienQuestLog.Settings.showFolder.Enable": "", + "ForienQuestLog.Settings.showFolder.EnableHint": "", "ForienQuestLog.Notifications.UserCantOpen": "", "ForienQuestLog.Tooltips.SetAvailable": "", "ForienQuestLog.Tooltips.TaskHidden": "", diff --git a/lang/missing/fr.json b/lang/missing/fr.json index 9e26dfee..8f658425 100644 --- a/lang/missing/fr.json +++ b/lang/missing/fr.json @@ -1 +1,9 @@ -{} \ No newline at end of file +{ + "ForienQuestLog.CloseDialog.Title": "", + "ForienQuestLog.CloseDialog.Header": "", + "ForienQuestLog.CloseDialog.Body": "", + "ForienQuestLog.CloseDialog.Cancel": "", + "ForienQuestLog.CloseDialog.Discard": "", + "ForienQuestLog.Settings.playersWelcomeScreen.Enable": "", + "ForienQuestLog.Settings.playersWelcomeScreen.EnableHint": "" +} \ No newline at end of file diff --git a/lang/missing/ja.json b/lang/missing/ja.json index 4ea03dae..713a9d6d 100644 --- a/lang/missing/ja.json +++ b/lang/missing/ja.json @@ -3,6 +3,11 @@ "ForienQuestLog.Api.hooks.createOpenQuestMacro.name": "", "ForienQuestLog.Notifications.CannotOpen": "", "ForienQuestLog.Api.create.title": "", + "ForienQuestLog.CloseDialog.Title": "", + "ForienQuestLog.CloseDialog.Header": "", + "ForienQuestLog.CloseDialog.Body": "", + "ForienQuestLog.CloseDialog.Cancel": "", + "ForienQuestLog.CloseDialog.Discard": "", "ForienQuestLog.QuestPreview.InvalidQuestId": "", "ForienQuestLog.QuestPreview.HeaderButtons.Show": "", "ForienQuestLog.SampleReward": "", @@ -11,12 +16,14 @@ "ForienQuestLog.Api.reward.create.type": "", "ForienQuestLog.Api.reward.create.data": "", "ForienQuestLog.Api.task.create.name": "", - "ForienQuestLog.Settings.showFolder.Enable": "", - "ForienQuestLog.Settings.showFolder.EnableHint": "", "ForienQuestLog.Settings.availableQuests.Enable": "", "ForienQuestLog.Settings.availableQuests.EnableHint": "", "ForienQuestLog.Settings.allowPlayersDrag.Enable": "", "ForienQuestLog.Settings.allowPlayersDrag.EnableHint": "", + "ForienQuestLog.Settings.playersWelcomeScreen.Enable": "", + "ForienQuestLog.Settings.playersWelcomeScreen.EnableHint": "", + "ForienQuestLog.Settings.showFolder.Enable": "", + "ForienQuestLog.Settings.showFolder.EnableHint": "", "ForienQuestLog.Notifications.UserCantOpen": "", "ForienQuestLog.Tooltips.SetAvailable": "", "ForienQuestLog.Tooltips.TaskHidden": "", diff --git a/lang/missing/ko.json b/lang/missing/ko.json index 9e26dfee..8f658425 100644 --- a/lang/missing/ko.json +++ b/lang/missing/ko.json @@ -1 +1,9 @@ -{} \ No newline at end of file +{ + "ForienQuestLog.CloseDialog.Title": "", + "ForienQuestLog.CloseDialog.Header": "", + "ForienQuestLog.CloseDialog.Body": "", + "ForienQuestLog.CloseDialog.Cancel": "", + "ForienQuestLog.CloseDialog.Discard": "", + "ForienQuestLog.Settings.playersWelcomeScreen.Enable": "", + "ForienQuestLog.Settings.playersWelcomeScreen.EnableHint": "" +} \ No newline at end of file diff --git a/lang/pl.json b/lang/pl.json index 57ea0cde..8105eb2c 100644 --- a/lang/pl.json +++ b/lang/pl.json @@ -52,6 +52,9 @@ "ForienQuestLog.Settings.titleAlign.left": "Wyrównaj do lewej", "ForienQuestLog.Settings.titleAlign.center": "Wyśrodkuj", + "ForienQuestLog.Settings.playersWelcomeScreen.Enable": "Pokazuj graczom Ekran Powitalny", + "ForienQuestLog.Settings.playersWelcomeScreen.EnableHint": "Odznacz, aby graczom nie wyświetlać po zalogowaniu Ekranu Powitalnego z każdą nową wersją. Gracze wciąż mogą go wyświetlić klikając na ikonę \"pomocy\" w Dzienniku Misji.",",", + "ForienQuestLog.QuestForm.Title": "Stwórz nową Misję", "ForienQuestLog.QuestForm.QuestGiver": "Zleceniodawca", "ForienQuestLog.QuestForm.QuestGiverPlaceholder": "Imię lub ID Aktora", @@ -81,6 +84,12 @@ "ForienQuestLog.DeleteDialog.Delete": "Usuń", "ForienQuestLog.DeleteDialog.Cancel": "Anuluj", + "ForienQuestLog.CloseDialog.Title": "Opuszczasz formularz", + "ForienQuestLog.CloseDialog.Header": "Czy na pewno?", + "ForienQuestLog.CloseDialog.Body": "Opuszczasz formularz bez zapisania go. Jeśli to zrobisz, utracisz niezapisane zmiany.", + "ForienQuestLog.CloseDialog.Cancel": "Anuluj", + "ForienQuestLog.CloseDialog.Discard": "Odrzuć zmiany", + "ForienQuestLog.Tooltips.ToggleImage": "Przełącz obraz Aktora/Tokenu", "ForienQuestLog.Tooltips.SetActive": "Ustaw na Aktywną", "ForienQuestLog.Tooltips.SetCompleted": "Ustaw jako Zakończoną", diff --git a/module.json b/module.json index 9b3edb4e..0af36e3b 100644 --- a/module.json +++ b/module.json @@ -9,14 +9,14 @@ "url": "https://www.patreon.com/forien" } ], - "version": "0.3.2", + "version": "0.3.3", "minimumCoreVersion": "0.6.0", "compatibleCoreVersion": "0.6.3", "url": "https://github.com/Forien/foundryvtt-forien-quest-log", "manifest": "https://raw.githubusercontent.com/Forien/foundryvtt-forien-quest-log/master/module.json", - "download": "https://github.com/Forien/foundryvtt-forien-quest-log/releases/download/v0.3.2/v0.3.2.zip", - "readme": "https://github.com/Forien/foundryvtt-forien-quest-log/blob/v0.3.2/README.md", - "changelog": "https://github.com/Forien/foundryvtt-forien-quest-log/blob/v0.3.2/changelog.md", + "download": "https://github.com/Forien/foundryvtt-forien-quest-log/releases/download/v0.3.3/v0.3.3.zip", + "readme": "https://github.com/Forien/foundryvtt-forien-quest-log/blob/v0.3.3/README.md", + "changelog": "https://github.com/Forien/foundryvtt-forien-quest-log/blob/v0.3.3/changelog.md", "bugs": "https://github.com/Forien/foundryvtt-forien-quest-log/issues", "languages": [ { diff --git a/modules/api/hooks.js b/modules/api/hooks.js index 5b996072..dcd05cec 100644 --- a/modules/api/hooks.js +++ b/modules/api/hooks.js @@ -38,4 +38,15 @@ export default function registerApiHooks() { } return false; }); + + // open quest details on link click + $('body').on("click", "a.entity-link[data-entity='Quest']", function (event) { + event.preventDefault(); + event.stopImmediatePropagation(); + const a = event.currentTarget; + + Quests.open(a.dataset.id); + + return false; + }); } diff --git a/modules/apps/quest-form.mjs b/modules/apps/quest-form.mjs index 6fc0f108..93d5689f 100644 --- a/modules/apps/quest-form.mjs +++ b/modules/apps/quest-form.mjs @@ -5,6 +5,8 @@ import Quest from "../entities/quest.mjs"; import Socket from "../utility/socket.mjs"; export default class QuestForm extends FormApplication { + submitted = false; + /** * Default Application options * @@ -49,7 +51,6 @@ export default class QuestForm extends FormApplication { * * @param event * @param formData - * @returns {Promise} * @private */ async _updateObject(event, formData) { @@ -88,17 +89,49 @@ export default class QuestForm extends FormApplication { let folder = this.getHiddenFolder(); - JournalEntry.create({ + return JournalEntry.create({ name: title, content: JSON.stringify(data), folder: folder._id - }).then(() => { + }).then((promise) => { QuestLog.render(true); // players don't see Hidden tab, but assistant GM can, so emit anyway Socket.refreshQuestLog(); + this.submitted = true; + return promise; }); } + + async close() { + if (this.submitted) { + return super.close(); + } + + new Dialog({ + title: game.i18n.localize("ForienQuestLog.CloseDialog.Title"), + content: `

${game.i18n.localize("ForienQuestLog.CloseDialog.Header")}

+

${game.i18n.localize("ForienQuestLog.CloseDialog.Body")}

`, + buttons: { + no: { + icon: ``, + label: game.i18n.localize("ForienQuestLog.CloseDialog.Cancel") + }, + yes: { + icon: ``, + label: game.i18n.localize("ForienQuestLog.CloseDialog.Discard"), + callback: () => { + this.submitted = true; + this.close(); + } + } + }, + default: "no" + }).render(true); + + + } + /** * Fired whenever any of TinyMCE editors is saved. * Just pass data to object's property, we handle save in one go after submit diff --git a/modules/apps/quest-log.mjs b/modules/apps/quest-log.mjs index d044040b..140b6e3e 100644 --- a/modules/apps/quest-log.mjs +++ b/modules/apps/quest-log.mjs @@ -1,6 +1,7 @@ import Quest from "../entities/quest.mjs"; import QuestPreview from "./quest-preview.mjs"; import QuestForm from "./quest-form.mjs"; +import renderWelcomeScreen from "../versioning/welcome-screen.mjs"; export default class QuestLog extends Application { sortBy = null; @@ -25,6 +26,19 @@ export default class QuestLog extends Application { }); } + _getHeaderButtons() { + const buttons = super._getHeaderButtons(); + + buttons.unshift({ + label: "", + class: "help", + icon: "fas fa-question-circle", + onclick: ev => renderWelcomeScreen() + }); + + return buttons + } + /** * Retrieves Data to be used in rendering template. * diff --git a/modules/apps/quest-preview.mjs b/modules/apps/quest-preview.mjs index df831bbc..c36edfcb 100644 --- a/modules/apps/quest-preview.mjs +++ b/modules/apps/quest-preview.mjs @@ -240,6 +240,7 @@ export default class QuestPreview extends FormApplication { value = this.quest.tasks[index].name; } + value = value.replace(/"/g, '"'); let input = $(``); let parent = $(event.target).parent('.editable-container'); diff --git a/modules/entities/collection/quests-collection.mjs b/modules/entities/collection/quests-collection.mjs new file mode 100644 index 00000000..96a2e229 --- /dev/null +++ b/modules/entities/collection/quests-collection.mjs @@ -0,0 +1,28 @@ +/** + * Class that acts "kind of" like Entity, to help Manage everything Quest Related + * in a more structured way, than to call JournalEntry every time. + */ +import Quest from "../quest.mjs"; + +export default class QuestsCollection { + constructor() { + let quests = Quest.getQuests(); + let entities = [...quests.active, ...quests.completed, ...quests.failed, ...quests.hidden]; + + this.entities = entities.map(e => { + let data = e; + data.name = data.title; + + return { + _id: e.id, + id: e.id, + name: e.title, + data: data + } + }) + } + + get(questId) { + return Quest.get(questId); + } +} diff --git a/modules/entities/quest.mjs b/modules/entities/quest.mjs index a7eff8df..fa660c2f 100644 --- a/modules/entities/quest.mjs +++ b/modules/entities/quest.mjs @@ -3,6 +3,7 @@ import Utils from "../utility/utils.mjs"; import QuestFolder from "./quest-folder.mjs"; import Reward from "./reward.mjs"; import Task from "./task.mjs"; +import QuestsCollection from "./collection/quests-collection.mjs"; /** * Class that acts "kind of" like Entity, to help Manage everything Quest Related @@ -535,6 +536,14 @@ export default class Quest { this._personal = (value === true); } + static get collection() { + return new QuestsCollection(); + } + + get name() { + return this._title; + } + toJSON() { return { actor: this._actor, @@ -548,3 +557,5 @@ export default class Quest { } } } + +window.Quest = Quest; \ No newline at end of file diff --git a/modules/init.mjs b/modules/init.mjs index 01fe6dbf..3a63d5f8 100644 --- a/modules/init.mjs +++ b/modules/init.mjs @@ -8,11 +8,18 @@ import Socket from "./utility/socket.mjs"; import Utils from "./utility/utils.mjs"; import VersionCheck from "./versioning/version-check.mjs"; import renderWelcomeScreen from "./versioning/welcome-screen.mjs"; +import Quest from "./entities/quest.mjs"; Hooks.once('init', () => { ModuleSettings.register(); + CONST.ENTITY_LINK_TYPES.push("Quest"); + CONFIG["Quest"] = { + entityClass: Quest, + sidebarIcon: 'far fa-question-circle', + }; + Utils.preloadTemplates(); Hooks.callAll("ForienQuestLog.afterInit"); @@ -29,7 +36,9 @@ Hooks.once("ready", () => { QuestFolder.initializeJournals(); if (VersionCheck.check(constants.moduleName)) { - renderWelcomeScreen(); + if (game.user.isGM || game.settings.get('forien-quest-log', 'playersWelcomeScreen')) { + renderWelcomeScreen(); + } Utils.updateMacros(); } diff --git a/modules/utility/config.mjs b/modules/utility/config.mjs index 74c3ea2e..195959ee 100644 --- a/modules/utility/config.mjs +++ b/modules/utility/config.mjs @@ -3,16 +3,6 @@ export default class ModuleSettings { * Registers various configuration settings for Module */ static register() { - game.settings.register("forien-quest-log", "showFolder", { - name: "ForienQuestLog.Settings.showFolder.Enable", - hint: "ForienQuestLog.Settings.showFolder.EnableHint", - scope: "world", - config: true, - default: false, - type: Boolean, - onChange: value => game.journal.render() - }); - game.settings.register("forien-quest-log", "availableQuests", { name: "ForienQuestLog.Settings.availableQuests.Enable", hint: "ForienQuestLog.Settings.availableQuests.EnableHint", @@ -90,5 +80,24 @@ export default class ModuleSettings { QuestLog.render(); } }); + + game.settings.register("forien-quest-log", "playersWelcomeScreen", { + name: "ForienQuestLog.Settings.playersWelcomeScreen.Enable", + hint: "ForienQuestLog.Settings.playersWelcomeScreen.EnableHint", + scope: "world", + config: true, + default: true, + type: Boolean + }); + + game.settings.register("forien-quest-log", "showFolder", { + name: "ForienQuestLog.Settings.showFolder.Enable", + hint: "ForienQuestLog.Settings.showFolder.EnableHint", + scope: "world", + config: true, + default: false, + type: Boolean, + onChange: value => game.journal.render() + }); } } diff --git a/modules/versioning/welcome-screen.mjs b/modules/versioning/welcome-screen.mjs index c40d7735..6dcecae8 100644 --- a/modules/versioning/welcome-screen.mjs +++ b/modules/versioning/welcome-screen.mjs @@ -24,6 +24,7 @@ class WelcomeScreen extends Application { getData(options = {}) { options = super.getData(options);; options.wfrp4e = game.system.data.name === 'wfrp4e'; + options.isChecked = !VersionCheck.check(constants.moduleName); return options; } diff --git a/templates/welcome-screen.html b/templates/welcome-screen.html index 3f915225..15d53b67 100644 --- a/templates/welcome-screen.html +++ b/templates/welcome-screen.html @@ -29,11 +29,19 @@

Suggestions? Feature Requests? Feedback?

Best regards,
Forien

-

+

Want to support development? Click here!

Changelog

+

v0.3.3

+

v0.3.2