Skip to content

Commit

Permalink
add showStatus client setting
Browse files Browse the repository at this point in the history
  • Loading branch information
reonZ committed Oct 4, 2024
1 parent e30df00 commit b2c9f51
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
11 changes: 10 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"tooltip": {
"title": "Token Tooltip",
"status": {
"name": "Health Status",
"name": "Health Status Entries",
"hint": "Comma separated strings representing the different divisions of a creature's health state from worst to best. Leave empty to disable.",
"default": "Dead, At Death's Door, Not Feeling Good, Seen Better Days, Barely Hurt, Perfectly Fine"
},
Expand All @@ -93,6 +93,15 @@
"observed": "Owned and observed"
}
},
"showStatus": {
"name": "Display Health Status",
"hint": "When should the creatures' health state be displayed on the tooltip if enabled in you world.",
"choices": {
"never": "Never",
"small": "Small Version Only",
"all": "Always"
}
},
"delay": {
"name": "Tooltip Delay",
"hint": "Delay in milliseconds before the tooltip shows up on screen."
Expand Down
28 changes: 21 additions & 7 deletions src/hud/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const DISTANCES: Record<
const DELAY_BUFFER = 50;
const SETTING_POSITION = R.keys(POSITIONS);
const SETTING_TYPE = ["never", "owned", "observed"] as const;
const SETTING_SHOW_STATUS = ["never", "small", "all"] as const;
const SETTING_DISTANCE = ["never", "idiot", "smart", "weird"] as const;
const SETTING_NO_DEAD = ["none", "small", "full"] as const;

Expand Down Expand Up @@ -104,6 +105,7 @@ class PF2eHudTooltip extends PF2eHudBaseToken<TooltipSettings, ActorPF2e, Toolti
"status",
"enabled",
"type",
"showStatus",
"delay",
"position",
"fontSize",
Expand All @@ -121,6 +123,13 @@ class PF2eHudTooltip extends PF2eHudBaseToken<TooltipSettings, ActorPF2e, Toolti
default: undefined,
onChange: () => this.enable(),
},
{
key: "showStatus",
type: String,
choices: SETTING_SHOW_STATUS,
default: "small",
scope: "client",
},
{
key: "type",
type: String,
Expand Down Expand Up @@ -323,7 +332,16 @@ class PF2eHudTooltip extends PF2eHudBaseToken<TooltipSettings, ActorPF2e, Toolti
return baseData;
}

const isOwner = actor.isOwner;
const isObserver = userCanObserveActor(actor);
const extendedType = this.getSetting("type");
const extended =
(extendedType === "owned" && isOwner) || (extendedType === "observed" && isObserver);

const status = (() => {
const statusType = this.getSetting("showStatus");
if (statusType === "never" || (statusType === "small" && extended)) return;

const statuses = this.healthStatuses;
if (!statuses) return;

Expand All @@ -345,11 +363,6 @@ class PF2eHudTooltip extends PF2eHudBaseToken<TooltipSettings, ActorPF2e, Toolti
return statuses.at(pick - 1);
})();

const setting = this.getSetting("type");
const isOwner = actor.isOwner;
const isObserver = userCanObserveActor(actor);

const extended = (setting === "owned" && isOwner) || (setting === "observed" && isObserver);
if (!extended) {
return {
...baseData,
Expand All @@ -376,8 +389,8 @@ class PF2eHudTooltip extends PF2eHudBaseToken<TooltipSettings, ActorPF2e, Toolti
statistics: getStatistics(actor),
distance: baseData.distance,
health: statsMain.health,
expended: extended,
level: actor.level,
extended,
status,
name,
iwr,
Expand Down Expand Up @@ -639,7 +652,7 @@ type StatusedTooltipContext = TooltipContextBase & {
type TooltipContext = StatusedTooltipContext & {
distance: DistanceContext | undefined;
status: string | undefined;
expended: boolean;
extended: boolean;
level: number;
name: string | undefined;
speeds: StatsSpeed[];
Expand All @@ -657,6 +670,7 @@ type TooltipSettings = BaseTokenSettings & {
delay: number;
status: string;
drawDistance: number;
showStatus: (typeof SETTING_SHOW_STATUS)[number];
type: (typeof SETTING_TYPE)[number];
noDead: (typeof SETTING_NO_DEAD)[number];
position: (typeof SETTING_POSITION)[number];
Expand Down
9 changes: 9 additions & 0 deletions styles/_tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
justify-content: center;
gap: 0.3em var(--inner-gap);
border: var(--outer-border);
margin: auto;

header,
hr {
Expand Down Expand Up @@ -148,5 +149,13 @@
}
}
}

+ .status {
width: fit-content;
margin: auto;
margin-top: -2px;
z-index: -1;
position: relative;
}
}
}
2 changes: 1 addition & 1 deletion styles/pf2e-hud.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion styles/pf2e-hud.css.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions templates/tooltip/tooltip.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>
{{/if}}

{{#if expended}}
{{#if extended}}
<div class="inner">
{{#if name}}
<header>{{name}}</header>
Expand Down Expand Up @@ -78,7 +78,9 @@
</section>
{{/if}}
</div>
{{else if status}}
{{/if}}

{{#if status}}
<div class="status" style="--hue: {{health.total.hue}};" data-section="health-status">
{{status}}
</div>
Expand Down

0 comments on commit b2c9f51

Please sign in to comment.