From d7569d31080cb8d55c5e57bae9a16f6a676c12ff Mon Sep 17 00:00:00 2001 From: xangelo Date: Wed, 6 Sep 2023 13:25:27 -0400 Subject: [PATCH] feat: display equippable hand option only When you are equipping items it will only show you the equip button for the hand that you have available --- src/server/views/inventory.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/server/views/inventory.ts b/src/server/views/inventory.ts index 6026775..88e3c8c 100644 --- a/src/server/views/inventory.ts +++ b/src/server/views/inventory.ts @@ -121,21 +121,30 @@ function renderInventoryItem(item: EquippedItemDetails , action: (item: Equipped } function renderInventorySection(inventory: EquippedItemDetails[]): string { + const used_slots = inventory.filter(i => i.is_equipped).map(i => i.equipment_slot); + return inventory.map(item => { return renderInventoryItem(item, item => { if(item.is_equipped) { return ``; } else { - if(item.equipment_slot === 'ANY_HAND') { - return ` -`; - } - else if(item.equipment_slot === 'LEFT_HAND') { - return ``; - } - else if(item.equipment_slot === 'RIGHT_HAND') { - return ``; + if(['ANY_HAND', 'LEFT_HAND', 'RIGHT_HAND'].includes(item.equipment_slot)) { + const str: string[] = [ + ``, + `` + ]; + + if(used_slots.includes('LEFT_HAND') && !used_slots.includes('RIGHT_HAND')) { + return str[1]; + } + else if(used_slots.includes('RIGHT_HAND') && !used_slots.includes('LEFT_HAND')) { + return str[0]; + } + else if(used_slots.includes('LEFT_HAND') && used_slots.includes('RIGHT_HAND')) { + return ""; + } + return str.join(""); } else { return ``; -- 2.25.1