-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transfer_autosplitmerge fail on full inventory #201
Comments
I put together two tests to verify this, but couldn't get the assertion to happen :( The first test tries to transfer an item stack into a full inventory: func issue_201_1() -> void:
# Create two 2x2 inventories
var inv1 = InventoryGridStacked.new()
inv1.item_protoset = preload("res://tests/data/item_definitions_grid.tres")
inv1.size = Vector2i(2, 2)
var inv2 = InventoryGridStacked.new()
inv2.item_protoset = preload("res://tests/data/item_definitions_grid.tres")
inv2.size = Vector2i(2, 2)
# Fill the first inventory with 1x1 item stacks with max stack size
for i in range(4):
var new_item = inv1.create_and_add_item("item_1x1")
InventoryGridStacked.set_item_max_stack_size(new_item, 3)
assert(InventoryGridStacked.set_item_stack_size(new_item, 3))
# Add a 1x1 item stack with max stack size to the second inventory
var item = inv2.create_and_add_item("item_1x1")
InventoryGridStacked.set_item_max_stack_size(item, 3)
assert(InventoryGridStacked.set_item_stack_size(item, 3))
# Try to transfer the 1x1 item from the second inventory to the first one
# using transfer_autosplitmerge
assert(!inv2.transfer_autosplitmerge(item, inv1))
inv1.free()
inv2.free() while the second one transfers into into an inventory with a partial stack: func issue_201_2() -> void:
# Create two 2x2 inventories
var inv1 = InventoryGridStacked.new()
inv1.item_protoset = preload("res://tests/data/item_definitions_grid.tres")
inv1.size = Vector2i(2, 2)
var inv2 = InventoryGridStacked.new()
inv2.item_protoset = preload("res://tests/data/item_definitions_grid.tres")
inv2.size = Vector2i(2, 2)
# Fill the first inventory with 1x1 item stacks with max stack size, except
# for one
for i in range(4):
var new_item = inv1.create_and_add_item("item_1x1")
InventoryGridStacked.set_item_max_stack_size(new_item, 3)
if i == 0:
assert(InventoryGridStacked.set_item_stack_size(new_item, 1))
else:
assert(InventoryGridStacked.set_item_stack_size(new_item, 3))
# Add a 1x1 item stack with max stack size to the second inventory
var item = inv2.create_and_add_item("item_1x1")
InventoryGridStacked.set_item_max_stack_size(item, 3)
assert(InventoryGridStacked.set_item_stack_size(item, 3))
# Try to transfer the 1x1 item from the second inventory to the first one
# using transfer_autosplitmerge
assert(inv2.transfer_autosplitmerge(item, inv1))
inv1.free()
inv2.free() In the first case Did I understand the use case correctly or maybe I missed some details? Edit: Reopening the issue, closed it by accident |
The stacks_constraint.gd file when calling transfer_autosplitmerge() does a var new_item using func transfer_autosplit, it's in that func that the assert exists:
If I comment out the: assert(!item_count.eq(ItemCount.inf()), "Item count is infinite!") then I don't get the assertion errors, and the split merge works just fine. I'm not sure entirely the reason, and what the purpose of the assertion line in that function is supposed to do. I have 3 inventories of the GridStacked/Grid type, currently I am manually making the list of items I want to pull from, but eventually I will just get them from the protoset. I'll figure that part out later. And I'll clean up my mess eventually
|
It's difficult to tell what's going on without executing the code, but i can notice that your screenshot shows three overflowInventoryGrid = guiChild.find_child("OverFlowCtrlInventoryGrid",true,true) You also seem to cast these inventories into base overflowInventory = overflowInventoryGrid.inventory as Inventory but then use them as an if overflowInventory.transfer_autosplitmerge(asm, inventoryGrid): The assertion you mentioned shouldn't really ever happen (that's why it's an assertion an not a |
I changed the harvest_done() function as you mentioned I was doing wierd things. again still learning hehe.
Could it be possible that I am moving the items too fast and it being made null, I recall seeing the item when I had print() lines where it would show up twice then null then show again. I'll add the print() back in and see what I get. |
So I change code some more to first put the list of items into a var, then check if that is not empty before trying to move anything. However the same Assertion fails: Item count is infinite! Hmm... it seems to me like it is setting the stack_size but the item has no other properties that were specified in my item Protoset... I'm still able to get the prototype values I set for the items in code... but why are the item nodes missing properties from the protoset? |
Do I have to specify the missing values everytime in code? |
Think I narrowed it down to the _get_space_for_single_item() function, which returns a large negative number.
Looks like the node changed... is that from item.duplicate() ? or did I do something? |
Unfortunately, this is not going to work 😬: print_debug(count)
print_debug(count.count) where a value of -1 will represent infinity. Or you can insert the following func _to_string() -> String:
if self.is_inf():
return "INF"
return str(count) The large negative number that you're seeing is just a numeric representation of a reference to an
That looks fine. The item duplicate is only a temporary object that is not added to the scene and is therefore not visible in the remote scene tree.
Nah, that also looks fine. The properties listed when inspecting an item in the debugger are only the overridden properties. The properties that have the same value as the prototype are not listed (i.e. no need to store them if they have the same value as the prototype). Wish I could help you more, but all I can say here is that for some reason |
I loaded up an example and using the inventory_grid_stacked_ex_transfer.tscn
The same issue occurs, but now something new I didn't see before since I was only using 1x1 items.
|
Ok, I think I managed to reproduce all three issues:
I'm already familiar with number 3 and I'm working on a fix. The other two I still have to investigate, but seems like there are some corner cases when the inventory has no space available, but new items are added. Hope I'll figure out a solution soon. |
I pushed some changes to the dev_v2.4.9 branch that should fix most of the issues mentioned above. It would be great if someone could give it a try. |
I should be able to do some testing this weekend on that |
Looks good, not seeing any errors with automerge or autosplitmerge like before.
I did see a large performance impact once inventory is full... which was because I used .sort() on the inventory after every item merge... I should probably defer that or just let the player choose when to sort... I'll make a seperate bug for that issue |
Update: I noticed some additional errors caused by the previous fix, so I came up with a new one and pushed it to dev_v2.4.9. It's still a hack but somewhat less ugly. Will keep testing for side effects... |
v2.4.9 has been merged to master. |
transfer_autosplitmerge fails to transfer any items to a full inventory with full stacks or even partial stacks.
assert(!item_count.eq(ItemCount.inf()), "Item count shouldn'td bew infinite!")
adding a print before this reveals the value is -1, which is the default value set for inf in the item_count.gd script.
print(str("Item Count: ",item_count," Count: ",item_count.count))
In my script the transfer_automerge failed returning false so it falls back onto transfer_autosplitmerge which throws an assert cause of the item_count == -1
My thought process was if the automerge return false I would instead use autosplitmerge to fill up the remaining stacks.
The text was updated successfully, but these errors were encountered: