Skip to content

Commit

Permalink
Merge pull request #832 from kgar/dnd5e-4.1.x-compat
Browse files Browse the repository at this point in the history
dnd5e: 4.1.x compatibility
  • Loading branch information
kgar authored Nov 13, 2024
2 parents 2b066e5 + 428dcbf commit 77efa2d
Show file tree
Hide file tree
Showing 37 changed files with 535 additions and 303 deletions.
6 changes: 3 additions & 3 deletions public/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
{
"id": "dnd5e",
"compatibility": {
"minimum": "4.0.0",
"verified": "4.0.0",
"maximum": "4.0.x"
"minimum": "4.1.0",
"verified": "4.1.0",
"maximum": "4.1.x"
}
}
],
Expand Down
13 changes: 13 additions & 0 deletions src/components/item-list/controls/DeleteOrOpenActivity.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script lang="ts">
import type { Item5e } from 'src/types/item.types';
import SpellOpenCastActivityControl from './SpellOpenCastActivityControl.svelte';
import ItemDeleteControl from './ItemDeleteControl.svelte';
export let item: Item5e;
</script>

{#if item.canDelete || !item.system.linkedActivity}
<ItemDeleteControl {item} />
{:else}
<SpellOpenCastActivityControl {item} />
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import { FoundryAdapter } from 'src/foundry/foundry-adapter';
import ItemControl from './ItemControl.svelte';
import type { Item5e } from 'src/types/item.types';
export let item: Item5e;
const localize = FoundryAdapter.localize;
</script>

<ItemControl
iconCssClass="fas fa-gear"
class={$$restProps.class ?? ''}
onclick={() => item.system.linkedActivity.sheet.render(true)}
title={localize('DOCUMENT.DND5E.Activity')}
/>
12 changes: 6 additions & 6 deletions src/components/spellbook/SpellbookFooter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
{#if $context.spellcastingInfo.calculations.rangedMod !== $context.spellcastingInfo.calculations.meleeMod}
<button
type="button"
on:click={(ev) =>
rollRawSpellAttack(
on:click={async (ev) =>
await rollRawSpellAttack(
ev,
$context.actor,
'rsak',
Expand All @@ -73,8 +73,8 @@
</button>
<button
type="button"
on:click={(ev) =>
rollRawSpellAttack(
on:click={async (ev) =>
await rollRawSpellAttack(
ev,
$context.actor,
'msak',
Expand All @@ -101,8 +101,8 @@
{:else}
<button
type="button"
on:click={(ev) =>
rollRawSpellAttack(
on:click={async (ev) =>
await rollRawSpellAttack(
ev,
$context.actor,
undefined,
Expand Down
9 changes: 7 additions & 2 deletions src/components/spellbook/SpellbookList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import type { Item5e } from 'src/types/item.types';
import ClassicControls from 'src/sheets/shared/ClassicControls.svelte';
import ConcentrationOverlayIcon from './ConcentrationOverlayIcon.svelte';
import DeleteOrOpenActivity from '../item-list/controls/DeleteOrOpenActivity.svelte';
let context = getContext<Readable<CharacterSheetContext | NpcSheetContext>>(
CONSTANTS.SVELTE_CONTEXT.CONTEXT,
Expand Down Expand Up @@ -86,7 +87,8 @@
if ($context.unlocked) {
controls.push({
component: ItemDeleteControl,
// svelte 5 - snippet?
component: DeleteOrOpenActivity,
props: ({ item }) => ({
item,
}),
Expand Down Expand Up @@ -209,7 +211,10 @@
<InlineFavoriteIcon />
{/if}
<ItemTableCell baseWidth={spellComponentsBaseWidth} cssClass="no-gap">
<SpellComponents {spell} spellComponentLabels={$context.spellComponentLabels} />
<SpellComponents
{spell}
spellComponentLabels={$context.spellComponentLabels}
/>
</ItemTableCell>
{#if includeSchool}
{@const icon = SpellSchool.getIcon(spell.system.school)}
Expand Down
58 changes: 39 additions & 19 deletions src/context-menu/tidy5e-context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,21 +286,23 @@ function getItemContextOptions(item: Item5e) {
}

// Toggle Prepared State
if ('preparation' in item.system) {
if (FoundryAdapter.canPrepareSpell(item)) {
const isPrepared = item.system?.preparation?.prepared === true;
options.push({
name: isActive
? 'TIDY5E.ContextMenuActionUnprepare'
: 'TIDY5E.ContextMenuActionPrepare',
icon: isActive
? "<i class='fas fa-book fa-fw'></i>"
: "<i class='fas fa-book fa-fw'></i>",
callback: () =>
item.update({ 'system.preparation.prepared': !isPrepared }),
condition: () => item.isOwner && !item.compendium?.locked,
});
}
if (
'preparation' in item.system &&
FoundryAdapter.canPrepareSpell(item) &&
!item.getFlag('dnd5e', 'cachedFor')
) {
const isPrepared = item.system?.preparation?.prepared === true;
options.push({
name: isActive
? 'TIDY5E.ContextMenuActionUnprepare'
: 'TIDY5E.ContextMenuActionPrepare',
icon: isActive
? "<i class='fas fa-book fa-fw'></i>"
: "<i class='fas fa-book fa-fw'></i>",
callback: () =>
item.update({ 'system.preparation.prepared': !isPrepared }),
condition: () => item.isOwner && !item.compendium?.locked,
});
}

options.push({
Expand Down Expand Up @@ -349,7 +351,7 @@ function getItemContextOptions(item: Item5e) {
icon: "<i class='fas fa-copy fa-fw'></i>",
condition: () =>
isUnlocked &&
!['race', 'background', 'class', 'subclass'].includes(item.type) &&
item.canDuplicate &&
item.isOwner &&
!item.compendium?.locked,

Expand All @@ -369,7 +371,21 @@ function getItemContextOptions(item: Item5e) {
name: 'TIDY5E.ContextMenuActionDelete',
icon: "<i class='fas fa-trash fa-fw' style='color: var(--t5e-warning-accent-color);'></i>",
callback: () => FoundryAdapter.onActorItemDelete(itemParent, item),
condition: () => isUnlocked && item.isOwner && !item.compendium?.locked,
condition: () =>
item.canDelete &&
isUnlocked &&
item.isOwner &&
!item.compendium?.locked,
});
options.push({
name: 'DOCUMENT.DND5E.Activity',
icon: "<i class='fas fa-gear fa-fw'></i>",
callback: () => item.system.linkedActivity.sheet.render(true),
condition: () =>
!item.canDelete &&
item.system.linkedActivity &&
item.isOwner &&
!item.compendium?.locked,
});
} else {
options.push({
Expand All @@ -393,14 +409,18 @@ function getItemContextOptions(item: Item5e) {
if (SettingsProvider.settings.includeFlagsInSpellScrollCreation.get()) {
options.flags = item.flags;
}

const scroll = await dnd5e.documents.Item5e.createScrollFromSpell(item, options);

const scroll = await dnd5e.documents.Item5e.createScrollFromSpell(
item,
options
);
if (scroll) {
dnd5e.documents.Item5e.create(scroll, { parent: itemParent });
}
},
condition: () =>
item.type === 'spell' &&
!item.getFlag('dnd5e', 'cachedFor') &&
itemParent?.isOwner &&
!itemParent?.compendium?.locked,
group: 'action',
Expand Down
4 changes: 2 additions & 2 deletions src/features/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ function getRangeTitles(item: Item5e): {
const firstActivity = item.system.activities?.contents[0] ?? {};

const rangeSubtitle =
(firstActivity.target.affects?.type ??
firstActivity.target.template?.type) &&
(firstActivity.target?.affects?.type ??
firstActivity.target?.template?.type) &&
item.labels?.target
? item.labels.target
: null;
Expand Down
Loading

0 comments on commit 77efa2d

Please sign in to comment.