Skip to content

Commit

Permalink
Added generic actorUsesActionFeature function to the actions script.
Browse files Browse the repository at this point in the history
Added useActionsFeature boolean to all actor sheet contexts.

Limited presence of action filter override control to when useActionsFeature is true.

Added Action Filter Override and Clear Override options to context menu.
  • Loading branch information
kgar committed Nov 25, 2023
1 parent 5ae14d2 commit 9c2dcec
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 24 deletions.
3 changes: 2 additions & 1 deletion public/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"OverriddenSetOverrideFalse": "Remove from Actions List (Shift+Click to clear override)",
"OverriddenSetOverrideTrue": "Add to Actions List (Shift+Click to clear override)",
"SetOverrideFalse": "Remove from Actions List",
"SetOverrideTrue": "Add to Actions List"
"SetOverrideTrue": "Add to Actions List",
"ClearOverride": "Clear Action Override"
},

"T5EK.HitDC": "Hit / DC",
Expand Down
31 changes: 31 additions & 0 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CONSTANTS } from 'src/constants';
import { FoundryAdapter } from 'src/foundry/foundry-adapter';
import { SettingsProvider } from 'src/settings/settings';
import type { Item5e } from 'src/types/item';
Expand Down Expand Up @@ -202,3 +203,33 @@ export const damageTypeIconMap: Record<string, string> = {
healing: '<i class="fas fa-heart"></i>',
temphp: '<i class="fas fa-shield-alt"></i>',
};

export function actorUsesActionFeature(actor: Actor5e) {
const selectedTabIds = FoundryAdapter.tryGetFlag<string[] | undefined>(
actor,
'selected-tabs'
);

if (selectedTabIds) {
return selectedTabIds.includes(CONSTANTS.TAB_ACTOR_ACTIONS);
}

const defaultTabIds =
actor.type === CONSTANTS.SHEET_TYPE_CHARACTER
? SettingsProvider.settings.defaultCharacterSheetTabs.get()
: actor.type === CONSTANTS.SHEET_TYPE_NPC
? SettingsProvider.settings.defaultNpcSheetTabs.get()
: actor.type === CONSTANTS.SHEET_TYPE_VEHICLE
? SettingsProvider.settings.defaultVehicleSheetTabs.get()
: [];

return defaultTabIds.includes(CONSTANTS.TAB_ACTOR_ACTIONS);
}

export function toggleActionFilterOverride(item: Item5e) {
FoundryAdapter.setFlag(
item,
'action-filter-override',
!isItemInActionList(item)
);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { Item5e } from 'src/types/item';
import ItemControl from './ItemControl.svelte';
import { isItemInActionList } from 'src/actions/actions';
import { isItemInActionList, toggleActionFilterOverride } from 'src/actions/actions';
import { FoundryAdapter } from 'src/foundry/foundry-adapter';
export let item: Item5e;
Expand Down Expand Up @@ -33,5 +33,5 @@
on:click={(ev) =>
ev.shiftKey
? FoundryAdapter.unsetFlag(item, 'action-filter-override')
: FoundryAdapter.toggleActionFilterOverride(item)}
: toggleActionFilterOverride(item)}
/>
4 changes: 3 additions & 1 deletion src/components/spellbook/SpellbookList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@
<ItemDuplicateControl item={spell} />
<ItemDeleteControl item={spell} />
{/if}
<ActionFilterOverrideControl item={spell} />
{#if $context.useActionsFeature}
<ActionFilterOverrideControl item={spell} />
{/if}
</ItemControls>
</ItemTableCell>
{/if}
Expand Down
32 changes: 32 additions & 0 deletions src/context-menu/tidy5e-context-menu.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
actorUsesActionFeature,
isItemInActionList,
toggleActionFilterOverride,
} from 'src/actions/actions';
import { CONSTANTS } from 'src/constants';
import { FoundryAdapter } from 'src/foundry/foundry-adapter';
import { SettingsProvider } from 'src/settings/settings';
Expand Down Expand Up @@ -301,5 +306,32 @@ function getItemContextOptions(item: Item5e) {
});
}
}

if (actorUsesActionFeature(actor)) {
const active = isItemInActionList(item);
options.push({
name: active
? 'T5EK.Actions.SetOverrideFalse'
: 'T5EK.Actions.SetOverrideTrue',
icon: active
? '<i class="fas fa-fist-raised" style="color: var(--t5ek-warning-accent-color)"></i>'
: '<i class="fas fa-fist-raised"></i>',
callback: () => {
toggleActionFilterOverride(item);
},
});

const overridden =
FoundryAdapter.tryGetFlag(item, 'action-filter-override') !== undefined;
if (overridden) {
options.push({
name: 'T5EK.Actions.ClearOverride',
icon: '<i class="fas fa-fist-raised" style="color: var(--t5ek-warning-accent-color)"></i>',
callback: () => {
FoundryAdapter.unsetFlag(item, 'action-filter-override');
},
});
}
}
return options;
}
7 changes: 0 additions & 7 deletions src/foundry/foundry-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,11 +1116,4 @@ export const FoundryAdapter = {
? FoundryAdapter.localize('DND5E.ActionOther')
: game.dnd5e.config.abilityActivationTypes[activationType];
},
toggleActionFilterOverride(item: Item5e) {
FoundryAdapter.setFlag(
item,
'action-filter-override',
!isItemInActionList(item)
);
},
};
9 changes: 5 additions & 4 deletions src/sheets/Tidy5eCharacterSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { SvelteComponent } from 'svelte';
import { getPercentage } from 'src/utils/numbers';
import type { ItemChatData } from 'src/types/item';
import { registeredCharacterTabs } from 'src/runtime/character-sheet-state';
import { getActorActions } from 'src/actions/actions';
import { actorUsesActionFeature, getActorActions } from 'src/actions/actions';

export class Tidy5eCharacterSheet
extends dnd5e.applications.actor.ActorSheet5eCharacter
Expand Down Expand Up @@ -183,9 +183,6 @@ export class Tidy5eCharacterSheet
relativeTo: this.actor,
}
),
useClassicControls:
SettingsProvider.settings.useClassicControlsForCharacter.get(),
useJournalTab: SettingsProvider.settings.useJournalTabForCharacter.get(),
editable,
features: sections,
flawEnrichedHtml: await FoundryAdapter.enrichHtml(
Expand Down Expand Up @@ -290,6 +287,10 @@ export class Tidy5eCharacterSheet
relativeTo: this.actor,
}
),
useActionsFeature: actorUsesActionFeature(this.actor),
useClassicControls:
SettingsProvider.settings.useClassicControlsForCharacter.get(),
useJournalTab: SettingsProvider.settings.useJournalTabForCharacter.get(),
useRoundedPortraitStyle: [
CONSTANTS.CIRCULAR_PORTRAIT_OPTION_ALL as string,
CONSTANTS.CIRCULAR_PORTRAIT_OPTION_CHARACTER as string,
Expand Down
3 changes: 2 additions & 1 deletion src/sheets/Tidy5eKgarVehicleSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { debug } from 'src/utils/logging';
import { getPercentage } from 'src/utils/numbers';
import type { ItemChatData } from 'src/types/item';
import { registeredVehicleTabs } from 'src/runtime/vehicle-sheet-state';
import { getActorActions } from 'src/actions/actions';
import { actorUsesActionFeature, getActorActions } from 'src/actions/actions';

export class Tidy5eVehicleSheet
extends dnd5e.applications.actor.ActorSheet5eVehicle
Expand Down Expand Up @@ -128,6 +128,7 @@ export class Tidy5eVehicleSheet
owner: this.actor.isOwner,
showLimitedSheet: FoundryAdapter.showLimitedSheet(this.actor),
tabs: [],
useActionsFeature: actorUsesActionFeature(this.actor),
useRoundedPortraitStyle: [
CONSTANTS.CIRCULAR_PORTRAIT_OPTION_ALL as string,
CONSTANTS.CIRCULAR_PORTRAIT_OPTION_NPCVEHICLE as string,
Expand Down
6 changes: 3 additions & 3 deletions src/sheets/Tidy5eNpcSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import LongRestDialog from 'src/dialogs/NpcLongRestDialog';
import type { SvelteComponent } from 'svelte';
import type { ItemChatData } from 'src/types/item';
import { registeredNpcTabs } from 'src/runtime/npc-sheet-state';
import { getActorActions } from 'src/actions/actions';
import { actorUsesActionFeature, getActorActions } from 'src/actions/actions';

export class Tidy5eNpcSheet
extends dnd5e.applications.actor.ActorSheet5eNPC
Expand Down Expand Up @@ -285,6 +285,7 @@ export class Tidy5eNpcSheet
relativeTo: this.actor,
}
),
useActionsFeature: actorUsesActionFeature(this.actor),
useJournalTab: SettingsProvider.settings.useJournalTabForNpc.get(),
useRoundedPortraitStyle: [
CONSTANTS.CIRCULAR_PORTRAIT_OPTION_ALL as string,
Expand All @@ -306,8 +307,7 @@ export class Tidy5eNpcSheet
(a, b) => selectedTabs.indexOf(a.id) - selectedTabs.indexOf(b.id)
);
} else {
const defaultTabs =
SettingsProvider.settings.defaultNpcSheetTabs.get();
const defaultTabs = SettingsProvider.settings.defaultNpcSheetTabs.get();
tabs = tabs
.filter((t) => defaultTabs?.includes(t.id))
.sort((a, b) => defaultTabs.indexOf(a.id) - defaultTabs.indexOf(b.id));
Expand Down
4 changes: 3 additions & 1 deletion src/sheets/character/parts/InventoryList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@
<ItemDuplicateControl {item} />
<ItemDeleteControl {item} />
{/if}
<ActionFilterOverrideControl {item} />
{#if $context.useActionsFeature}
<ActionFilterOverrideControl {item} />
{/if}
</ItemControls>
</ItemTableCell>
{/if}
Expand Down
4 changes: 3 additions & 1 deletion src/sheets/character/tabs/CharacterFeaturesTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@
<ItemDuplicateControl {item} />
<ItemDeleteControl {item} />
{/if}
<ActionFilterOverrideControl {item} />
{#if $context.useActionsFeature}
<ActionFilterOverrideControl {item} />
{/if}
</ItemTableCell>
{/if}
</ItemTableRow>
Expand Down
4 changes: 3 additions & 1 deletion src/sheets/npc/tabs/NpcAbilitiesTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@
<ItemDuplicateControl {item} />
<ItemDeleteControl {item} />
{/if}
<ActionFilterOverrideControl {item} />
{#if $context.useActionsFeature}
<ActionFilterOverrideControl {item} />
{/if}
</ItemControls>
</ItemTableCell>
{/if}
Expand Down
4 changes: 3 additions & 1 deletion src/sheets/vehicle/tabs/VehicleAttributesTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@
<ItemDuplicateControl {item} />
<ItemDeleteControl {item} />
{/if}
<ActionFilterOverrideControl {item} />
{#if $context.useActionsFeature}
<ActionFilterOverrideControl {item} />
{/if}
</ItemControls>
</ItemTableCell>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion src/sheets/vehicle/tabs/VehicleCargoAndCrewTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
/>
{/if}

{#if $context.editable && !section.editableName}
{#if $context.editable && !section.editableName && $context.useActionsFeature}
<ActionFilterOverrideControl {item} />
{/if}
</ItemControls>
Expand Down
1 change: 1 addition & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export type ActorSheetContext = {
owner: boolean;
showLimitedSheet: boolean;
tabs: Tab[];
useActionsFeature?: boolean;
useClassicControls: boolean;
useRoundedPortraitStyle: boolean;
} & JQueryHooksSheetIntegration &
Expand Down

0 comments on commit 9c2dcec

Please sign in to comment.