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.isDeath = this.document.system.deathMoveViable;
|
||||||
context.sidebarFavoritesEmpty = this.document.system.sidebarFavorites.length === 0;
|
context.sidebarFavoritesEmpty = this.document.system.sidebarFavorites.length === 0;
|
||||||
context.showfavorites = !context.sidebarFavoritesEmpty || this.document.system.usedUnarmed;
|
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) {
|
if (inventoryItem) {
|
||||||
event.dataTransfer.setDragImage(inventoryItem.querySelector('img'), 60, 0);
|
event.dataTransfer.setDragImage(inventoryItem.querySelector('img'), 60, 0);
|
||||||
}
|
}
|
||||||
|
super._onDragStart(event);
|
||||||
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 }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _onDropItem(event, item) {
|
async _onDropItem(event, item) {
|
||||||
|
|
@ -1024,45 +1019,8 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
||||||
const allowedItemTypes = ['domainCard', 'feature', 'weapon', 'armor', 'loot', 'consumable'];
|
const allowedItemTypes = ['domainCard', 'feature', 'weapon', 'armor', 'loot', 'consumable'];
|
||||||
if (!allowedItemTypes.includes(item.type)) return;
|
if (!allowedItemTypes.includes(item.type)) return;
|
||||||
|
|
||||||
const siblings = this.document.system.sidebarFavorites.filter(x => x.item.id !== item.id);
|
if (this.document.system.sidebarFavorites.some(x => x.id === item.id)) return;
|
||||||
let source = null;
|
|
||||||
|
|
||||||
const data = foundry.applications.ux.TextEditor.getDragEventData(event);
|
this.document.update({ 'system.sidebarFavorites': [...this.document.system.sidebarFavorites, item] });
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -548,9 +548,7 @@ export default function DHApplicationMixin(Base) {
|
||||||
callback: async (target, _event) => {
|
callback: async (target, _event) => {
|
||||||
const doc = await getDocFromElement(target);
|
const doc = await getDocFromElement(target);
|
||||||
this.document.update({
|
this.document.update({
|
||||||
'system.sidebarFavorites': this.document.system.sidebarFavorites
|
'system.sidebarFavorites': this.document.system.sidebarFavorites.filter(x => x.id !== doc.id)
|
||||||
.filter(x => x.item.id !== doc.id)
|
|
||||||
.map(x => ({ ...x, item: x.item.uuid }))
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -568,15 +566,8 @@ export default function DHApplicationMixin(Base) {
|
||||||
},
|
},
|
||||||
callback: async (target, _event) => {
|
callback: async (target, _event) => {
|
||||||
const doc = await getDocFromElement(target);
|
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({
|
this.document.update({
|
||||||
'system.sidebarFavorites': [
|
'system.sidebarFavorites': [...this.document.system.sidebarFavorites, doc]
|
||||||
...this.document.system.sidebarFavorites.map(x => ({ ...x, item: x.item.uuid })),
|
|
||||||
{ sort: nextSort, item: doc.uuid }
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -286,12 +286,7 @@ export default class DhCharacter extends BaseDataActor {
|
||||||
ignore: new fields.BooleanField()
|
ignore: new fields.BooleanField()
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
sidebarFavorites: new fields.ArrayField(
|
sidebarFavorites: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||||
new fields.SchemaField({
|
|
||||||
sort: new fields.NumberField({ required: true, nullable: false, integer: true }),
|
|
||||||
item: new ForeignDocumentUUIDField({ type: 'Item' })
|
|
||||||
})
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,10 @@
|
||||||
type="attack"
|
type="attack"
|
||||||
}}
|
}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#each sidebarFavorites as |data|}}
|
{{#each sidebarFavorites as |item|}}
|
||||||
{{> 'daggerheart.inventory-item-compact'
|
{{> 'daggerheart.inventory-item-compact'
|
||||||
item=data.item
|
item=item
|
||||||
type=data.item.type
|
type=item.type
|
||||||
}}
|
}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
@ -122,6 +122,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="experience-section">
|
<div class="experience-section">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
|
|
@ -145,5 +146,4 @@
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</aside>
|
</aside>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue