mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-01 05:43:22 +01:00
Fix: Unify Tankopedia model, camouflage and attachment loaders
- Tankopedia state uses `loaders: { model, skin, attachment }` with `requested` and `loaded`
- useSkin swaps the camouflage halfway through the lighting transition for both cached and downloaded skins
- Remove the leftover "Unreleased" camouflage name handling
This commit is contained in:
1 parent
523fee5010
commit
c772d47a07
8 files changed
+74
-83
No files matched your search
@@ -35,36 +35,28 @@ function skinPath(id: number, skin: number) {
|
||||
}
|
||||
|
||||
// attachments load the same way as camouflages and can be shown with one
|
||||
const slots = {
|
||||
skin: { requested: "requestedSkin", loaded: "loadedSkin" },
|
||||
attachment: { requested: "requestedAttachment", loaded: "loadedAttachment" },
|
||||
} as const;
|
||||
|
||||
export function useSkin(id: number, slot: keyof typeof slots = "skin") {
|
||||
const { requested, loaded } = slots[slot];
|
||||
const requestedSkin = Tankopedia.use((state) => state[requested]);
|
||||
const skin = Tankopedia.use((state) => state[slot]);
|
||||
export function useSkin(id: number, loader: "skin" | "attachment" = "skin") {
|
||||
const requested = Tankopedia.use((state) => state.loaders[loader].requested);
|
||||
const loaded = Tankopedia.use((state) => state.loaders[loader].loaded);
|
||||
|
||||
useEffect(() => {
|
||||
const path =
|
||||
requestedSkin === undefined ? undefined : skinPath(id, requestedSkin);
|
||||
if (requested === Tankopedia.state.loaders[loader].loaded) return;
|
||||
|
||||
const path = requested === undefined ? undefined : skinPath(id, requested);
|
||||
const cached = path === undefined || loadedSkins.has(path);
|
||||
let settled = false;
|
||||
|
||||
if (path === undefined || loadedSkins.has(path)) {
|
||||
if (!cached) {
|
||||
Tankopedia.mutate((draft) => {
|
||||
draft[loaded] = requestedSkin;
|
||||
draft.revealed = false;
|
||||
});
|
||||
return;
|
||||
|
||||
if (!skins.has(path)) skins.set(path, loadSkin(path));
|
||||
}
|
||||
|
||||
Tankopedia.mutate((draft) => {
|
||||
draft.revealed = false;
|
||||
});
|
||||
|
||||
if (!skins.has(path)) skins.set(path, loadSkin(path));
|
||||
|
||||
// swaps halfway through the lighting transition
|
||||
Promise.all([
|
||||
skins.get(path),
|
||||
path && skins.get(path),
|
||||
new Promise((resolve) =>
|
||||
setTimeout(resolve, TRANSITION_ANIMATION_TIME * 1e3),
|
||||
),
|
||||
@@ -73,9 +65,8 @@ export function useSkin(id: number, slot: keyof typeof slots = "skin") {
|
||||
|
||||
settled = true;
|
||||
Tankopedia.mutate((draft) => {
|
||||
draft[loaded] = requestedSkin;
|
||||
draft[slot] = requestedSkin;
|
||||
draft.revealed = true;
|
||||
draft.loaders[loader].loaded = requested;
|
||||
if (!cached) draft.revealed = true;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -83,11 +74,16 @@ export function useSkin(id: number, slot: keyof typeof slots = "skin") {
|
||||
if (settled) return;
|
||||
|
||||
settled = true;
|
||||
|
||||
if (cached) return;
|
||||
|
||||
Tankopedia.mutate((draft) => {
|
||||
draft.revealed = true;
|
||||
});
|
||||
};
|
||||
}, [id, slot, requestedSkin]);
|
||||
}, [id, loader, requested]);
|
||||
|
||||
return skin === undefined ? undefined : loadedSkins.get(skinPath(id, skin));
|
||||
return loaded === undefined
|
||||
? undefined
|
||||
: loadedSkins.get(skinPath(id, loaded));
|
||||
}
|
||||
Reference in new issue
Block a user