From 29d25f8afe23a15d4cb0c3b85d3aaa73d18b050a Mon Sep 17 00:00:00 2001 From: macniel Date: Wed, 12 Nov 2025 17:05:45 +0100 Subject: [PATCH] Implements Filtering --- src/lang/de.json | 3 + src/module/dialog/itemBrowserDialog.mjs | 86 +++++++++++++++++-- src/module/setup/sheets.mjs | 2 +- src/module/sheets/equipmentSheet.mjs | 4 +- src/style/organisms/_item-browser-dialog.scss | 40 +++++++++ .../organisms/character-tabs/_inventory.scss | 20 ++++- .../actor/character/tab-equipment.hbs | 10 ++- src/templates/dialog/item-browser-dialog.hbs | 27 +++++- 8 files changed, 176 insertions(+), 16 deletions(-) diff --git a/src/lang/de.json b/src/lang/de.json index 2561331e..b1914f86 100644 --- a/src/lang/de.json +++ b/src/lang/de.json @@ -45,5 +45,8 @@ "regularFormula": "Schadensformel:", "bonusDamage": "Zusätzlicher Schaden:", "buttonText": "Würfeln" + }, + "ITEM_BROWSER": { + "progress": "{current}/{max}: Importiere von {compendium}" } } diff --git a/src/module/dialog/itemBrowserDialog.mjs b/src/module/dialog/itemBrowserDialog.mjs index c5db0023..dbad818b 100644 --- a/src/module/dialog/itemBrowserDialog.mjs +++ b/src/module/dialog/itemBrowserDialog.mjs @@ -10,15 +10,18 @@ export class ItemBrowserDialog extends HandlebarsApplicationMixin(ApplicationV2) static DEFAULT_OPTIONS = { classes: ['dsa41', 'dialog', 'item-browser'], tag: "form", + form: { + submitOnChange: true, + closeOnSubmit: false, + handler: ItemBrowserDialog.#onSubmitForm + }, position: { width: 640, height: 480 }, window: { resizable: true, - }, - actions: { - buy: ItemBrowserDialog.#buy + title: "Gegenstände Browser" } } @@ -39,16 +42,29 @@ export class ItemBrowserDialog extends HandlebarsApplicationMixin(ApplicationV2) * @private */ _items = [] + filter_price_lower = 0 + filter_price_upper = 0 + filter_weight_lower = 0 + filter_weight_upper = 0 + filter_name = "" + filter_category = "" constructor(actor) { super(); this._actor = actor - // load compendium data this._items = [] } - static async #buy(event, target) { + static async #onSubmitForm(event, form, formData) { + event.preventDefault() + this.filter_price_lower = formData.object.filter_price_lower + this.filter_price_upper = formData.object.filter_price_upper + this.filter_weight_lower = formData.object.filter_weight_lower + this.filter_weight_upper = formData.object.filter_weight_upper + this.filter_name = formData.object.filter_name + this.filter_category = formData.object.filter_category + this.render({parts: ["form"]}) } _canDragDrop(event, options) { @@ -83,10 +99,51 @@ export class ItemBrowserDialog extends HandlebarsApplicationMixin(ApplicationV2) async _prepareContext(options) { const context = await super._prepareContext(options) + context.categories = { + "": "", + "Gegenstand": "Gegenstand", + "Nahkampfwaffe": "Nahkampfwaffe", + "Fernkampfwaffe": "Fernkampfwaffe", + "Munition": "Munition", + "Währung": "Währung" + } + context.filterName = this.filter_name + context.filterCategory = this.filter_category + context.filter_price_lower = this.filter_price_lower ?? this._minPrice + context.filter_price_upper = this.filter_price_upper ?? this._maxPrice + context.filter_weight_lower = this.filter_weight_lower ?? this._minWeight + context.filter_weight_upper = this.filter_weight_upper ?? this._maxWeight + context.price_lower = this._minPrice + context.price_upper = this._maxPrice + context.weight_lower = this._minWeight + context.weight_upper = this._maxWeight + context.items = this._items + ?.filter(p => p.name.toLowerCase().indexOf(context.filterName.toLowerCase()) !== -1 || context.filterName === "") + ?.filter(p => p.category.indexOf(context.filterCategory) !== -1 || context.filterCategory === "") + ?.filter(p => Number(context.filter_price_lower) <= p.price && p.price <= Number(context.filter_price_upper)) + ?.filter(p => Number(context.filter_weight_lower) <= p.weight && p.weight <= Number(context.filter_weight_upper)) + + + return context } + #updateProgress(compendiumName, current, max) { + if (compendiumName && current && max) { + this.element.querySelector('.progress').style.display = 'block'; + this.element.querySelector('.progress .fill').style.width = (current / max * 100) + "%"; + this.element.querySelector('.progress .text').textContent = game.i18n.format("ITEM_BROWSER.progress", { + compendium: compendiumName, + current: current, + max: max + }) + + } else { + this.element.querySelector('.progress').style.display = 'none'; + } + } + async _onRender(context, options) { if (this._items.length === 0) { @@ -97,8 +154,13 @@ export class ItemBrowserDialog extends HandlebarsApplicationMixin(ApplicationV2) game.packs.get('DSA_4-1.Items') ] + let totalEntries = compendia.reduce((p, c) => p + c.index.size, 0) + let parsedEntries = 0 + let currentCompendiumName = "" + for (const c of compendia) { const it = await c.getDocuments() + currentCompendiumName = c.metadata.label it.forEach((item) => { const uuid = item.uuid const e = new Equipment(item) @@ -111,13 +173,23 @@ export class ItemBrowserDialog extends HandlebarsApplicationMixin(ApplicationV2) weight: e.system.weight, category: e.system.category.join(", ") }) - console.log("importing ", item.name) + + parsedEntries += 1 + this.#updateProgress(currentCompendiumName, parsedEntries, totalEntries) }) - console.log("done importing from ", c) } + this._minPrice = Math.min(...this._items.map(item => item.price)) + this._maxPrice = Math.max(...this._items.map(item => item.price)) + + this._minWeight = Math.min(...this._items.map(item => item.weight)) + this._maxWeight = Math.max(...this._items.map(item => item.weight)) + + + this.#updateProgress() this.render({parts: ["form"]}) } + new foundry.applications.ux.DragDrop.implementation({ dropSelector: ".window-content", dragSelector: ".item", diff --git a/src/module/setup/sheets.mjs b/src/module/setup/sheets.mjs index 51fe9bec..781333f5 100644 --- a/src/module/setup/sheets.mjs +++ b/src/module/setup/sheets.mjs @@ -4,7 +4,7 @@ import {GroupSheet} from "../sheets/groupSheet.mjs"; import {SkillSheet} from "../sheets/skillSheet.mjs"; import {SpellSheet} from "../sheets/spellSheet.mjs"; import {AdvantageSheet} from "../sheets/advantageSheet.mjs"; -import {EquipmentSheet} from "../sheets/equipmentSheet.mjs"; +import EquipmentSheet from "../sheets/equipmentSheet.mjs"; import {LiturgySheet} from "../sheets/liturgySheet.mjs"; import {SpecialAbilitySheet} from "../sheets/specialAbilitySheet.mjs"; import {ActiveEffectSheet} from "../sheets/activeEffectSheet.mjs"; diff --git a/src/module/sheets/equipmentSheet.mjs b/src/module/sheets/equipmentSheet.mjs index 6d29b1fd..76b352c2 100644 --- a/src/module/sheets/equipmentSheet.mjs +++ b/src/module/sheets/equipmentSheet.mjs @@ -1,6 +1,6 @@ const {DocumentSheetV2, HandlebarsApplicationMixin} = foundry.applications.api -export class EquipmentSheet extends HandlebarsApplicationMixin(DocumentSheetV2) { +class EquipmentSheet extends HandlebarsApplicationMixin(DocumentSheetV2) { /** @inheritDoc */ static DEFAULT_OPTIONS = { @@ -311,3 +311,5 @@ export class EquipmentSheet extends HandlebarsApplicationMixin(DocumentSheetV2) } } + +export default EquipmentSheet diff --git a/src/style/organisms/_item-browser-dialog.scss b/src/style/organisms/_item-browser-dialog.scss index 75ad7ea2..051979ba 100644 --- a/src/style/organisms/_item-browser-dialog.scss +++ b/src/style/organisms/_item-browser-dialog.scss @@ -2,6 +2,46 @@ .window-content [data-application-part] { + position: relative; + + .progress { + position: absolute; + top: 0; + left: 0; + right: 0; + height: 24px; + border-radius: 4px; + background-color: rgba(0, 0, 0, 0.3); + + .fill { + position: absolute; + left: 0; + top: 0; + bottom: 0; + background: url('/systems/DSA_4-1/assets/gradient.png'); + background-size: 24px 100%; + background-color: rgba(64, 192, 192, 0.8); + background-blend-mode: multiply; + } + + .text { + position: absolute; + left: 0; + top: 0; + right: 0; + bottom: 0; + height: 24px; + line-height: 24px; + vertical-align: middle; + font-weight: bold; + margin-left: 8px; + text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3); + color: white; + } + + + } + display: grid; grid-template-columns: 240px 1fr; height: 100%; diff --git a/src/style/organisms/character-tabs/_inventory.scss b/src/style/organisms/character-tabs/_inventory.scss index ef33c147..4a490e73 100644 --- a/src/style/organisms/character-tabs/_inventory.scss +++ b/src/style/organisms/character-tabs/_inventory.scss @@ -56,11 +56,29 @@ } } - h3.inventory-header { + .inventory-header { line-height: 32px; grid-area: inventory-header; margin: 0; padding: 0; + display: flex; + + h3 { + flex: 1; + line-height: 32px; + } + + .buttons { + flex: 0; + display: flex; + gap: 4px; + + button { + + } + } + + } diff --git a/src/templates/actor/character/tab-equipment.hbs b/src/templates/actor/character/tab-equipment.hbs index d72a93a0..f289a702 100644 --- a/src/templates/actor/character/tab-equipment.hbs +++ b/src/templates/actor/character/tab-equipment.hbs @@ -15,9 +15,13 @@ -

Inventar

- - +
+

Inventar

+
+ + +
+
{{> "systems/DSA_4-1/templates/ui/partial-equipment-button.hbs" equipments}}
diff --git a/src/templates/dialog/item-browser-dialog.hbs b/src/templates/dialog/item-browser-dialog.hbs index d09860f6..9dd575b3 100644 --- a/src/templates/dialog/item-browser-dialog.hbs +++ b/src/templates/dialog/item-browser-dialog.hbs @@ -1,23 +1,44 @@
+