Don't reset player setting groups right after game load, refactor update group functions

ini_importer_tests
uramer 11 months ago
parent 9cce2e39ba
commit 2008f35e57

@ -396,51 +396,38 @@ local function onGroupRegistered(global, key)
end end
end end
local function updateGroups(global)
local function updatePlayerGroups() local groupSection = common.getSection(global, common.groupSectionKey)
local playerGroups = storage.playerSection(common.groupSectionKey) for groupKey in pairs(groupSection:asTable()) do
for groupKey in pairs(playerGroups:asTable()) do onGroupRegistered(global, groupKey)
onGroupRegistered(false, groupKey)
end end
playerGroups:subscribe(async:callback(function(_, key) groupSection:subscribe(async:callback(function(_, key)
if key then if key then
onGroupRegistered(false, key) onGroupRegistered(global, key)
else else
for groupKey in pairs(playerGroups:asTable()) do for groupKey in pairs(groupSection:asTable()) do
onGroupRegistered(false, groupKey) onGroupRegistered(global, groupKey)
end end
end end
end)) end))
end end
local updatePlayerGroups = function() updateGroups(false) end
updatePlayerGroups() updatePlayerGroups()
local function updateGlobalGroups() local updateGlobalGroups = function() updateGroups(true) end
local globalGroups = storage.globalSection(common.groupSectionKey)
for groupKey in pairs(globalGroups:asTable()) do
onGroupRegistered(true, groupKey)
end
globalGroups:subscribe(async:callback(function(_, key)
if key then
onGroupRegistered(true, key)
else
for groupKey in pairs(globalGroups:asTable()) do
onGroupRegistered(true, groupKey)
end
end
end))
end
local menuGroups = {} local menuGroups = {}
local menuPages = {} local menuPages = {}
local function resetPlayerGroups() local function resetPlayerGroups()
local settingGroupsSection = storage.playerSection(common.groupSectionKey) print('MENU reset player groups')
local playerGroupsSection = storage.playerSection(common.groupSectionKey)
for pageKey, page in pairs(groups) do for pageKey, page in pairs(groups) do
for groupKey, group in pairs(page) do for groupKey, group in pairs(page) do
if not menuGroups[groupKey] and not group.global then if not menuGroups[groupKey] and not group.global then
page[groupKey] = nil page[groupKey] = nil
settingGroupsSection:set(groupKey, nil) playerGroupsSection:set(groupKey, nil)
end end
end end
if pageOptions[pageKey] then if pageOptions[pageKey] then
@ -513,10 +500,11 @@ return {
}, },
engineHandlers = { engineHandlers = {
onStateChanged = function() onStateChanged = function()
resetPlayerGroups()
if menu.getState() == menu.STATE.Running then if menu.getState() == menu.STATE.Running then
updatePlayerGroups() updatePlayerGroups()
updateGlobalGroups() updateGlobalGroups()
else
resetPlayerGroups()
end end
end, end,
}, },

Loading…
Cancel
Save