From 231a0ddc36242ec91ac880389088964451664908 Mon Sep 17 00:00:00 2001 From: Haxxer Date: Thu, 11 Apr 2024 17:06:18 +0100 Subject: [PATCH] Changelog, fixes --- changelog.md | 10 + .../merchant-columns-editor-shell.svelte | 4 - .../item-pile-config/settings/merchant.svelte | 6 +- .../item-pile-inventory-shell.svelte | 2 +- src/applications/settings-app/Setting.svelte | 18 +- src/applications/settings-app/settings-app.js | 4 +- .../settings-app/settings-shell.svelte | 19 +- src/constants/settings.js | 4 +- src/plugins/simple-calendar.js | 25 ++- src/settings.js | 189 +++++++++--------- src/stores/merchant-store.js | 4 +- 11 files changed, 161 insertions(+), 124 deletions(-) diff --git a/changelog.md b/changelog.md index 7acfba01..ba74159f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,15 @@ # Item Piles Changelog +## Version 2.9.1 + +- Added support for the Shadowdark system (thank you mrstarbuck007 on github!) +- Added additional settings for item types (thank you p4535992 on github!) +- Tweaked currency settings to update cached item if the currency names or images were updated +- Updated D&D4e system support (thank you EndlesNights on github!) +- Fixed Better Rolltables compatibility (thank you p4535992 on github!) +- Fixed trying to open merchant columns settings after they had broken would throw error and prevent fixing the error +- Fixed Simple Calendar integration not hiding tokens of closed merchants that were set to hide + ## Version 2.9.0 - Added formal support for D&D5e 3.0.x - moving/buying/trading containers is still not supported diff --git a/src/applications/editors/merchant-columns-editor/merchant-columns-editor-shell.svelte b/src/applications/editors/merchant-columns-editor/merchant-columns-editor-shell.svelte index 11f876a5..0f3c1989 100644 --- a/src/applications/editors/merchant-columns-editor/merchant-columns-editor-shell.svelte +++ b/src/applications/editors/merchant-columns-editor/merchant-columns-editor-shell.svelte @@ -63,10 +63,6 @@ form.requestSubmit(); } - function preventDefault(event) { - event.preventDefault(); - } - diff --git a/src/applications/item-pile-config/settings/merchant.svelte b/src/applications/item-pile-config/settings/merchant.svelte index 2fe2da0a..2d8b0abc 100644 --- a/src/applications/item-pile-config/settings/merchant.svelte +++ b/src/applications/item-pile-config/settings/merchant.svelte @@ -74,13 +74,13 @@ } async function showMerchantColumns() { - const data = pileData.merchantColumns || []; + const data = Array.isArray(pileData.merchantColumns) ? pileData.merchantColumns : []; return MerchantColumnsEditor.show( data, { id: `merchant-columns-item-pile-config-${pileActor.id}` }, { title: localize("ITEM-PILES.Applications.MerchantColumnsEditor.TitleActor", { actor_name: pileActor.name }), } ).then((result) => { - pileData.merchantColumns = result || []; + pileData.merchantColumns = Array.isArray(result.merchantColumns) ? result.merchantColumns : []; }); } @@ -292,7 +292,7 @@ {localize("ITEM-PILES.Applications.ItemPileConfig.Merchant.HideTokenWhenClosed")}

{localize("ITEM-PILES.Applications.ItemPileConfig.Merchant.HideTokenWhenClosedExplanation")}

- +
diff --git a/src/applications/item-pile-inventory-app/item-pile-inventory-shell.svelte b/src/applications/item-pile-inventory-app/item-pile-inventory-shell.svelte index e405e3f6..3ec59c5f 100644 --- a/src/applications/item-pile-inventory-app/item-pile-inventory-shell.svelte +++ b/src/applications/item-pile-inventory-app/item-pile-inventory-shell.svelte @@ -220,7 +220,7 @@ .item-piles-items-list { max-height: 500px; - overflow-y: scroll; + overflow-y: auto; display: block; padding-right: 5px; diff --git a/src/applications/settings-app/Setting.svelte b/src/applications/settings-app/Setting.svelte index a17fc65c..396dc496 100644 --- a/src/applications/settings-app/Setting.svelte +++ b/src/applications/settings-app/Setting.svelte @@ -4,6 +4,7 @@ export let key; export let data; export let disabled = false; + export let options = []; @@ -26,7 +27,7 @@ {:else if data.choices}
- {#each Object.entries(data.choices) as [key, choice], index (index)} {#if data.type === Number} @@ -52,9 +53,18 @@ {:else}
- - {#if data.localize} - + + {#if options.length} + + {:else} + + {#if data.localize} + + {/if} {/if}
diff --git a/src/applications/settings-app/settings-app.js b/src/applications/settings-app/settings-app.js index 45d188d4..3a999b4f 100644 --- a/src/applications/settings-app/settings-app.js +++ b/src/applications/settings-app/settings-app.js @@ -3,7 +3,7 @@ import { getActiveApps } from '../../helpers/helpers'; import SettingsShell from './settings-shell.svelte'; import SETTINGS from "../../constants/settings.js"; -class SettingsApp extends SvelteApplication { +export class SettingsApp extends SvelteApplication { static get defaultOptions() { return foundry.utils.mergeObject(super.defaultOptions, { @@ -99,7 +99,7 @@ class SettingsApp extends SvelteApplication { } } -export default class SettingsShim extends FormApplication { +export class SettingsShim extends FormApplication { /** * @inheritDoc diff --git a/src/applications/settings-app/settings-shell.svelte b/src/applications/settings-app/settings-shell.svelte index f4cff598..6f2c22b4 100644 --- a/src/applications/settings-app/settings-shell.svelte +++ b/src/applications/settings-app/settings-shell.svelte @@ -57,6 +57,15 @@ for (let [key, setting] of settingsToUpdate) { await helpers.setSetting(key, setting.value); } + const currencies = settings[SETTINGS.CURRENCIES].value.concat(settings[SETTINGS.SECONDARY_CURRENCIES].value) + for (const currency of currencies) { + if (!currency.data?.uuid) continue; + const actualItem = await fromUuid(currency.data?.uuid); + await actualItem.update({ + name: currency.name, + img: currency.img + }); + } application.close(); } @@ -101,7 +110,7 @@ { value: "system", label: localize("ITEM-PILES.Applications.Settings.System"), hidden: !userCanChangeSettings }, ]; - let activeTab = tabs[0].value; + let activeTab = application?.options?.tab ?? tabs[0].value; @@ -183,13 +192,13 @@ getSettings(); }}/> + options={["None", ...game.system.template.Actor.types]}/> + options={["None", ...game.system.template.Item.types]}/> + options={["None", ...game.system.template.Item.types]}/> + options={["None", ...game.system.template.Item.types]}/> diff --git a/src/constants/settings.js b/src/constants/settings.js index be0089f9..7403e8bf 100644 --- a/src/constants/settings.js +++ b/src/constants/settings.js @@ -35,7 +35,7 @@ const SETTINGS = { ITEM_FILTERS: "itemFilters", ACTOR_CLASS_TYPE: "actorClassType", ITEM_CLASS_LOOT_TYPE: "itemClassLootType", - ITEM_CLASS_WEAPON_TYPE: "itemClassWeaponType", + ITEM_CLASS_WEAPON_TYPE: "itemClassWeaponType", ITEM_CLASS_EQUIPMENT_TYPE: "itemClassEquipmentType", ITEM_QUANTITY_ATTRIBUTE: "itemQuantityAttribute", ITEM_PRICE_ATTRIBUTE: "itemPriceAttribute", @@ -221,7 +221,7 @@ const SETTINGS = { type: String }, - [SETTINGS.ITEM_CLASS_LOOT_TYPE]: { + [SETTINGS.ITEM_CLASS_WEAPON_TYPE]: { name: "ITEM-PILES.Settings.ItemWeaponClass.Title", hint: "ITEM-PILES.Settings.ItemWeaponClass.Hint", scope: "world", diff --git a/src/plugins/simple-calendar.js b/src/plugins/simple-calendar.js index ab9cec44..6ef57503 100644 --- a/src/plugins/simple-calendar.js +++ b/src/plugins/simple-calendar.js @@ -135,25 +135,34 @@ export default class SimpleCalendarPlugin extends BasePlugin { const actors = this.actors.filter((actor) => { const pileData = PileUtilities.getActorFlagData(actor); - return pileData.hideTokenWhenClosed && PileUtilities.isMerchantClosed(actor, { pileData }); + return pileData.hideTokenWhenClosed; }); - const actorTokens = actors.map(actor => actor.getActiveTokens()) + const validTokensOnScenes = actors.map(actor => actor.getActiveTokens()) .deepFlatten() .reduce((acc, token) => { - if (!acc[token.parent.id]) acc[token.parent.id] = []; - acc[token.parent.id].push(token); + const tokenDocument = token.document; + const sceneId = tokenDocument.parent.id; + if (!acc[sceneId]) acc[sceneId] = []; + acc[sceneId].push(tokenDocument); return acc; }, {}); - const validTokensOnScenes = this.validTokensOnScenes.filter((token) => { + this.validTokensOnScenes.filter((token) => { const pileData = PileUtilities.getActorFlagData(token); - return pileData.hideTokenWhenClosed && PileUtilities.isMerchantClosed(token, { pileData }); + return pileData.hideTokenWhenClosed; + }).forEach(([sceneId, token]) => { + if (validTokensOnScenes[sceneId].length) { + if (!validTokensOnScenes[sceneId].find(t => t === token)) return; + validTokensOnScenes[sceneId].push(token) + } else { + validTokensOnScenes[sceneId] = [token] + } }); - for (const [sceneId, tokens] of validTokensOnScenes) { + for (const [sceneId, tokens] of Object.entries(validTokensOnScenes)) { const scene = game.scenes.get(sceneId); - const updates = Object.values(tokens.concat(actorTokens).reduce((acc, token) => { + const updates = Object.values(tokens.reduce((acc, token) => { if (!acc[token.id]) { acc[token.id] = { _id: token.id, diff --git a/src/settings.js b/src/settings.js index 55391691..eca4bd84 100644 --- a/src/settings.js +++ b/src/settings.js @@ -2,127 +2,130 @@ import CONSTANTS from "./constants/constants.js"; import SETTINGS from "./constants/settings.js"; import * as Helpers from "./helpers/helpers.js"; import { SYSTEMS } from "./systems.js"; -import SettingsShim from "./applications/settings-app/settings-app.js"; +import { SettingsShim, SettingsApp } from "./applications/settings-app/settings-app.js"; import { TJSDialog } from "@typhonjs-fvtt/runtime/svelte/application"; import CustomDialog from "./applications/components/CustomDialog.svelte"; export function registerSettings() { - game.settings.registerMenu(CONSTANTS.MODULE_NAME, "configure-settings", { - name: "ITEM-PILES.Settings.Configure.Title", - label: "ITEM-PILES.Settings.Configure.Label", - hint: "ITEM-PILES.Settings.Configure.Hint", - icon: "fas fa-cog", - type: SettingsShim, - restricted: false - }); + game.settings.registerMenu(CONSTANTS.MODULE_NAME, "configure-settings", { + name: "ITEM-PILES.Settings.Configure.Title", + label: "ITEM-PILES.Settings.Configure.Label", + hint: "ITEM-PILES.Settings.Configure.Hint", + icon: "fas fa-cog", + type: SettingsShim, + restricted: false + }); - for (let [name, data] of Object.entries(SETTINGS.GET_DEFAULT())) { - game.settings.register(CONSTANTS.MODULE_NAME, name, data); - } + for (let [name, data] of Object.entries(SETTINGS.GET_DEFAULT())) { + game.settings.register(CONSTANTS.MODULE_NAME, name, data); + } } export async function applyDefaultSettings() { - const settings = SETTINGS.GET_SYSTEM_DEFAULTS(); - for (const [name, data] of Object.entries(settings)) { - await Helpers.setSetting(name, data.default); - } - await Helpers.setSetting(SETTINGS.SYSTEM_VERSION, SYSTEMS.DATA.VERSION); - await patchCurrencySettings(); + const settings = SETTINGS.GET_SYSTEM_DEFAULTS(); + for (const [name, data] of Object.entries(settings)) { + await Helpers.setSetting(name, data.default); + } + await Helpers.setSetting(SETTINGS.SYSTEM_VERSION, SYSTEMS.DATA.VERSION); + await patchCurrencySettings(); } export async function applySoftMigration(migrationKey) { - const migrationSettings = SYSTEMS.DATA.SOFT_MIGRATIONS[migrationKey]; - for (const [key, values] of Object.entries(migrationSettings)) { - const settingsKey = SETTINGS[key]; - const currentSettingValue = Helpers.getSetting(settingsKey); - await Helpers.setSetting(settingsKey, foundry.utils.mergeObject(currentSettingValue, values)); - } - await Helpers.setSetting(SETTINGS.SYSTEM_VERSION, SYSTEMS.DATA.VERSION); + const migrationSettings = SYSTEMS.DATA.SOFT_MIGRATIONS[migrationKey]; + for (const [key, values] of Object.entries(migrationSettings)) { + const settingsKey = SETTINGS[key]; + const currentSettingValue = Helpers.getSetting(settingsKey); + await Helpers.setSetting(settingsKey, foundry.utils.mergeObject(currentSettingValue, values)); + } + await Helpers.setSetting(SETTINGS.SYSTEM_VERSION, SYSTEMS.DATA.VERSION); } export async function patchCurrencySettings() { - const currencies = Helpers.getSetting(SETTINGS.CURRENCIES); - for (let currency of currencies) { - if (currency.type !== "item" || !currency.data.uuid || currency.data.item) continue; - const item = await fromUuid(currency.data.uuid); - if (!item) continue; - currency.data.item = item.toObject(); - } - return Helpers.setSetting(SETTINGS.CURRENCIES, currencies); + const currencies = Helpers.getSetting(SETTINGS.CURRENCIES); + for (let currency of currencies) { + if (currency.type !== "item" || !currency.data.uuid || currency.data.item) continue; + const item = await fromUuid(currency.data.uuid); + if (!item) continue; + currency.data.item = item.toObject(); + } + return Helpers.setSetting(SETTINGS.CURRENCIES, currencies); } export function applySystemSpecificStyles(data = false) { - const defaultCssVariables = foundry.utils.deepClone(SETTINGS.DEFAULT_CSS_VARIABLES); - const cssVariables = data || Helpers.getSetting(SETTINGS.CSS_VARIABLES); - const mergedCssVariables = foundry.utils.mergeObject(defaultCssVariables, cssVariables) - const root = document.documentElement; - for (const [style, val] of Object.entries(mergedCssVariables)) { - if (!val) { - root.style.removeProperty(`--item-piles-${style}`) - } else { - root.style.setProperty(`--item-piles-${style}`, val); - } - } + const defaultCssVariables = foundry.utils.deepClone(SETTINGS.DEFAULT_CSS_VARIABLES); + const cssVariables = data || Helpers.getSetting(SETTINGS.CSS_VARIABLES); + const mergedCssVariables = foundry.utils.mergeObject(defaultCssVariables, cssVariables) + const root = document.documentElement; + for (const [style, val] of Object.entries(mergedCssVariables)) { + if (!val) { + root.style.removeProperty(`--item-piles-${style}`) + } else { + root.style.setProperty(`--item-piles-${style}`, val); + } + } } export async function checkSystem() { - if (!SYSTEMS.HAS_SYSTEM_SUPPORT) { - - if (Helpers.getSetting(SETTINGS.SYSTEM_NOT_FOUND_WARNING_SHOWN)) return; - - let settingsValid = true; - for (const [name, data] of Object.entries(SETTINGS.GET_DEFAULT())) { - settingsValid = settingsValid && Helpers.getSetting(name).length !== (new data.type).length - } - - if (settingsValid) return; - - TJSDialog.prompt({ - title: game.i18n.localize("ITEM-PILES.Dialogs.NoSystemFound.Title"), - content: { - class: CustomDialog, - props: { - content: game.i18n.localize("ITEM-PILES.Dialogs.NoSystemFound.Content") - } - } - }); - - return Helpers.setSetting(SETTINGS.SYSTEM_NOT_FOUND_WARNING_SHOWN, true); - - } - - if (Helpers.getSetting(SETTINGS.SYSTEM_FOUND) || SYSTEMS.DATA.INTEGRATION) { - const currentVersion = Helpers.getSetting(SETTINGS.SYSTEM_VERSION); - const newVersion = SYSTEMS.DATA.VERSION; - Helpers.debug(`Comparing system version - Current: ${currentVersion} - New: ${newVersion}`) - if (SYSTEMS.DATA.SOFT_MIGRATIONS[currentVersion + "-" + newVersion]) { - Helpers.debug(`Applying soft migration for ${game.system.title}`); - await applySoftMigration(currentVersion + "-" + newVersion); - } else if (isNewerVersion(newVersion, currentVersion)) { - Helpers.debug(`Applying system settings for ${game.system.title}`) - await applyDefaultSettings(); - } - return; - } - - await Helpers.setSetting(SETTINGS.SYSTEM_FOUND, true); - - if (Helpers.getSetting(SETTINGS.SYSTEM_NOT_FOUND_WARNING_SHOWN)) { - Helpers.custom_notify(game.i18n.localize("ITEM-PILES.Notifications.SystemSupportFound")); - } - - return applyDefaultSettings(); + if (!SYSTEMS.HAS_SYSTEM_SUPPORT) { + + if (Helpers.getSetting(SETTINGS.SYSTEM_NOT_FOUND_WARNING_SHOWN)) return; + + let settingsValid = true; + for (const [name, data] of Object.entries(SETTINGS.GET_DEFAULT())) { + settingsValid = settingsValid && Helpers.getSetting(name).length !== (new data.type).length + } + + if (settingsValid) return; + + TJSDialog.prompt({ + title: game.i18n.localize("ITEM-PILES.Dialogs.NoSystemFound.Title"), + content: { + class: CustomDialog, + props: { + content: game.i18n.localize("ITEM-PILES.Dialogs.NoSystemFound.Content") + } + }, + modal: true + }).then(() => { + SettingsApp.show({ tab: "system" }); + }); + + return Helpers.setSetting(SETTINGS.SYSTEM_NOT_FOUND_WARNING_SHOWN, true); + + } + + if (Helpers.getSetting(SETTINGS.SYSTEM_FOUND) || SYSTEMS.DATA.INTEGRATION) { + const currentVersion = Helpers.getSetting(SETTINGS.SYSTEM_VERSION); + const newVersion = SYSTEMS.DATA.VERSION; + Helpers.debug(`Comparing system version - Current: ${currentVersion} - New: ${newVersion}`) + if (SYSTEMS.DATA.SOFT_MIGRATIONS[currentVersion + "-" + newVersion]) { + Helpers.debug(`Applying soft migration for ${game.system.title}`); + await applySoftMigration(currentVersion + "-" + newVersion); + } else if (isNewerVersion(newVersion, currentVersion)) { + Helpers.debug(`Applying system settings for ${game.system.title}`) + await applyDefaultSettings(); + } + return; + } + + await Helpers.setSetting(SETTINGS.SYSTEM_FOUND, true); + + if (Helpers.getSetting(SETTINGS.SYSTEM_NOT_FOUND_WARNING_SHOWN)) { + Helpers.custom_notify(game.i18n.localize("ITEM-PILES.Notifications.SystemSupportFound")); + } + + return applyDefaultSettings(); } export function applyShims() { - if (game.release.generation !== 11) return; + if (game.release.generation !== 11) return; - CONSTANTS.ACTOR_DELTA_PROPERTY = "delta"; + CONSTANTS.ACTOR_DELTA_PROPERTY = "delta"; - Object.freeze(CONSTANTS); + Object.freeze(CONSTANTS); } diff --git a/src/stores/merchant-store.js b/src/stores/merchant-store.js index f1cb8da4..d520ecb9 100644 --- a/src/stores/merchant-store.js +++ b/src/stores/merchant-store.js @@ -115,8 +115,8 @@ export default class MerchantStore extends ItemPileStore { } setupColumns(pileData) { - - const customColumns = foundry.utils.deepClone(pileData.merchantColumns ?? []) + const merchantColumns = Array.isArray(pileData?.merchantColumns) ? pileData.merchantColumns : []; + const customColumns = foundry.utils.deepClone(merchantColumns) .filter(column => { return this.isMerchant ? (column?.buying ?? true) : (column?.selling ?? true); })