Merge pull request #466 from bbassie/fix/quickbar-pages

Use page and slot for quick bar filters
This commit is contained in:
Cooldude2606
2026-09-06 01:08:32 +01:00
committed by GitHub
+15 -23
View File
@@ -20,46 +20,38 @@ PlayerFilters:set_metadata{
end, end,
} }
--- Filters are stored by a single index across the ten pages of ten slots
local total_page_count = 10
local slots_per_page = 10
--- Loads your quickbar preset --- Loads your quickbar preset
PlayerFilters:on_load(function(player_name, filters) PlayerFilters:on_load(function(player_name, filters)
if not filters then filters = config[player_name] end if not filters then filters = config[player_name] end
if not filters then return end if not filters then return end
local player = game.players[player_name] local player = game.players[player_name]
for i, item_name in pairs(filters) do for index, item_name in pairs(filters) do
if item_name ~= nil and item_name ~= "" then if item_name ~= nil and item_name ~= "" then
player.set_quick_bar_slot(i, item_name) local page = math.ceil(index / slots_per_page)
local slot = (index - 1) % slots_per_page + 1
player.set_quick_bar_slot(page, slot, item_name)
end end
end end
end) end)
local ignored_items = { --- Saves your quickbar preset, only plain item filters can be saved
["blueprint"] = true,
["blueprint-book"] = true,
["deconstruction-planner"] = true,
["spidertron-remote"] = true,
["upgrade-planner"] = true,
}
--- Saves your quickbar preset to the script-output folder
Commands.new("save-quickbar", "Saves your Quickbar preset items to file") Commands.new("save-quickbar", "Saves your Quickbar preset items to file")
:add_aliases{ "save-toolbar" } :add_aliases{ "save-toolbar" }
:add_flags{ "disabled" }
:register(function(player) :register(function(player)
local filters = {} local filters = {}
error("2.1 changes to get_quick_bar_slot beak compatibility with 2.0; waiting for upstream") for page = 1, total_page_count do
-- Upstream may add method to compat, or change inventory sync to have a quickbar only mode for slot = 1, slots_per_page do
for i = 1, 100 do -- Records, remotes and specific item instances hold data which can not be saved by name
--[[ local quick_bar_slot = player.get_quick_bar_slot(page, slot)
local slot = player.get_quick_bar_slot(i) if quick_bar_slot and quick_bar_slot.type == "filter" then
-- Need to filter out blueprint and blueprint books because the slot is a LuaItemPrototype and does not contain a way to export blueprint data filters[(page - 1) * slots_per_page + slot] = assert(quick_bar_slot.filter).name
if slot ~= nil then
local ignored = ignored_items[slot.name]
if ignored ~= true then
filters[i] = slot.name
end end
end end
]]
end end
if next(filters) then if next(filters) then