diff --git a/src/actors/players/playerE/PlayerE.gd b/src/actors/players/playerE/PlayerE.gd index 5ea7509..6c128d6 100644 --- a/src/actors/players/playerE/PlayerE.gd +++ b/src/actors/players/playerE/PlayerE.gd @@ -32,6 +32,10 @@ func _process(delta): var _selected_item = player_inventory.switch_primary() if _selected_item: print("Switched Primary item to: ", _selected_item.name) + elif Input.is_action_just_released("switch_secondary_item_" + str(player_number)): + var _selected_item = player_inventory.switch_secondary() + if _selected_item: + print("Switched Secondary item to: ", _selected_item.name) func hit_Receiver(damage): $Hurtbox_Component.set_hurtbox(false) diff --git a/src/classes/inventory_manager.gd b/src/classes/inventory_manager.gd index 8ac4f2b..0c3695c 100644 --- a/src/classes/inventory_manager.gd +++ b/src/classes/inventory_manager.gd @@ -54,6 +54,35 @@ func switch_primary() -> Item: ## Nothing changed return null +func switch_secondary() -> Item: + ## Don't switch unless there is another item + if secondary_selection != null and _items.size() > 1: + var found_item :bool = false + var itemarr = _items.keys() + for i in itemarr: + ## Item found in last iteration, grab the next one. + if found_item: + if i == primary_selection: + break + secondary_selection = i + return i + if i == secondary_selection: + found_item = true + ## Item found but was the last in the list, grab the first one. + if found_item and itemarr[0] != secondary_selection: + if itemarr[0] != primary_selection: + secondary_selection = itemarr[0] + return itemarr[0] + ## Swap primary and secondary + if primary_selection != null: + var i = primary_selection + if secondary_selection != null: + primary_selection = secondary_selection + secondary_selection = i + return i + ## Nothing changed + return null + func select_secondary(_item :Item) -> void: if _items.has(_item): secondary_selection = _item