Skip to content

Commit

Permalink
Added toHit just like the new save prop.
Browse files Browse the repository at this point in the history
  • Loading branch information
kgar committed Feb 4, 2025
1 parent c26714b commit a58867a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/features/item/ItemContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ export class ItemContext {
};
}
}

static getToHit(item: Item5e): number | null {
const toHit = parseInt(item.labels.modifier);
return item.hasAttack && !isNaN(toHit) ? toHit : null;
}
}
5 changes: 4 additions & 1 deletion src/sheets/classic/Tidy5eCharacterSheet.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,10 @@ export class Tidy5eCharacterSheet

// Save
context.save = ItemContext.getItemSaveContext(item);


// To Hit
context.toHit = ItemContext.getToHit(item);

// Activities
context.activities = Activities.getVisibleActivities(
item,
Expand Down
1 change: 1 addition & 0 deletions src/sheets/classic/Tidy5eGroupSheetClassic.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ export class Tidy5eGroupSheetClassic extends Tidy5eActorSheetBaseMixin(
hasUses: item.hasLimitedUses,
isStack: item.system.quantity > 1,
save: ItemContext.getItemSaveContext(item),
toHit: ItemContext.getToHit(item),
totalWeight: (await item.system.totalWeight)?.toNearest(0.1) ?? 0,
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/sheets/classic/Tidy5eKgarVehicleSheet.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ export class Tidy5eVehicleSheet
// Save
ctx.save = ItemContext.getItemSaveContext(item);

// To Hit
ctx.toHit = ItemContext.getToHit(item);

// Activities
ctx.activities = Activities.getVisibleActivities(
item,
Expand Down
3 changes: 3 additions & 0 deletions src/sheets/classic/Tidy5eNpcSheet.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ export class Tidy5eNpcSheet
// Save
ctx.save = ItemContext.getItemSaveContext(item);

// To Hit
ctx.toHit = ItemContext.getToHit(item);

ctx.totalWeight = item.system.totalWeight?.toNearest(0.1);
if (item.type === CONSTANTS.ITEM_TYPE_SPELL) {
if (this._concentration.items.has(item)) {
Expand Down
10 changes: 6 additions & 4 deletions src/sheets/classic/actor/tabs/ActorActionsTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
setSearchResultsContext,
} from 'src/features/search/search.svelte';
import { getSheetContext } from 'src/sheets/sheet-context.svelte';
import { formatAsModifier } from 'src/utils/formatting';
let context =
$derived(
Expand Down Expand Up @@ -260,7 +261,7 @@
<ItemTableCell baseWidth="5rem" cssClass="flex-column no-gap">
<!-- HIT / DC -->
{@const save = ctx?.save}
{#if save?.dc || actionItem.item.labels?.toHit}
{#if save?.dc || ctx?.toHit}
{#if save?.dc}
<span
title={actionItem.item.labels?.save ?? ''}
Expand All @@ -276,9 +277,10 @@
{save.ability}
</small>
{:else}
<span title={actionItem.item.labels?.toHit ?? ''}
>{actionItem.item.labels?.toHit ?? ''}</span
>
{@const toHit = formatAsModifier(
ctx.toHit?.toString() ?? '',
)}
<span>{toHit}</span>
{/if}
{/if}
</ItemTableCell>
Expand Down
1 change: 1 addition & 0 deletions src/types/group.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface GroupItemContext {
hasUses?: boolean;
isStack?: boolean;
save?: ItemSaveContext;
toHit?: number | null;
totalWeight?: number;
}

Expand Down
3 changes: 3 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export type CharacterItemContext = {
linkedUses?: LinkedUses;
needsSubclass?: boolean;
save?: ItemSaveContext;
toHit?: number | null;
toggleClass?: string;
toggleTitle?: string;
totalWeight?: number;
Expand Down Expand Up @@ -434,6 +435,7 @@ export type NpcItemContext = {
needsSubclass?: boolean;
parent?: Item5e;
save?: ItemSaveContext;
toHit?: number | null;
toggleTitle?: string;
totalWeight?: number;
};
Expand Down Expand Up @@ -480,6 +482,7 @@ export type VehicleItemContext = {
cover?: string;
hasUses?: boolean;
save?: ItemSaveContext;
toHit?: number | null;
threshold?: number | string;
toggleClass?: string;
toggleTitle?: string;
Expand Down

0 comments on commit a58867a

Please sign in to comment.