mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
Reverted sorting
This commit is contained in:
parent
201d3c3f3c
commit
7614001bdd
4 changed files with 31 additions and 87 deletions
|
|
@ -267,7 +267,7 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
context.isDeath = this.document.system.deathMoveViable;
|
||||
context.sidebarFavoritesEmpty = this.document.system.sidebarFavorites.length === 0;
|
||||
context.showfavorites = !context.sidebarFavoritesEmpty || this.document.system.usedUnarmed;
|
||||
context.sidebarFavorites = this.document.system.sidebarFavorites.sort((a, b) => a.sort - b.sort);
|
||||
context.sidebarFavorites = this.document.system.sidebarFavorites.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -962,12 +962,7 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
if (inventoryItem) {
|
||||
event.dataTransfer.setDragImage(inventoryItem.querySelector('img'), 60, 0);
|
||||
}
|
||||
|
||||
await super._onDragStart(event);
|
||||
const baseDragData = foundry.applications.ux.TextEditor.getDragEventData(event);
|
||||
|
||||
const sidebarReorder = Boolean(event.target.closest('.items-sidebar-list'));
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify({ ...baseDragData, sidebarReorder }));
|
||||
super._onDragStart(event);
|
||||
}
|
||||
|
||||
async _onDropItem(event, item) {
|
||||
|
|
@ -1024,45 +1019,8 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
const allowedItemTypes = ['domainCard', 'feature', 'weapon', 'armor', 'loot', 'consumable'];
|
||||
if (!allowedItemTypes.includes(item.type)) return;
|
||||
|
||||
const siblings = this.document.system.sidebarFavorites.filter(x => x.item.id !== item.id);
|
||||
let source = null;
|
||||
if (this.document.system.sidebarFavorites.some(x => x.id === item.id)) return;
|
||||
|
||||
const data = foundry.applications.ux.TextEditor.getDragEventData(event);
|
||||
if (data.sidebarReorder) {
|
||||
source = this.document.system.sidebarFavorites.find(x => x.item.id === item.id);
|
||||
} else {
|
||||
if (this.document.system.sidebarFavorites.some(x => x.item.id === item.id)) return;
|
||||
source = { sort: null, item };
|
||||
}
|
||||
|
||||
const update = siblings.length
|
||||
? this.getDropSortedFavorites(event, source, siblings)
|
||||
: [
|
||||
...this.document.system.sidebarFavorites.map(x => ({ ...x, item: x.item.uuid })),
|
||||
{ item, sort: 100000 }
|
||||
];
|
||||
if (!update) return;
|
||||
|
||||
this.document.update({ 'system.sidebarFavorites': update });
|
||||
}
|
||||
|
||||
getDropSortedFavorites(event, source, siblings) {
|
||||
const dropTarget = event.target.closest('[data-item-id]');
|
||||
if (!dropTarget) return;
|
||||
|
||||
const target = this.document.system.sidebarFavorites.find(x => x.item.id === dropTarget.dataset.itemId);
|
||||
const sortUpdates = foundry.utils.performIntegerSort(source, { target, siblings });
|
||||
const updates = sortUpdates.map(u => ({
|
||||
sort: u.update.sort,
|
||||
item: u.target?.uuid ?? u.target.item.uuid
|
||||
}));
|
||||
|
||||
const test = this.document.system.sidebarFavorites.reduce((acc, curr) => {
|
||||
if (acc.some(x => x.item === curr.item.uuid)) return acc;
|
||||
acc.push({ ...curr, item: curr.item.uuid });
|
||||
|
||||
return acc;
|
||||
}, updates);
|
||||
return test;
|
||||
this.document.update({ 'system.sidebarFavorites': [...this.document.system.sidebarFavorites, item] });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -548,9 +548,7 @@ export default function DHApplicationMixin(Base) {
|
|||
callback: async (target, _event) => {
|
||||
const doc = await getDocFromElement(target);
|
||||
this.document.update({
|
||||
'system.sidebarFavorites': this.document.system.sidebarFavorites
|
||||
.filter(x => x.item.id !== doc.id)
|
||||
.map(x => ({ ...x, item: x.item.uuid }))
|
||||
'system.sidebarFavorites': this.document.system.sidebarFavorites.filter(x => x.id !== doc.id)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -568,15 +566,8 @@ export default function DHApplicationMixin(Base) {
|
|||
},
|
||||
callback: async (target, _event) => {
|
||||
const doc = await getDocFromElement(target);
|
||||
const nextSort = this.document.system.sidebarFavorites.length
|
||||
? this.document.system.sidebarFavorites.reduce((acc, curr) => Math.max(curr.sort, acc), 0) +
|
||||
100000
|
||||
: 0;
|
||||
this.document.update({
|
||||
'system.sidebarFavorites': [
|
||||
...this.document.system.sidebarFavorites.map(x => ({ ...x, item: x.item.uuid })),
|
||||
{ sort: nextSort, item: doc.uuid }
|
||||
]
|
||||
'system.sidebarFavorites': [...this.document.system.sidebarFavorites, doc]
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -286,12 +286,7 @@ export default class DhCharacter extends BaseDataActor {
|
|||
ignore: new fields.BooleanField()
|
||||
})
|
||||
}),
|
||||
sidebarFavorites: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
sort: new fields.NumberField({ required: true, nullable: false, integer: true }),
|
||||
item: new ForeignDocumentUUIDField({ type: 'Item' })
|
||||
})
|
||||
)
|
||||
sidebarFavorites: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,10 +109,10 @@
|
|||
type="attack"
|
||||
}}
|
||||
{{/if}}
|
||||
{{#each sidebarFavorites as |data|}}
|
||||
{{#each sidebarFavorites as |item|}}
|
||||
{{> 'daggerheart.inventory-item-compact'
|
||||
item=data.item
|
||||
type=data.item.type
|
||||
item=item
|
||||
type=item.type
|
||||
}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
|
@ -122,28 +122,28 @@
|
|||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<div class="experience-section">
|
||||
<div class="title">
|
||||
<side-line-div class="invert"></side-line-div>
|
||||
<h3>{{localize "DAGGERHEART.GENERAL.experience.single"}}</h3>
|
||||
<side-line-div></side-line-div>
|
||||
</div>
|
||||
<div class="experience-list">
|
||||
{{#each document.system.experiences as |experience id|}}
|
||||
<div class="experience-row" data-tooltip-text="{{experience.description}}">
|
||||
<span class="experience-value">
|
||||
+{{experience.value}}
|
||||
</span>
|
||||
<span class="experience-name">{{experience.name}}</span>
|
||||
<div class="controls">
|
||||
<a data-action="sendExpToChat" data-type="experience" data-id="{{id}}">
|
||||
<i class="fa-regular fa-message"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="experience-section">
|
||||
<div class="title">
|
||||
<side-line-div class="invert"></side-line-div>
|
||||
<h3>{{localize "DAGGERHEART.GENERAL.experience.single"}}</h3>
|
||||
<side-line-div></side-line-div>
|
||||
</div>
|
||||
<div class="experience-list">
|
||||
{{#each document.system.experiences as |experience id|}}
|
||||
<div class="experience-row" data-tooltip-text="{{experience.description}}">
|
||||
<span class="experience-value">
|
||||
+{{experience.value}}
|
||||
</span>
|
||||
<span class="experience-name">{{experience.name}}</span>
|
||||
<div class="controls">
|
||||
<a data-action="sendExpToChat" data-type="experience" data-id="{{id}}">
|
||||
<i class="fa-regular fa-message"></i>
|
||||
</a>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
Loading…
Add table
Add a link
Reference in a new issue