Merge pull request #3 from D4M13N-D3V/2-is_grid_space_available-on-the-inventorygrid-class-is-not-working-properly

fix the inventory grid class to account for global position not being…
This commit is contained in:
Damien Ostler 2024-01-09 00:26:22 -05:00 committed by GitHub
commit 6a3c366cd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -92,6 +92,7 @@ func show_context_menu(mouse_pos: Vector2, item):
# Function to hide the context menu # Function to hide the context menu
func hide_context_menu(): func hide_context_menu():
if(inventory_context_menu!=null): if(inventory_context_menu!=null):
inventory_context_menu_item=null
inventory_context_menu.queue_free() inventory_context_menu.queue_free()
func context_menu_open(): func context_menu_open():

View File

@ -135,13 +135,15 @@ func get_item_under_pos(pos):
if item.get_global_rect().has_point(pos): if item.get_global_rect().has_point(pos):
return item return item
return null return null
# Function to insert an item at the first available spot in the grid
# Function to insert an item at the first available spot in the grid # Function to insert an item at the first available spot in the grid
func insert_item_at_first_available_spot(item): func insert_item_at_first_available_spot(item):
for x in inventory_item_grid_width: for x in range(inventory_item_grid_width):
for y in inventory_item_grid_height: for y in range(inventory_item_grid_height):
if not inventory_item_grid[x][y]["used"]: if inventory_item_grid[x][y]["used"] == false:
item.global_position = Vector2(x* inventory_item_grid_cell_size, (y)* inventory_item_grid_cell_size) item.global_position = global_position+ Vector2(x * inventory_item_grid_cell_size, y * inventory_item_grid_cell_size)
if insert_item(item) == true: if insert_item(item) == true:
print("Item inserted at:", item.position)
return true return true
return false return false