From c759e084f2c6e67608c03b3560eaf119fe57a664 Mon Sep 17 00:00:00 2001 From: Kayla Glick <12898988+kayla-glick@users.noreply.github.com> Date: Wed, 14 Feb 2024 02:15:20 -0500 Subject: [PATCH] Fix item swap issues (#4213) * fix gear comparison index issue with item swap * little bit of cleanup * import missing stylesheet --- ui/core/components/gear_picker.tsx | 13 ++++--------- ui/core/player.ts | 8 ++++++++ ui/core/proto_utils/gear.ts | 3 ++- ui/scss/core/individual_sim_ui/index.scss | 1 + 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ui/core/components/gear_picker.tsx b/ui/core/components/gear_picker.tsx index 42c3134701..85e343690a 100644 --- a/ui/core/components/gear_picker.tsx +++ b/ui/core/components/gear_picker.tsx @@ -2,7 +2,6 @@ import { difficultyNames, professionNames, slotNames } from '../proto_utils/name import { BaseModal } from './base_modal'; import { Component } from './component'; import { FiltersMenu } from './filters_menu'; -import { Input, InputConfig } from './input'; import { makePhaseSelector, makeShow1hWeaponsSelector, @@ -21,18 +20,15 @@ import { formatDeltaTextElem } from '../utils'; import { ActionId } from '../proto_utils/action_id'; import { getEnchantDescription, getUniqueEnchantString } from '../proto_utils/enchants'; import { EquippedItem } from '../proto_utils/equipped_item'; -import { ItemSwapGear } from '../proto_utils/gear' import { getEmptyGemSocketIconUrl, gemMatchesSocket } from '../proto_utils/gems'; import { Stats } from '../proto_utils/stats'; import { Class, - Spec, GemColor, ItemQuality, ItemSlot, ItemSpec, - ItemSwap, ItemType, } from '../proto/common'; import { @@ -43,6 +39,7 @@ import { } from '../proto/ui.js'; import { IndividualSimUI } from '../individual_sim_ui.js'; import { Tooltip } from 'bootstrap'; +// eslint-disable-next-line unused-imports/no-unused-imports import { element, fragment, ref } from 'tsx-vanilla'; import { Clusterize } from './virtual_scroll/clusterize.js'; @@ -331,12 +328,10 @@ export class IconItemSwapPicker extends Component { this._items = this.player.getItems(slot); this._enchants = this.player.getEnchants(slot); const gearData = { - equipItem: (eventID: EventID, equippedItem: EquippedItem | null) => { - let curIsg = player.getItemSwapGear(); - curIsg = curIsg.withEquippedItem(slot, equippedItem, player.canDualWield2H()) - player.setItemSwapGear(eventID, curIsg); + equipItem: (eventID: EventID, newItem: EquippedItem | null) => { + player.equipItemSwapitem(eventID, this.slot, newItem) }, - getEquippedItem: () => this.player.getItemSwapGear().getEquippedItem(this.slot), + getEquippedItem: () => player.getItemSwapItem(this.slot), changeEvent: player.itemSwapChangeEmitter, } diff --git a/ui/core/player.ts b/ui/core/player.ts index b9e1b95c02..b8bf54ab96 100644 --- a/ui/core/player.ts +++ b/ui/core/player.ts @@ -624,6 +624,14 @@ export class Player { this.itemSwapChangeEmitter.emit(eventID); } + equipItemSwapitem(eventID: EventID, slot: ItemSlot, newItem: EquippedItem | null) { + this.setItemSwapGear(eventID, this.itemSwapGear.withEquippedItem(slot, newItem, this.canDualWield2H())); + } + + getItemSwapItem(slot: ItemSlot): EquippedItem | null { + return this.itemSwapGear.getEquippedItem(slot); + } + getItemSwapGear(): ItemSwapGear { return this.itemSwapGear; } diff --git a/ui/core/proto_utils/gear.ts b/ui/core/proto_utils/gear.ts index 1c54371112..96b11d82a4 100644 --- a/ui/core/proto_utils/gear.ts +++ b/ui/core/proto_utils/gear.ts @@ -38,7 +38,8 @@ abstract class BaseGear { abstract getItemSlots(): ItemSlot[] equals(other: BaseGear): boolean { - return this.asArray().every((thisItem, slot) => equalsOrBothNull(thisItem, other.getEquippedItem(slot), (a, b) => a.equals(b))); + const otherArray = other.asArray(); + return this.asArray().every((thisItem, slot) => equalsOrBothNull(thisItem, otherArray[slot], (a, b) => a.equals(b))) } getEquippedItem(slot: ItemSlot): EquippedItem | null { diff --git a/ui/scss/core/individual_sim_ui/index.scss b/ui/scss/core/individual_sim_ui/index.scss index 92330b1c17..7094455fb2 100644 --- a/ui/scss/core/individual_sim_ui/index.scss +++ b/ui/scss/core/individual_sim_ui/index.scss @@ -16,6 +16,7 @@ @import "../components/icon_enum_picker"; @import "../components/icon_picker"; @import "../components/importers"; +@import "../components/item_swap_picker"; @import "../components/multi_icon_picker"; @import "../components/number_list_picker"; @import "../components/number_picker";