tools separated in inv
This commit is contained in:
@@ -123,37 +123,33 @@ func try_interact(interactable : Interactable):
|
||||
func try_move(move_to : Vector2):
|
||||
instruction = MoveInstruction.new(move_to)
|
||||
|
||||
func pick_item(item : Item) -> Item:
|
||||
AudioManager.play_sfx("PickUp")
|
||||
if data.inventory.is_full():
|
||||
func can_pick_item(item: Item):
|
||||
return item.type == Item.ItemType.TOOL_ITEM || !data.inventory.is_full() || !data.inventory.current_is_tool()
|
||||
|
||||
func pick_item(item : Item):
|
||||
if item.type != Item.ItemType.TOOL_ITEM && data.inventory.is_full():
|
||||
await drop_item()
|
||||
|
||||
var current_item : Item = null
|
||||
AudioManager.play_sfx("PickUp")
|
||||
|
||||
var available_slot_ind = data.inventory.get_best_available_slot_ind()
|
||||
if (
|
||||
available_slot_ind == data.inventory.current_item_ind
|
||||
&& data.inventory.items[available_slot_ind] != null
|
||||
):
|
||||
current_item = data.inventory.get_item()
|
||||
data.inventory.set_item(item, available_slot_ind)
|
||||
else :
|
||||
if data.inventory.set_item(item, available_slot_ind):
|
||||
data.inventory.set_current_item(available_slot_ind);
|
||||
data.inventory.add_item(item)
|
||||
|
||||
# Save after a timer to let the time to the item to disappear
|
||||
get_tree().create_timer(0.1).timeout.connect(region.save)
|
||||
return current_item
|
||||
|
||||
func drop_item():
|
||||
var item_to_drop = data.inventory.pop_item()
|
||||
func drop_item():
|
||||
var ind_to_drop := data.inventory.current_item_ind
|
||||
if data.inventory.current_is_tool():
|
||||
ind_to_drop = data.inventory.n_tools
|
||||
var item_to_drop = data.inventory.pop_item(ind_to_drop)
|
||||
if item_to_drop:
|
||||
terrain.drop_item(item_to_drop, global_position)
|
||||
AudioManager.play_sfx("Drop")
|
||||
region.save()
|
||||
|
||||
func delete_item(item: Item):
|
||||
data.inventory.remove_item(item)
|
||||
if !data.inventory.current_is_tool():
|
||||
data.inventory.remove_item(item)
|
||||
|
||||
func try_use_item(item : Item, use_position : Vector2):
|
||||
await setup_action_zone(use_position, item)
|
||||
@@ -195,7 +191,7 @@ func upgrade_max_energy(amount = 1):
|
||||
player_updated.emit(self)
|
||||
|
||||
func upgrade_inventory_size(amount = 1):
|
||||
data.inventory.size += amount
|
||||
data.inventory.change_size(amount)
|
||||
upgraded.emit()
|
||||
player_updated.emit(self)
|
||||
|
||||
|
||||
@@ -14,4 +14,4 @@ const DEFAULT_INVENTORY_SIZE = 3
|
||||
set(v):
|
||||
energy = v
|
||||
updated.emit(self)
|
||||
@export var inventory = Inventory.new(DEFAULT_INVENTORY_SIZE)
|
||||
@export var inventory := Inventory.new(DEFAULT_INVENTORY_SIZE)
|
||||
Reference in New Issue
Block a user