Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#845] Container TLC #849

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/scss/partials/_items.scss
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,13 @@ document-tags button {
.price {
display: flex;
align-items: center;
gap: 0.25rem
gap: 0.25rem;
}
}

.window-content
:is(.tidy-table-cell, .inventory-currency)
:is(input[type='text'], input[type='number']) {
--input-background-color: transparent;
padding-inline: 0.125rem;
}
15 changes: 14 additions & 1 deletion src/sheets/container/ContainerContentsSections.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import type { Readable } from 'svelte/store';
import InlineContainerView from './InlineContainerView.svelte';
import InlineActivitiesList from 'src/components/item-list/InlineActivitiesList.svelte';
import ItemUses from 'src/components/item-list/ItemUses.svelte';
import ItemAddUses from 'src/components/item-list/ItemAddUses.svelte';

export let contents: InventorySection[];
export let container: Item5e;
Expand Down Expand Up @@ -81,7 +83,7 @@
? `/* Controls */ ${classicControlWidthRems * classicControls.length}rem`
: '';

$: gridTemplateColumns = `/* Name */ 1fr /* Weight */ 3rem /* Quantity */ 3rem ${classicControlsWidth}`;
$: gridTemplateColumns = `/* Name */ 1fr /* Uses */ 3.125rem /* Weight */ 3rem /* Quantity */ 3rem ${classicControlsWidth}`;

const localize = FoundryAdapter.localize;
</script>
Expand All @@ -101,6 +103,9 @@
<TidyTableHeaderCell primary={true}>
{localize(section.label)} ({section.items.length})
</TidyTableHeaderCell>
<TidyTableHeaderCell title={localize('DND5E.Charges')}>
<i class="fas fa-bolt" />
</TidyTableHeaderCell>
<TidyTableHeaderCell>
{localize('DND5E.Weight')}
</TidyTableHeaderCell>
Expand Down Expand Up @@ -154,6 +159,7 @@
>{item.name}</span
>
</ItemName>

{#if !FoundryAdapter.concealDetails(item)}
{@const attunementContext =
FoundryAdapter.getAttunementContext(item)}
Expand All @@ -170,6 +176,13 @@
<InlineFavoriteIcon />
{/if}
</TidyTableCell>
<TidyTableCell>
{#if item.hasLimitedUses}
<ItemUses {item} />
{:else}
<ItemAddUses {item} />
{/if}
</TidyTableCell>
<TidyTableCell
title={localize('TIDY5E.Inventory.Weight.Text', {
weight: weight,
Expand Down
32 changes: 30 additions & 2 deletions src/sheets/mixins/BaseSheetCustomSectionMixin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TidyFlags } from 'src/foundry/TidyFlags';
import type { Item5e } from 'src/types/item.types';
import type { Actor5e } from 'src/types/types';
import { isNil } from 'src/utils/data';

/**
Expand All @@ -16,15 +17,38 @@ type OwnedItemsFunction = (object: any) => Map<string, Item5e>;
*/
export function BaseSheetCustomSectionMixin<
T extends new (...args: any[]) => {
_onDropItemCreate(item: any, event: DragEvent): Promise<any> | void;
_onSortItem(
event: DragEvent,
itemData: Record<string, unknown>
itemData: Record<string, unknown>,
allowSectionTransfer?: boolean
): Promise<any> | void;
actor: Actor5e;
object: any;
}
>(itemsFn: OwnedItemsFunction, Base: T) {
return class extends Base {
async _onSortItem(event: DragEvent, itemData: Record<string, unknown>) {
async _onDropItem(event: DragEvent, data: any) {
if (!this.actor.isOwner) return false;
const item = await Item.implementation.fromDropData(data);

// Handle moving out of container & item sorting
if (this.actor.uuid === item.parent?.uuid) {
const removingFromContainer = item.system.container !== null;
if (removingFromContainer) {
await item.update({ 'system.container': null });
}
return this._onSortItem(event, item.toObject(), !removingFromContainer);
}

return this._onDropItemCreate(item, event);
}

async _onSortItem(
event: DragEvent,
itemData: Record<string, unknown>,
allowSectionTransfer: boolean = true
) {
const sourceSection = foundry.utils.getProperty(
itemData,
TidyFlags.section.prop
Expand All @@ -42,6 +66,10 @@ export function BaseSheetCustomSectionMixin<

const initialSortResult = await super._onSortItem(event, itemData);

if (!allowSectionTransfer) {
return initialSortResult;
}

const item = itemsFn(this.object).get(itemData._id as string);

return isMovedToNewSection
Expand Down