}
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 `<button type="button" class="unequip-item red" hx-post="/player/unequip/${item.item_id}">Unequip</button>`;
}
else {
- if(item.equipment_slot === 'ANY_HAND') {
- return `<button type="button" class="equip-item" hx-post="/player/equip/${item.item_id}/LEFT_HAND">Equip L</button>
-<button type="button" class="equip-item" hx-post="/player/equip/${item.item_id}/RIGHT_HAND">Equip R</button>`;
- }
- else if(item.equipment_slot === 'LEFT_HAND') {
- return `<button type="button" class="equip-item" hx-post="/player/equip/${item.item_id}/${item.equipment_slot}">Equip Left</button>`;
- }
- else if(item.equipment_slot === 'RIGHT_HAND') {
- return `<button type="button" class="equip-item" hx-post="/player/equip/${item.item_id}/${item.equipment_slot}">Equip Right</button>`;
+ if(['ANY_HAND', 'LEFT_HAND', 'RIGHT_HAND'].includes(item.equipment_slot)) {
+ const str: string[] = [
+ `<button type="button" class="equip-item" hx-post="/player/equip/${item.item_id}/LEFT_HAND">Equip L</button>`,
+ `<button type="button" class="equip-item" hx-post="/player/equip/${item.item_id}/RIGHT_HAND">Equip R</button>`
+ ];
+
+ 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 `<button type="button" class="equip-item" hx-post="/player/equip/${item.item_id}/${item.equipment_slot}">Equip</button>`;