Skip to content

Commit

Permalink
Merge pull request #28 from kgar/alpha_2023-11-05-fixes
Browse files Browse the repository at this point in the history
[#27] Enriched Biography and Journal tabs for PCs and NPCs
  • Loading branch information
kgar authored Nov 5, 2023
2 parents 7a709dc + 76f17a9 commit c02a90b
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 26 deletions.
6 changes: 5 additions & 1 deletion src/foundry/foundry-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export const FoundryAdapter = {
);
return map;
},
getProperty(obj: any, path: string): unknown {
getProperty<T = unknown>(obj: any, path: string): T | undefined {
return foundry.utils.getProperty(obj, path);
},
getInventoryRowClasses(item: Item5e, ctx?: any, extras?: string[]): string {
Expand Down Expand Up @@ -925,6 +925,9 @@ export const FoundryAdapter = {
debug(`tidy5e-npc | activateListeners | average: ${average}`);
return average;
},
enrichHtml(value: string, options?: any): Promise<string> {
return TextEditor.enrichHTML(value, options);
},
};

/* ------------------------------------------------------
Expand Down Expand Up @@ -956,6 +959,7 @@ declare const ui: any;
declare const debounce: any;
declare const ChatMessage: any;
declare const AudioHelper: any;
declare const TextEditor: any;

type AbilityReference = {
abbreviation: string;
Expand Down
122 changes: 118 additions & 4 deletions src/sheets/Tidy5eCharacterSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ export class Tidy5eCharacterSheet extends dnd5e.applications.actor
private async getContext(): Promise<CharacterSheetContext> {
const editable = FoundryAdapter.canEditActor(this.actor) && this.isEditable;

const defaultContext = await super.getData(this.options);
const defaultCharacterContext = await super.getData(this.options);

const sections = defaultContext.features.map((section: any) => ({
const sections = defaultCharacterContext.features.map((section: any) => ({
...section,
showLevelColumn: !section.hasActions && section.isClass,
showRequirementsColumn: !section.isClass && !section.columns?.length,
Expand All @@ -112,7 +112,7 @@ export class Tidy5eCharacterSheet extends dnd5e.applications.actor
}));

const context: CharacterSheetContext = {
...defaultContext,
...defaultCharacterContext,
activateFoundryJQueryListeners: (node: HTMLElement) => {
this._activateCoreListeners($(node));
super.activateListeners($(node));
Expand All @@ -125,27 +125,141 @@ export class Tidy5eCharacterSheet extends dnd5e.applications.actor
SettingsProvider.settings.allowHpMaxOverride.get() &&
(!SettingsProvider.settings.lockHpMaxChanges.get() ||
FoundryAdapter.userIsGm()),
appearanceEnrichedHtml: await FoundryAdapter.enrichHtml(
this.actor.system.details.appearance,
{
secrets: this.actor.isOwner,
rollData: defaultCharacterContext.rollData,
async: true,
relativeTo: this.actor,
}
),
appId: this.appId,
biographyEnrichedHtml: await FoundryAdapter.enrichHtml(
this.actor.system.details.biography.value,
{
secrets: this.actor.isOwner,
rollData: defaultCharacterContext.rollData,
async: true,
relativeTo: this.actor,
}
),
bondEnrichedHtml: await FoundryAdapter.enrichHtml(
this.actor.system.details.bond,
{
secrets: this.actor.isOwner,
rollData: defaultCharacterContext.rollData,
async: true,
relativeTo: this.actor,
}
),
classicControlsEnabled:
SettingsProvider.settings.enableClassicControlsForCharacter.get(),
characterJournalTabDisabled:
SettingsProvider.settings.characterJournalTabDisabled.get(),
editable,
features: sections,
flawEnrichedHtml: await FoundryAdapter.enrichHtml(
this.actor.system.details.flaw,
{
secrets: this.actor.isOwner,
rollData: defaultCharacterContext.rollData,
async: true,
relativeTo: this.actor,
}
),
healthPercentage: getPercentage(
this.actor?.system?.attributes?.hp?.value,
this.actor?.system?.attributes?.hp?.max
),
idealEnrichedHtml: await FoundryAdapter.enrichHtml(
this.actor.system.details.ideal,
{
secrets: this.actor.isOwner,
rollData: defaultCharacterContext.rollData,
async: true,
relativeTo: this.actor,
}
),
lockExpChanges: FoundryAdapter.shouldLockExpChanges(),
lockHpMaxChanges: FoundryAdapter.shouldLockHpMaxChanges(),
lockItemQuantity: FoundryAdapter.shouldLockItemQuantity(),
lockLevelSelector: FoundryAdapter.shouldLockLevelSelector(),
lockMoneyChanges: FoundryAdapter.shouldLockMoneyChanges(),
lockSensitiveFields:
!editable && SettingsProvider.settings.editTotalLockEnabled.get(),
originalContext: defaultContext,
notes1EnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.notes1.value`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultCharacterContext.rollData,
async: true,
relativeTo: this.actor,
}
),
notes2EnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.notes2.value`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultCharacterContext.rollData,
async: true,
relativeTo: this.actor,
}
),
notes3EnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.notes3.value`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultCharacterContext.rollData,
async: true,
relativeTo: this.actor,
}
),
notes4EnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.notes4.value`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultCharacterContext.rollData,
async: true,
relativeTo: this.actor,
}
),
notesEnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.notes.value`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultCharacterContext.rollData,
async: true,
relativeTo: this.actor,
}
),
originalContext: defaultCharacterContext,
owner: this.actor.isOwner,
showLimitedSheet: FoundryAdapter.showLimitedSheet(this.actor),
traitEnrichedHtml: await FoundryAdapter.enrichHtml(
this.actor.system.details.trait,
{
secrets: this.actor.isOwner,
rollData: defaultCharacterContext.rollData,
async: true,
relativeTo: this.actor,
}
),
useRoundedPortraitStyle: [
CONSTANTS.ROUNDED_PORTRAIT_OPTION_ALL as string,
CONSTANTS.ROUNDED_PORTRAIT_OPTION_CHARACTER as string,
Expand Down
139 changes: 136 additions & 3 deletions src/sheets/Tidy5eNpcSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,163 @@ export class Tidy5eNpcSheet extends dnd5e.applications.actor.ActorSheet5eNPC {
super.activateListeners($(node));
},
allowEffectsManagement: true,
appearanceEnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.appearance`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultNpcContext.rollData,
async: true,
relativeTo: this.actor,
}
),
appId: this.appId,
biographyEnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`system.details.biography.value`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultNpcContext.rollData,
async: true,
relativeTo: this.actor,
}
),
bondEnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.bond`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultNpcContext.rollData,
async: true,
relativeTo: this.actor,
}
),
classicControlsEnabled:
SettingsProvider.settings.enableClassicControlsForNpc.get(),
encumbrance: this.actor.system.attributes.encumbrance,
editable,
flawEnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.flaw`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultNpcContext.rollData,
async: true,
relativeTo: this.actor,
}
),
hideEmptySpellbook:
lockSensitiveFields && defaultNpcContext.spellbook.length === 0,
healthPercentage: getPercentage(
this.actor?.system?.attributes?.hp?.value,
this.actor?.system?.attributes?.hp?.max
),
hideSpellbookTab: SettingsProvider.settings.hideSpellbookTabNpc.get(),
idealEnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.ideal`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultNpcContext.rollData,
async: true,
relativeTo: this.actor,
}
),
lockSensitiveFields,
longRest: this._onLongRest.bind(this),
rollDeathSave: this._rollDeathSave.bind(this),
shortRest: this._onShortRest.bind(this),
tokenState: this.#getTokenState(),
lockExpChanges: FoundryAdapter.shouldLockExpChanges(),
lockHpMaxChanges: FoundryAdapter.shouldLockHpMaxChanges(),
lockItemQuantity: FoundryAdapter.shouldLockItemQuantity(),
lockLevelSelector: FoundryAdapter.shouldLockLevelSelector(),
lockMoneyChanges: FoundryAdapter.shouldLockMoneyChanges(),
notes1EnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.notes1.value`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultNpcContext.rollData,
async: true,
relativeTo: this.actor,
}
),
notes2EnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.notes2.value`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultNpcContext.rollData,
async: true,
relativeTo: this.actor,
}
),
notes3EnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.notes3.value`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultNpcContext.rollData,
async: true,
relativeTo: this.actor,
}
),
notes4EnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.notes4.value`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultNpcContext.rollData,
async: true,
relativeTo: this.actor,
}
),
notesEnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.notes.value`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultNpcContext.rollData,
async: true,
relativeTo: this.actor,
}
),
owner: this.actor.isOwner,
rollDeathSave: this._rollDeathSave.bind(this),
shortRest: this._onShortRest.bind(this),

showLimitedSheet: FoundryAdapter.showLimitedSheet(this.actor),
tokenState: this.#getTokenState(),
traitEnrichedHtml: await FoundryAdapter.enrichHtml(
FoundryAdapter.getProperty<string>(
this.actor,
`flags.${CONSTANTS.MODULE_ID}.trait`
) ?? '',
{
secrets: this.actor.isOwner,
rollData: defaultNpcContext.rollData,
async: true,
relativeTo: this.actor,
}
),
useRoundedPortraitStyle: [
CONSTANTS.ROUNDED_PORTRAIT_OPTION_ALL as string,
CONSTANTS.ROUNDED_PORTRAIT_OPTION_NPCVEHICLE as string,
Expand Down
Loading

0 comments on commit c02a90b

Please sign in to comment.