Skip to content

Commit

Permalink
save persistent actor in user flag instead of client setting
Browse files Browse the repository at this point in the history
  • Loading branch information
reonZ committed Jun 18, 2024
1 parent 229862f commit 0705cee
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/hud/persistent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
addListenerAll,
createHTMLElement,
createHook,
createWrapper,
getFlag,
isInstanceOf,
libWrapper,
localize,
setFlag,
templateLocalize,
warn,
} from "foundry-pf2e";
Expand All @@ -22,7 +22,6 @@ import {
AdvancedHudEvent,
CLOSE_SETTINGS,
CloseSetting,
IPF2eHudAdvanced,
addSidebarsListeners,
makeAdvancedHUD,
} from "./base/advanced";
Expand Down Expand Up @@ -96,14 +95,6 @@ class PF2eHudPersistent extends makeAdvancedHUD(

get SETTINGS(): SettingOptions[] {
return super.SETTINGS.concat([
{
key: "selected",
type: String,
default: "",
scope: "client",
config: false,
onChange: () => this.render(),
},
{
key: "noflash",
type: Boolean,
Expand Down Expand Up @@ -192,6 +183,10 @@ class PF2eHudPersistent extends makeAdvancedHUD(
};
}

get selected() {
return getFlag<string>(game.user, "persistent.selected") ?? "";
}

_onEnable(enabled: boolean = this.enabled) {
this.#renderActorSheetHook.toggle(enabled);
this.#renderHotbarHook.toggle(enabled);
Expand All @@ -200,7 +195,7 @@ class PF2eHudPersistent extends makeAdvancedHUD(
this.#updateUserHook.toggle(enabled);

if (enabled) {
const selected = this.getSetting("selected");
const selected = this.selected;

let actor = fromUuidSync<ActorPF2e>(selected);

Expand All @@ -218,7 +213,7 @@ class PF2eHudPersistent extends makeAdvancedHUD(
_configureRenderOptions(options: PersistentRenderOptions) {
super._configureRenderOptions(options);

options.hasSavedActor = !!this.getSetting("selected");
options.hasSavedActor = !!this.selected;
options.cleaned = this.getSetting("cleanPortrait");

const allowedParts = this.templates;
Expand Down Expand Up @@ -307,8 +302,6 @@ class PF2eHudPersistent extends makeAdvancedHUD(
}
}

_insertElement(element: HTMLElement) {}

_actorCleanup() {
this.#actor = null;
this.#isUserCharacter = false;
Expand Down Expand Up @@ -368,8 +361,8 @@ class PF2eHudPersistent extends makeAdvancedHUD(
this.#isUserCharacter = actor === game.user.character;
this.#actor = actor as PersistentHudActor;

if (skipSave) this.render(!!actor);
else this.setSetting("selected", savedActor?.uuid ?? "");
if (!skipSave) setFlag(game.user, "persistent.selected", savedActor?.uuid ?? "");
this.render(!!actor);
}

isCurrentActor(actor: Maybe<ActorPF2e>, flash = false): actor is PersistentHudActor {
Expand Down Expand Up @@ -621,7 +614,6 @@ type PersistentContext = Omit<BaseActorContext<PersistentHudActor>, "actor" | "h
type PersistentSettings = BaseActorSettings &
SidebarSettings &
Record<CloseSetting, boolean> & {
selected: string;
cleanPortrait: boolean;
noflash: boolean;
};
Expand Down

0 comments on commit 0705cee

Please sign in to comment.