Skip to content

Commit

Permalink
feature: update the UI on pullFromPostmaster (#1338)
Browse files Browse the repository at this point in the history
* feature: update the UI on pullFromPostmaster

* lint fix
  • Loading branch information
NigelBreslaw authored Apr 19, 2024
1 parent 9100bb5 commit 027d9d2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 55 deletions.
43 changes: 40 additions & 3 deletions native/app/store/AccountInventoryLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import {
} from "@/app/inventory/Common.ts";
import type { AccountSliceGetter, AccountSliceSetter } from "@/app/store/AccountSlice.ts";
import { itemsDefinition, rawProfileData } from "@/app/store/Definitions.ts";
import { VAULT_CHARACTER_ID } from "@/app/utilities/Constants.ts";
import {
GLOBAL_CONSUMABLES_CHARACTER_ID,
GLOBAL_MODS_CHARACTER_ID,
VAULT_CHARACTER_ID,
} from "@/app/utilities/Constants.ts";
import { typeAndPowerSort } from "@/app/utilities/Helpers.ts";
import { create } from "mutative";

Expand Down Expand Up @@ -325,12 +329,14 @@ function returnInventoryArray(dataArray: DestinyItem[], bucketHash: number): Des
// Update UI logic
// ------------------------------

export function removeFromInventory(get: AccountSliceGetter, set: AccountSliceSetter, destinyItem: DestinyItem) {
export function removeInventoryItem(get: AccountSliceGetter, set: AccountSliceSetter, destinyItem: DestinyItem) {
if (destinyItem.previousCharacterId === "") {
console.error("ERROR: removeFromGuardian expected previousCharacterId to be set");
return;
}

console.log("removeInventoryItem", destinyItem);

if (destinyItem.previousCharacterId === VAULT_CHARACTER_ID) {
// TODO: Cope with stackable items
const previousGeneralVault = get().generalVault;
Expand Down Expand Up @@ -370,7 +376,8 @@ export function removeFromInventory(get: AccountSliceGetter, set: AccountSliceSe
}
}

export function addToInventory(get: AccountSliceGetter, set: AccountSliceSetter, destinyItem: DestinyItem) {
export function addInventoryItem(get: AccountSliceGetter, set: AccountSliceSetter, destinyItem: DestinyItem) {
console.log("addInventoryItem", destinyItem);
// Vault or other?
if (destinyItem.characterId === VAULT_CHARACTER_ID) {
// TODO: Cope with stackable items
Expand Down Expand Up @@ -445,6 +452,36 @@ export function swapEquipAndInventoryItem(get: AccountSliceGetter, set: AccountS
set({ guardians: updatedGuardians });
}

export function transformSuccessfulPullFromPostmasterItem(destinyItem: DestinyItem): DestinyItem {
let characterId: string;
console.log(
"transformSuccessfulPullFromPostmasterItem",
destinyItem.characterId,
SectionBuckets[destinyItem.recoveryBucketHash],
);
switch (destinyItem.recoveryBucketHash) {
case SectionBuckets.Mods: {
characterId = GLOBAL_MODS_CHARACTER_ID;
break;
}
case SectionBuckets.Consumables: {
characterId = GLOBAL_CONSUMABLES_CHARACTER_ID;
break;
}
default: {
characterId = destinyItem.characterId;
}
}
const bucketHash = destinyItem.recoveryBucketHash;
const newDestinyItem: DestinyItem = {
...destinyItem,
characterId,
bucketHash,
};

return newDestinyItem;
}

const deepSightItemHash: number[] = [101423981, 213377779, 1948344346, 2373253941, 2400712188, 3394691176, 3632593563];

export function hasSocketedResonance(itemInstanceId: string): boolean {
Expand Down
28 changes: 17 additions & 11 deletions native/app/store/AccountSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ import {
import type { StateCreator } from "zustand";
import type { IStore } from "@/app/store/GGStore.ts";
import {
addToInventory,
addInventoryItem,
checkForCraftedMasterwork,
hasSocketedResonance,
removeFromInventory,
removeInventoryItem,
swapEquipAndInventoryItem,
transformSuccessfulPullFromPostmasterItem,
updateAllPages,
} from "@/app/store/AccountInventoryLogic.ts";
import { bitmaskContains } from "@/app/utilities/Helpers.ts";
Expand Down Expand Up @@ -77,8 +78,7 @@ export interface AccountSlice {
setTimestamps: (responseMintedTimestamp: string, secondaryComponentsMintedTimestamp: string) => void;
moveItem: (updatedDestinyItem: DestinyItem) => void;
equipItem: (updatedDestinyItem: DestinyItem) => void;
removeFromLostItems: (updatedDestinyItem: DestinyItem) => void;
addInventoryItem: (updatedDestinyItem: DestinyItem) => void;
pullFromPostmaster: (updatedDestinyItem: DestinyItem) => DestinyItem;
findDestinyItem: (itemDetails: DestinyItemIdentifier) => DestinyItem;
setSecondarySpecial: (characterId: string, itemHash: number) => void;
}
Expand Down Expand Up @@ -130,8 +130,8 @@ export const createAccountSlice: StateCreator<IStore, [], [], AccountSlice> = (s

moveItem: (updatedDestinyItem) => {
const p1 = performance.now();
removeFromInventory(get, set, updatedDestinyItem);
addToInventory(get, set, updatedDestinyItem);
removeInventoryItem(get, set, updatedDestinyItem);
addInventoryItem(get, set, updatedDestinyItem);
const p2 = performance.now();
console.log("moveItem", `${(p2 - p1).toFixed(4)} ms`);
updateAllPages(get, set);
Expand All @@ -140,11 +140,17 @@ export const createAccountSlice: StateCreator<IStore, [], [], AccountSlice> = (s
swapEquipAndInventoryItem(get, set, updatedDestinyItem);
updateAllPages(get, set);
},
removeFromLostItems: (updatedDestinyItem) => {
removeFromInventory(get, set, updatedDestinyItem);
},
addInventoryItem: (updatedDestinyItem) => {
addToInventory(get, set, updatedDestinyItem);
pullFromPostmaster: (updatedDestinyItem) => {
// remove the item from the lost items
removeInventoryItem(get, set, updatedDestinyItem);
// Mutate the item to be part of the characters items or a global bucket
const transformedItem = transformSuccessfulPullFromPostmasterItem(updatedDestinyItem);
// Add the item back
addInventoryItem(get, set, transformedItem);

updateAllPages(get, set);

return transformedItem;
},
findDestinyItem: (itemDetails) =>
findDestinyItem(get, {
Expand Down
45 changes: 4 additions & 41 deletions native/app/transfer/TransferLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import {
} from "@/app/inventory/Common.ts";
import { itemsDefinition } from "@/app/store/Definitions.ts";
import { useGGStore } from "@/app/store/GGStore.ts";
import {
GLOBAL_CONSUMABLES_CHARACTER_ID,
GLOBAL_INVENTORY_NAMES,
GLOBAL_MODS_CHARACTER_ID,
VAULT_CHARACTER_ID,
} from "@/app/utilities/Constants.ts";
import { GLOBAL_INVENTORY_NAMES, VAULT_CHARACTER_ID } from "@/app/utilities/Constants.ts";
import { bitmaskContains } from "@/app/utilities/Helpers.ts";
import { apiKey } from "@/constants/env.ts";
import { number, object, optional, safeParse, string } from "valibot";
Expand Down Expand Up @@ -52,7 +47,7 @@ export async function processTransferItem(
quantityToMove,
"equipOnTarget:",
equipOnTarget,
); //, destinyItem);
);
}

const transferItem: TransferItem = {
Expand All @@ -79,15 +74,8 @@ export async function processTransferItem(
const parsedResult = safeParse(responseSchema, result[0]);
if (parsedResult.success) {
if (parsedResult.output.ErrorStatus === "Success") {
// remove the item from the lost items
useGGStore.getState().removeFromLostItems(result[1]);

// Mutate the item to be part of the characters items or a global bucket
const transformedItem = transformSuccessfulPullFromPostmasterItem(result[1]);

// Add the item back
useGGStore.getState().addInventoryItem(result[1]);

// Update the UI and get a transformed item to continue the transfer
const transformedItem = useGGStore.getState().pullFromPostmaster(result[1]);
// Send the item on its way
processTransferItem(toCharacterId, transformedItem, quantityToMove, equipOnTarget);
return;
Expand Down Expand Up @@ -162,31 +150,6 @@ export async function processTransferItem(
}
}

function transformSuccessfulPullFromPostmasterItem(destinyItem: DestinyItem): DestinyItem {
let characterId: string;
switch (destinyItem.recoveryBucketHash) {
case SectionBuckets.Mods: {
characterId = GLOBAL_MODS_CHARACTER_ID;
break;
}
case SectionBuckets.Consumables: {
characterId = GLOBAL_CONSUMABLES_CHARACTER_ID;
break;
}
default: {
characterId = destinyItem.characterId;
}
}
const bucketHash = destinyItem.recoveryBucketHash;
const newDestinyItem: DestinyItem = {
...destinyItem,
characterId,
bucketHash,
};

return newDestinyItem;
}

async function _unequipItem(destinyItem: DestinyItem): Promise<boolean> {
let allowExotic = destinyItem.tierType === TierType.Exotic;

Expand Down

0 comments on commit 027d9d2

Please sign in to comment.