Changes for inventory_grid.gd regarding create_and_add_item for implementing get_item_at_position #38
-
Hey there. Since create_and_add_item function has been added yesterday, I believe that it needs a separate implementation for the inventory_grid.gd, because when we add and create an item in inventory_grid, it also gets added a position, but in the base inventory, item position is not added. I've noticed this because I wanted to implement a function that gets an item at the certain position in the inventory. This function would be useful for mapping items to hotkeys etc. For getting item at the position I've made this function
For overriding the base classes function we can use the same function which calls the inventory_grid's add_item functions that handles position properties.
If this is already possible in the current implementation, I'd like to know how, so I can use it the way it was meant to be used :D PS: I really like the plugin |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yeah, helper functions like func create_and_add_item_at(prototype_id: String, position: Vector2) -> InventoryItem:
var item = create_and_add_item(prototype_id)
if item:
move_item_to(item, position)
return item Getting items at specific grid coordinates can currently be done with help of func get_item_at(position: Vector2) -> InventoryItem:
for item in get_items():
if get_item_rect(item).has_point(position):
return item
return null Note: I haven't actually tested any of the above, so I'm not 100% sure it would work. EDIT: Implemented in #40 |
Beta Was this translation helpful? Give feedback.
Yeah, helper functions like
create_and_add_item_at
andget_item_at
are still missing, however I think it shouldn't be hard to implement them.One thing you're missing in your implementation is that items with missing
KEY_GRID_POSITION
property are considered to be positioned at(0, 0)
. This makes the whole thing a lot simpler, as items can be added at certain positions simply by adding them at(0, 0)
and moving them to the desired grid coordinates:Getting items at specific grid coordinates…