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

dnd5e: Compatibility pack 1 #940

Merged
merged 24 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5a145d7
Removed deprecated hook "tidy5e-sheet.renderItemSheet" and updated al…
kgar Jan 21, 2025
0aff661
Fixed known broken localization keys.
kgar Jan 21, 2025
bd4ddbc
Fixed XP abbreviation loc key
kgar Jan 22, 2025
c3f615b
Fixed health and speed conditions loc keys.
kgar Jan 22, 2025
0cda0cf
Fixed remaining known loc keys, except for Container details and deta…
kgar Jan 22, 2025
a338fe0
Resolve dep warnings by updating CONIG.DND5E types for movement units…
kgar Jan 22, 2025
2212889
Added roll link group to roll link styles.
kgar Jan 22, 2025
9f26fab
Ported vehicle change to handling crew actions and preparign vehicle …
kgar Jan 22, 2025
770a3af
Added new recoveryOptions to config dnd5e types.
kgar Jan 22, 2025
c3f3ad5
Added modernRules context setting to all sheets.
kgar Jan 22, 2025
e73f870
The system now makes i elements inert. Updated to avoid blurring those.
kgar Jan 22, 2025
6e8d6d3
Added needed config dnd5e stuff.
kgar Jan 22, 2025
1401c67
Updated capacity bar to use lemniscate instead of the word Infinity.
kgar Jan 22, 2025
d6333f9
Applied revamp to hightouch container sheet.
kgar Jan 22, 2025
08bdda1
Added weight unit input to item weight: containers and regular items …
kgar Jan 22, 2025
43c8d78
Implemented loyalty tracker.
kgar Jan 22, 2025
0438b23
Implemented Important NPC hit dice counter.
kgar Jan 22, 2025
9c0ad77
Added hasLegendaries context prop for NPCs.
kgar Jan 23, 2025
d9c84bc
Implemented 2024 Lair content on the NPC sheet.
kgar Jan 23, 2025
c918e1a
Merge branch 'main' of github.com:kgar/foundry-tidy5e-sheet-2 into dn…
kgar Jan 23, 2025
a7725cb
Limited NPC Death Saves to important NPCs.
kgar Jan 23, 2025
4f6ce6e
Added Treasure Trait Section and Treasure Config.
kgar Jan 23, 2025
6348f94
Swapped languages to use the correct application window and now rende…
kgar Jan 23, 2025
60b0c11
???
kgar Jan 23, 2025
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
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.1.0",
"verified": "4.1.0",
"maximum": "4.1.x"
"minimum": "4.2.0",
"verified": "4.2.0",
"maximum": "4.2.x"
}
}
],
Expand Down
3 changes: 2 additions & 1 deletion src/api/Tidy5eSheetsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,8 @@ export class Tidy5eSheetsApi {
* @returns the original HTML with a transparent element wrapped around which indicates to Tidy that this should be removed and re-rendered.
*
* @remarks
* The intended use of this function is to accompany the use of the `tidy5e-sheet.renderActorSheet` or `tidy5e-sheet.renderItemSheet` hook.
* The intended use of this function is to accompany the use of the `tidy5e-sheet.renderActorSheet` hook in App V1 (PCs, NPCs, Vehicles)
* or the standard sheet render hooks in App V2 (Items, Containers, Groups).
* Any content injected through those hooks needs to be wrapped in this way so that the old version
* of the HTML can be removed before adding it back in.
* Handlebars refreshes content in this way, but for Tidy purposes, the module needs to know when an arbitrary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
{
type: CONSTANTS.SHEET_TYPE_NPC,
label: localize('DND5E.NPC'),
label: localize('DND5E.NPC.Label'),
tabs: mapTabs(NpcSheetRuntime.tabMap, [
CONSTANTS.TAB_NPC_ABILITIES,
CONSTANTS.TAB_ACTOR_INVENTORY,
Expand Down Expand Up @@ -90,7 +90,7 @@
}

return mappedTabs.sort((left, right) =>
left.title.localeCompare(right.title),
left.title.localeCompare(right.title, game.i18n.lang),
);
}

Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ export const CONSTANTS = {
SHEET_SETTINGS_OPTION_GM_AND_OWNERS: 'gm-and-owners',
TEXT_EDITOR_ACTIVATION_ELEMENT_SELECTOR: '.editor-content[data-edit]',
SKILL_KEY_PERCEPTION: 'prc',
TREASURE_ANY: 'any',
SVELTE_CONTEXT: {
ACCORDION_CONTEXT: 'accordionContext',
APP_ID: 'appId',
Expand Down
12 changes: 8 additions & 4 deletions src/features/conditions-and-effects/ConditionsAndEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ export class ConditionsAndEffects {
const { id, name, img, disabled, duration } = effect;
let source = (await effect.getSource()) ?? actor;
// If the source is an ActiveEffect from another Actor, note the source as that Actor instead.
if (
source instanceof dnd5e.documents.ActiveEffect5e &&
source.target !== object
) {
if (source instanceof ActiveEffect) {
source = source.target;
if (
source instanceof Item &&
source.parent &&
source.parent !== object
) {
source = source.parent;
}
}

arr = await arr;
Expand Down
2 changes: 1 addition & 1 deletion src/features/sections/SheetSections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export class SheetSections {

return Array.from<string>(sectionSet)
.filter((x) => !isNil(x, ''))
.toSorted((left, right) => left.localeCompare(right));
.toSorted((left, right) => left.localeCompare(right, game.i18n.lang));
}

static getFilteredGlobalSectionsToShowWhenEmpty(
Expand Down
29 changes: 0 additions & 29 deletions src/foundry/TidyFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,35 +926,6 @@ export class TidyFlags {
},
};

/**
* Indicates whether the legendary toolbar should be shown for a given NPC.
*/
static showLegendaryToolbar = {
key: 'showLegendaryToolbar' as const,
prop: TidyFlags.getFlagPropertyPath('showLegendaryToolbar'),
/** Gets whether the legendary toolbar should be shown for an NPC. */
get(actor: Actor5e): boolean | undefined {
return (
TidyFlags.tryGetFlag<boolean>(
actor,
TidyFlags.showLegendaryToolbar.key
) ?? undefined
);
},
/** Sets whether the legendary toolbar should be shown for an NPC. */
set(actor: Actor5e, value: boolean): Promise<void> {
return TidyFlags.setFlag(
actor,
TidyFlags.showLegendaryToolbar.key,
value
);
},
/** Clears whether the legendary toolbar should be shown for an NPC. */
unset(actor: Actor5e) {
return TidyFlags.unsetFlag(actor, TidyFlags.showLegendaryToolbar.key);
},
};

/**
* Indicates whether the additional personality info should be shown
* for a given NPC on the biography tab.
Expand Down
28 changes: 0 additions & 28 deletions src/foundry/TidyHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,34 +479,6 @@ export class TidyHooks {
Hooks.callAll('tidy5e-sheet.renderActorSheet', app, element, data, forced);
}

/**
* The item sheet has rendered all content and registered custom content. Is called on partial and full renders.
* @param {any} app The target item sheet application class instance.
* @param {HTMLElement} element The item sheet's HTML element.
* @param {ContainerSheetClassicContext | ItemSheetContext} data The data context from `getData()`.
* @param {boolean} forced `true` when performing a full re-render; `false` when performing a partial re-render.
*
* @example
* ```js
* Hooks.on('tidy5e-sheet.renderItemSheet', (app, element, data, forced) => {
* // Your code here
* });
* ```
*
* @deprecated This hook is now redundant for App V2 item and container sheets. It will be removed as of Tidy V8.
*/
static tidy5eSheetsRenderItemSheet(
app: any,
element: HTMLElement,
data:
| ContainerSheetClassicContext
| ItemSheetContext
| ContainerSheetHightouchContext,
forced: boolean
) {
Hooks.callAll('tidy5e-sheet.renderItemSheet', app, element, data, forced);
}

/**
* A tab has been selected on the sheet.
* @param {any} app The sheet application instance.
Expand Down
80 changes: 66 additions & 14 deletions src/foundry/config.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,42 @@ type CurrencyItemConfig = {
conversion: number;
};

interface MovementUnitConfig {
label: string;
abbreviation: string;
conversion: number;
formattingUnit: string;
type: string;
}

interface IndividualTargetTypesConfig {
label: string;
scalar?: boolean;
counted: string;
}

interface RecoveryOption {
value: string;
label: string;
group?: string;
}

interface VolumeUnitConfig {
label: string;
abbreviation: string;
counted?: string;
conversion: number;
type: string;
}

interface TreasureConfig {
label: string;
}

interface CommunicationTypeConfig {
label: string;
}

export type CONFIG = {
debug: {
applications: boolean;
Expand Down Expand Up @@ -2493,6 +2529,9 @@ export type CONFIG = {
cha: Dnd5eAbility;
} & Record<string, Dnd5eAbility>;
areaTargetOptions: GroupableSelectOption[];
communicationTypes: {
telepathy: CommunicationTypeConfig;
} & Record<string, CommunicationTypeConfig>;
defaultAbilities: {
meleeAttack: string;
rangedAttack: string;
Expand Down Expand Up @@ -3241,6 +3280,7 @@ export type CONFIG = {
abbreviation: string;
formula: boolean;
};
recoveryOptions: RecoveryOption[];
};
enchantmentPeriods: {
sr: {
Expand Down Expand Up @@ -3738,10 +3778,10 @@ export type CONFIG = {
walk: string;
};
movementUnits: {
ft: string;
mi: string;
m: string;
km: string;
ft: MovementUnitConfig;
mi: MovementUnitConfig;
m: MovementUnitConfig;
km: MovementUnitConfig;
};
rangeTypes: {
self: string;
Expand Down Expand Up @@ -3844,16 +3884,16 @@ export type CONFIG = {
};
};
individualTargetTypes: {
self: string;
ally: string;
enemy: string;
creature: string;
object: string;
space: string;
creatureOrObject: string;
any: string;
willing: string;
};
self: IndividualTargetTypesConfig;
ally: IndividualTargetTypesConfig;
enemy: IndividualTargetTypesConfig;
creature: IndividualTargetTypesConfig;
object: IndividualTargetTypesConfig;
space: IndividualTargetTypesConfig;
creatureOrObject: IndividualTargetTypesConfig;
any: IndividualTargetTypesConfig;
willing: IndividualTargetTypesConfig;
} & Record<string, IndividualTargetTypesConfig>;
areaTargetTypes: {
circle: {
label: string;
Expand Down Expand Up @@ -5571,6 +5611,18 @@ export type CONFIG = {
woodcarver: string;
};
};
treasure: {
any: TreasureConfig;
arcana: TreasureConfig;
armaments: TreasureConfig;
implements: TreasureConfig;
individual: TreasureConfig;
relics: TreasureConfig;
} & Record<string, TreasureConfig>;
volumeUnits: {
cubicFoot: VolumeUnitConfig;
liter: VolumeUnitConfig;
} & Record<string, VolumeUnitConfig>;
};
};

Expand Down
45 changes: 32 additions & 13 deletions src/foundry/foundry-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export const FoundryAdapter = {
getTidySetting<T = string>(settingName: string): T {
return game.settings.get(CONSTANTS.MODULE_ID, settingName) as T;
},
async setTidySetting(key: keyof CurrentSettings, value: unknown): Promise<void> {
async setTidySetting(
key: keyof CurrentSettings,
value: unknown
): Promise<void> {
await game.settings.set(CONSTANTS.MODULE_ID, key, value);
},
registerTidySetting(key: string, data: any): void {
Expand Down Expand Up @@ -202,11 +205,11 @@ export const FoundryAdapter = {
if (event.button !== CONSTANTS.MOUSE_BUTTON_AUXILIARY) {
return;
}

if (!entityWithSheet.sheet.isEditable) {
return;
}

event.preventDefault();
event.stopImmediatePropagation();

Expand Down Expand Up @@ -836,16 +839,8 @@ export const FoundryAdapter = {
);
},
deleteAdvancement(advancementItemId: string, item: Item5e) {
if (item.isEmbedded && !game.settings.get('dnd5e', 'disableAdvancements')) {
let manager =
dnd5e.applications.advancement.AdvancementManager.forDeletedAdvancement(
item.actor,
item.id,
advancementItemId
);
if (manager.steps.length) return manager.render(true);
}
return item.deleteAdvancement(advancementItemId);
const advancement = item.advancement.byId[advancementItemId];
return advancement?.deleteDialog();
},
modifyAdvancementChoices(advancementLevel: string, item: Item5e) {
let manager =
Expand Down Expand Up @@ -1447,4 +1442,28 @@ export const FoundryAdapter = {
: FoundryAdapter.localize('DND5E.AbbreviationDC')
: null;
},
checkIfModernRules(document: any) {
return document.system.source?.rules
? document.system.source?.rules === '2024'
: game.settings.get('dnd5e', 'rulesVersion') === 'modern';
},
prepareLanguageTrait(actor: any, traits: any) {
const languages = actor.system.traits?.languages?.labels;
if (languages?.languages?.length)
traits.languages = languages.languages.map((label: string) => ({
label,
}));
for (const [key, { label }] of Object.entries(
CONFIG.DND5E.communicationTypes
)) {
const data = actor.system.traits?.languages?.communication?.[key];
if (!data?.value) continue;
let value = data.value;
if (data.units) {
value += ` ${data.units}`;
}
traits.languages ??= [];
traits.languages.push({ label, value: value });
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { settings } from 'src/settings/settings.svelte';
export class TidyCustomSectionsInDefaultItemSheetIntegration
implements SystemIntegrationBase
{
init(api: Tidy5eSheetsApi): void {
init(_: Tidy5eSheetsApi): void {
Hooks.on('renderItemSheet5e', (app: any) => {
const includeSectionFields =
settings.value.includeTidySectionFieldsInDefaultSheets;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/item/default-item-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const defaultItemFilters = {
!!item.system.activities?.some(
(a: any) => a.activation?.type === CONSTANTS.ACTIVATION_COST_LEGENDARY
),
text: 'DND5E.LegendaryActionLabel',
text: 'DND5E.LegendaryAction.Label',
},
activationCostMythic: {
name: 'activationCostMythic',
Expand All @@ -51,7 +51,7 @@ export const defaultItemFilters = {
!!item.system.activities?.some(
(a: any) => a.activation?.type === CONSTANTS.ACTIVATION_COST_LAIR
),
text: 'DND5E.LairActionLabel',
text: 'DND5E.LAIR.Action.Label',
},
activationCostCrew: {
name: 'activationCostCrew',
Expand Down
Loading