Release Healer Man 0.1.44
This commit is contained in:
1 parent
ccc01396cd
commit
756ee4f64a
24 files changed
+575
-46
No files matched your search
@@ -2,7 +2,9 @@ import { create } from "zustand";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
import { loadUiPreferences, saveUiPreferences } from "../app/accountRepository";
|
||||
import { useShellStore } from "../app/shellStore";
|
||||
import { normalizeUiPreferences, type UiDevice, type UiLayout, type UiPreferences } from "./uiLayout";
|
||||
import type { CharacterProfile } from "../app/types";
|
||||
import { abilitiesForCharacter, defaultActionBarForCharacter } from "./abilityCatalog";
|
||||
import { activateDesktopAbilityLoadout, normalizeUiPreferences, type UiDevice, type UiLayout, type UiPreferences } from "./uiLayout";
|
||||
import { publishInputPreferences } from "../input/keybindRuntime";
|
||||
|
||||
export function currentUiDevice(): UiDevice {
|
||||
@@ -13,6 +15,7 @@ export function currentUiDevice(): UiDevice {
|
||||
}
|
||||
interface UiLayoutState {
|
||||
ownerId: string | null;
|
||||
desktopLoadoutKey: string | null;
|
||||
preferences: UiPreferences;
|
||||
draft: UiLayout | null;
|
||||
device: UiDevice;
|
||||
@@ -25,7 +28,7 @@ interface UiLayoutState {
|
||||
finish: (save: boolean) => void;
|
||||
}
|
||||
export const useUiLayoutStore = create<UiLayoutState>((set, get) => ({
|
||||
ownerId: null, preferences: normalizeUiPreferences(null), draft: null, device: currentUiDevice(),
|
||||
ownerId: null, desktopLoadoutKey: null, preferences: normalizeUiPreferences(null), draft: null, device: currentUiDevice(),
|
||||
mode: "layout", selectedButton: null, selectedElement: null,
|
||||
begin: () => {
|
||||
const device = currentUiDevice();
|
||||
@@ -36,7 +39,11 @@ export const useUiLayoutStore = create<UiLayoutState>((set, get) => ({
|
||||
const ownerId = get().ownerId;
|
||||
if (!ownerId) throw new Error("Sign in or choose an offline profile before saving your UI.");
|
||||
// Write first: storage errors leave the editor open with its draft intact.
|
||||
const saved = saveUiPreferences(ownerId, preferences);
|
||||
const key = get().desktopLoadoutKey;
|
||||
const saved = saveUiPreferences(ownerId, key ? { ...preferences,
|
||||
desktopAbilityLoadouts: { ...preferences.desktopAbilityLoadouts,
|
||||
[key]: preferences.current.pc.bars.flatMap((bar) => bar.slots.map((slot) => slot.abilityId)) },
|
||||
} : preferences);
|
||||
set({ preferences: saved });
|
||||
},
|
||||
finish: (save) => {
|
||||
@@ -48,7 +55,7 @@ export const useUiLayoutStore = create<UiLayoutState>((set, get) => ({
|
||||
|
||||
function activateOwner() {
|
||||
const ownerId = useShellStore.getState().session?.ownerId ?? null;
|
||||
useUiLayoutStore.setState({ ownerId, preferences: ownerId ? loadUiPreferences(ownerId) : normalizeUiPreferences(null), draft: null });
|
||||
useUiLayoutStore.setState({ ownerId, desktopLoadoutKey: null, preferences: ownerId ? loadUiPreferences(ownerId) : normalizeUiPreferences(null), draft: null });
|
||||
}
|
||||
activateOwner();
|
||||
publishInputPreferences(useUiLayoutStore.getState().preferences.keybinds);
|
||||
@@ -57,6 +64,18 @@ useShellStore.subscribe((state, previous) => {
|
||||
if (state.session !== previous.session) activateOwner();
|
||||
});
|
||||
|
||||
/** Call after the character's catalogs have loaded, in both menu and gameplay paths. */
|
||||
export function activateCharacterUi(character: CharacterProfile): void {
|
||||
const ui = useUiLayoutStore.getState();
|
||||
if (ui.ownerId !== character.ownerId) return;
|
||||
const key = `${character.id}:${character.classId}:${character.secondaryClassId ?? ""}`;
|
||||
useUiLayoutStore.setState({ desktopLoadoutKey: key, draft: null,
|
||||
preferences: activateDesktopAbilityLoadout(ui.preferences, key,
|
||||
defaultActionBarForCharacter(character.classId, character.secondaryClassId, character.level),
|
||||
abilitiesForCharacter(character.classId, character.secondaryClassId).map((ability) => ability.id)),
|
||||
});
|
||||
}
|
||||
|
||||
export function activeUiLayout(): UiLayout {
|
||||
const state = useUiLayoutStore.getState();
|
||||
return state.draft ?? state.preferences.current[currentUiDevice()];
|
||||
|
||||
Reference in new issue
Block a user