Use page and slot for quick bar filters

Factorio 2.1 changed get_quick_bar_slot and set_quick_bar_slot to take a
page and slot rather than a single index, and to describe slots holding
records, remotes and specific item instances. Saved filters keep their
single index, which is converted on load and save, and only plain item
filters are saved since the other slot types hold data which has no name
to store. The command is enabled again.

Fixes #444
This commit is contained in:
bbassie
2026-09-05 20:54:21 +00:00
parent 810269971b
commit f961a8d82e
+14 -23
View File
@@ -20,46 +20,37 @@ PlayerFilters:set_metadata{
end, end,
} }
--- Filters are stored by a single index across the ten pages of ten slots
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, slots_per_page 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