07-18-19, 01:08 PM | #1 |
Inventory sorting
Hi!
I have an issue that I have been scratching my head about for a couple of days, and I was wondering if you good folks could assist me. I'm making a bag addon that allows the user to separate slots from the main bag into separate bags. However, after a custom bag has been deleted, I need to reorder the slots, such that custom bags always use the "last" slots, I refer to this as "defragging". I can rearrange the slots easily enough, but part of defragging involves moving items around in the inventory, such that to the user, they would appear to remain in place, and this is where my issue lies. My approach so far has been to treat it as a problem of sorting. I impose a virtual order before I do any defragging. After I have reordered the slots, and thus shuffled the virtual order, I use a selection sort to swap the items around in the inventory. The below image is before defragging. The numbers on the slots is bag number concatinated with a three digit slot number. Notice that the numbers in the bag called "Title - 1" (i.e. the Main bag) to the bottom is higher than those in the custom bag. This is my desired result. Notice that the actual slots have shifted, but the items remain in place within the bags. This is what actually happens. Notice that the slots are indeed in the correct place, but the items are misplaced. Here are some relevant code sections: Defragging Lua Code:
The utility functions passed to the sort function Lua Code:
The sorting function itself (It says cyclesort, but it is a selection sort. For now anyway ). The coroutine is resumed OnUpdate. Lua Code:
The entire thing is available here, if you wish to play around with it: https://github.com/Malakahh/ObeliskBags/tree/WoWIBug To recreate the issue: 1) Create a 10 slot bag 2) Create a 16 slot bag 3) Delete the 10 slot bag 4) Defrag I don't know if it matters, but I have been using a 16slot backpack and 4x 10slot bags for testing. Hopefully it's not so simple as me doing sorting wrong, but I can't really think of anything else it could be. Please help Edit: I seem to have circumvented my issue by taking a different approach. Instead of sorting based on a virtual slot number, I now record which items are supposed to be in which virtual slots. I scan my bags to find an item with matching Id (and quantity, if stackable) and place it in that virtual slot. I then "lock" the slot to make sure the item isn't moved again, and repeat for the remainder of the inventory. I still don't understand why my original approach doesn't seem to do the trick, but I guess it's moot at this point Last edited by Malakahh : 07-26-19 at 01:13 PM. Reason: Circumvented my issue |
|
WoWInterface » Developer Discussions » Lua/XML Help » Inventory sorting |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|