Sort the creative inventory:

Item groups like glass and crystals are now at the bottom.
Items at the top are now sorted.
Fixes #341
This commit is contained in:
IntegratedQuantum 2024-05-02 12:22:53 +02:00
parent 3419034754
commit a575edae45

View File

@ -33,12 +33,26 @@ pub fn trySwappingItems(index: usize, destination: *ItemStack) void {
destination.amount = destination.item.?.stackSize();
}
fn lessThan(_: void, lhs: Item, rhs: Item) bool {
if(lhs == .baseItem and rhs == .baseItem) {
const lhsFolders = std.mem.count(u8, lhs.baseItem.id, "/");
const rhsFolders = std.mem.count(u8, rhs.baseItem.id, "/");
if(lhsFolders < rhsFolders) return true;
if(lhsFolders > rhsFolders) return false;
return std.ascii.lessThanIgnoreCase(lhs.baseItem.id, rhs.baseItem.id);
} else {
if(lhs == .baseItem) return true;
return false;
}
}
pub fn onOpen() void {
items = main.List(Item).init(main.globalAllocator);
var itemIterator = main.items.iterator();
while(itemIterator.next()) |item| {
items.append(Item{.baseItem = item.*});
}
std.mem.sort(Item, items.items, {}, lessThan);
const list = VerticalList.init(.{padding, padding + 16}, 140, 0);
var i: u32 = 0;