mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49:02 +01:00
Replace compendium calls
This commit is contained in:
parent
42867a4be1
commit
3ea050997b
12 changed files with 220 additions and 70 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { abilities } from '../../config/actorConfig.mjs';
|
||||
import { burden } from '../../config/generalConfig.mjs';
|
||||
import { createEmbeddedItemWithEffects } from '../../helpers/utils.mjs';
|
||||
import { ItemBrowser } from '../ui/itemBrowser.mjs';
|
||||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
|
|
@ -485,8 +486,24 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
|||
});
|
||||
}
|
||||
|
||||
static async viewCompendium(_, target) {
|
||||
(await game.packs.get(`daggerheart.${target.dataset.compendium}`))?.render(true);
|
||||
static async viewCompendium(event, target) {
|
||||
const type = target.dataset.compendium ?? target.dataset.type;
|
||||
|
||||
const presets = {
|
||||
compendium: "daggerheart",
|
||||
folder: type,
|
||||
render: {
|
||||
noFolder: true
|
||||
}
|
||||
};
|
||||
|
||||
if(type == "domains")
|
||||
presets.filter = {
|
||||
'level.max': { key: 'level.max', value: 1 },
|
||||
'system.domain': { key: 'system.domain', value: this.setup.class?.system.domains ?? null },
|
||||
};
|
||||
|
||||
return new ItemBrowser({ presets }).render({ force: true });
|
||||
}
|
||||
|
||||
static async viewItem(_, target) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { abilities, subclassFeatureLabels } from '../../config/actorConfig.mjs';
|
||||
import { domains } from '../../config/domainConfig.mjs';
|
||||
import { getDeleteKeys, tagifyElement } from '../../helpers/utils.mjs';
|
||||
import { ItemBrowser } from '../ui/itemBrowser.mjs';
|
||||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
|
|
@ -525,8 +526,24 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
|
|||
this.render();
|
||||
}
|
||||
|
||||
static async viewCompendium(_, button) {
|
||||
(await game.packs.get(`daggerheart.${button.dataset.compendium}`))?.render(true);
|
||||
static async viewCompendium(event, target) {
|
||||
const type = target.dataset.compendium ?? target.dataset.type;
|
||||
|
||||
const presets = {
|
||||
compendium: "daggerheart",
|
||||
folder: type,
|
||||
render: {
|
||||
noFolder: true
|
||||
}
|
||||
};
|
||||
|
||||
// if(type == "domains")
|
||||
// presets.filter = {
|
||||
// 'level.max': { key: 'level.max', value: 1 },
|
||||
// 'system.domain': { key: 'system.domain', value: this.setup.class?.system.domains ?? null },
|
||||
// };
|
||||
|
||||
return new ItemBrowser({ presets }).render({ force: true });
|
||||
}
|
||||
|
||||
static async selectPreview(_, button) {
|
||||
|
|
|
|||
|
|
@ -594,7 +594,16 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
*/
|
||||
static async #openPack(_event, button) {
|
||||
const { key } = button.dataset;
|
||||
game.packs.get(key)?.render(true);
|
||||
|
||||
const presets = {
|
||||
compendium: "daggerheart",
|
||||
folder: key,
|
||||
render: {
|
||||
noFolder: true
|
||||
}
|
||||
};
|
||||
|
||||
return new ItemBrowser({ presets }).render({ force: true });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
||||
import { getDocFromElement, getDocFromElementSync, tagifyElement } from '../../../helpers/utils.mjs';
|
||||
import { ItemBrowser } from '../../ui/itemBrowser.mjs';
|
||||
|
||||
/**
|
||||
* @typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction
|
||||
|
|
@ -82,7 +83,9 @@ export default function DHApplicationMixin(Base) {
|
|||
toChat: DHSheetV2.#toChat,
|
||||
useItem: DHSheetV2.#useItem,
|
||||
toggleEffect: DHSheetV2.#toggleEffect,
|
||||
toggleExtended: DHSheetV2.#toggleExtended
|
||||
toggleExtended: DHSheetV2.#toggleExtended,
|
||||
addNewItem: DHSheetV2.#addNewItem,
|
||||
browseItem: DHSheetV2.#browseItem,
|
||||
},
|
||||
contextMenus: [
|
||||
{
|
||||
|
|
@ -409,6 +412,71 @@ export default function DHApplicationMixin(Base) {
|
|||
/* Application Clicks Actions */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
static async #addNewItem(event, target) {
|
||||
const { type } = target.dataset;
|
||||
|
||||
const createChoice = await foundry.applications.api.DialogV2.wait({
|
||||
classes: ['dh-style', 'two-big-buttons'],
|
||||
buttons: [
|
||||
{
|
||||
action: "create",
|
||||
label: "Create Item",
|
||||
icon: "fa-solid fa-plus"
|
||||
},
|
||||
{
|
||||
action: "browse",
|
||||
label: "Browse Compendium",
|
||||
icon: "fa-solid fa-book"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
if(!createChoice) return;
|
||||
|
||||
if(createChoice === "browse")
|
||||
return DHSheetV2.#browseItem.call(this, event, target);
|
||||
else
|
||||
return DHSheetV2.#createDoc.call(this, event, target);
|
||||
|
||||
}
|
||||
|
||||
static async #browseItem(event, target) {
|
||||
const type = target.dataset.compendium ?? target.dataset.type;
|
||||
|
||||
const presets = {};
|
||||
|
||||
switch (type) {
|
||||
case 'loot':
|
||||
case 'consumable':
|
||||
case 'armor':
|
||||
case 'weapon':
|
||||
presets.compendium = "daggerheart";
|
||||
presets.folder = "equipments";
|
||||
presets.render = {
|
||||
noFolder: true
|
||||
};
|
||||
presets.filter = {
|
||||
type: { key: 'type', value: type, forced: true }
|
||||
};
|
||||
break;
|
||||
case 'domainCard':
|
||||
presets.compendium = "daggerheart";
|
||||
presets.folder = "domains";
|
||||
presets.render = {
|
||||
noFolder: true
|
||||
};
|
||||
presets.filter = {
|
||||
'level.max': { key: 'level.max', value: this.document.system.levelData.level.current },
|
||||
'system.domain': { key: 'system.domain', value: this.document.system.domains },
|
||||
};
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
return new ItemBrowser({ presets }).render({ force: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an embedded document.
|
||||
* @type {ApplicationClickAction}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
this.fieldFilter = [];
|
||||
this.selectedMenu = { path: [], data: null };
|
||||
this.config = CONFIG.DH.ITEMBROWSER.compendiumConfig;
|
||||
this.presets = options.presets;
|
||||
|
||||
if(this.presets?.folder)
|
||||
ItemBrowser.selectFolder.call(this, null, null, this.presets.compendium, this.presets.folder);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
|
|
@ -37,10 +41,10 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
sortList: this.sortList
|
||||
},
|
||||
position: {
|
||||
width: 1000,
|
||||
height: 800
|
||||
// top: "200px",
|
||||
// left: "120px"
|
||||
top: 70,
|
||||
left: 120,
|
||||
width: 800,
|
||||
height: 600
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -89,6 +93,11 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
this._createSearchFilter();
|
||||
this._createFilterInputs();
|
||||
this._createDragProcess();
|
||||
|
||||
if(this.presets?.filter) {
|
||||
Object.entries(this.presets.filter).forEach(([k,v]) => this.fieldFilter.find(c => c.name === k).value = v.value);
|
||||
await this._onInputFilterBrowser();
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
|
@ -105,7 +114,7 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
context.formatChoices = this.formatChoices;
|
||||
context.fieldFilter = this.fieldFilter = this._createFieldFilter();
|
||||
context.items = this.items;
|
||||
console.log(this.items);
|
||||
context.presets = this.presets;
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
@ -128,10 +137,10 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
return folders;
|
||||
}
|
||||
|
||||
static async selectFolder(_, target) {
|
||||
static async selectFolder(_, target, compend, folder) {
|
||||
const config = foundry.utils.deepClone(this.config),
|
||||
compendium = target.closest('[data-compendium-id]').dataset.compendiumId,
|
||||
folderId = target.dataset.folderId,
|
||||
compendium = compend ?? target.closest('[data-compendium-id]').dataset.compendiumId,
|
||||
folderId = folder ?? target.dataset.folderId,
|
||||
folderPath = `${compendium}.folders.${folderId}`,
|
||||
folderData = foundry.utils.getProperty(config, folderPath);
|
||||
|
||||
|
|
@ -186,9 +195,9 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
if (typeof f.field === 'string') f.field = foundry.utils.getProperty(game, f.field);
|
||||
else if (typeof f.choices === 'function') {
|
||||
f.choices = f.choices();
|
||||
console.log(f.choices)
|
||||
}
|
||||
f.name ??= f.key;
|
||||
f.value = this.presets.filter?.[f.name]?.value ?? null;
|
||||
// filters.push(f);
|
||||
});
|
||||
return filters;
|
||||
|
|
@ -286,11 +295,9 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
async _onInputFilterBrowser(event) {
|
||||
this.#filteredItems.browser.input.clear();
|
||||
|
||||
this.fieldFilter.find(f => f.name === event.target.name).value = event.target.value;
|
||||
if(event) this.fieldFilter.find(f => f.name === event.target.name).value = event.target.value;
|
||||
|
||||
// console.log(_event, html, filters)
|
||||
|
||||
for (const li of event.target.closest('[data-application-part="list"]').querySelectorAll('.item-container')) {
|
||||
for (const li of this.element.querySelectorAll('.item-container')) {
|
||||
const itemUUID = li.dataset.itemUuid,
|
||||
item = this.items.find(i => i.uuid === itemUUID);
|
||||
|
||||
|
|
@ -308,6 +315,8 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
li.hidden = !(search.has(item.id) && matchesMenu);
|
||||
// li.hidden = !(matchesMenu);
|
||||
}
|
||||
|
||||
console.log(this.fieldFilter)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -316,24 +325,18 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
* @param {*} filter
|
||||
*/
|
||||
static evaluateFilter(obj, filter) {
|
||||
const docValue = foundry.utils.getProperty(obj, filter.field);
|
||||
const filterValue = filter.value;
|
||||
let docValue = foundry.utils.getProperty(obj, filter.field);
|
||||
let filterValue = filter.value;
|
||||
switch (filter.operator) {
|
||||
case "contains2":
|
||||
return Array.isArray(docValue) ? docValue.includes(filterValue) : [docValue].includes(filterValue);
|
||||
break;
|
||||
filterValue = Array.isArray(filterValue) ? filterValue : [filterValue];
|
||||
docValue = Array.isArray(docValue) ? docValue : [docValue];
|
||||
return docValue.some(dv => filterValue.includes(dv));
|
||||
case "contains3":
|
||||
return docValue.some(f => f.value === filterValue);
|
||||
break;
|
||||
default:
|
||||
return foundry.applications.ux.SearchFilter.evaluateFilter(obj, filter);
|
||||
break;
|
||||
}
|
||||
if(filter.operator === "contains2") {
|
||||
const docValue = foundry.utils.getProperty(obj, filter.field);
|
||||
const filterValue = filter.value;
|
||||
return Array.isArray(docValue) ? docValue.includes(filterValue) : [docValue].includes(filterValue);
|
||||
} return foundry.applications.ux.SearchFilter.evaluateFilter(obj, filter)
|
||||
}
|
||||
|
||||
createFilterData(filter) {
|
||||
|
|
@ -414,8 +417,9 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
async _onDragStart(event) {
|
||||
// console.log(event)
|
||||
// ui.context?.close({ animate: false });
|
||||
const { itemUuid } = event.target.closest('[data-item-uuid]').dataset;
|
||||
const dragData = foundry.utils.fromUuidSync(itemUuid).toDragData();
|
||||
const { itemUuid } = event.target.closest('[data-item-uuid]').dataset,
|
||||
item = await foundry.utils.fromUuid(itemUuid),
|
||||
dragData = item.toDragData();
|
||||
// console.log(dragData)
|
||||
// const dragData = { UUID: itemUuid };
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(dragData));
|
||||
|
|
|
|||
|
|
@ -169,7 +169,8 @@ export const typeConfig = {
|
|||
{
|
||||
key: "system.domain",
|
||||
label: "Domain",
|
||||
field: 'system.api.models.items.DHDomainCard.schema.fields.domain'
|
||||
field: 'system.api.models.items.DHDomainCard.schema.fields.domain',
|
||||
operator: "contains2"
|
||||
},
|
||||
{
|
||||
key: "system.level",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue