Skip to content

Commit

Permalink
rebirth shuffle some player config stuff because need PROFILEMAN loaded
Browse files Browse the repository at this point in the history
we have to delay replacing and recalculating a bunch of stuff because THEME loads before PROFILEMAN which means we cant find the profile directories to force load or force save from those directories at startup
  • Loading branch information
poco0317 committed Feb 19, 2023
1 parent 298bec9 commit 2c53bd5
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions Themes/Rebirth/Scripts/01 player_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ local defaultConfig = {
DisplayStdDev = false,
Leaderboard = 0, -- 0=off, 1=online, 2=local (current rate)
MeasureCounter = false,
MeasureLines = false,
MiniProgressBar = true,
NPSDisplay = true,
NPSGraph = true,
Expand Down Expand Up @@ -264,7 +263,7 @@ playerConfig.load = function(self, slot)
force_table_elements_to_match_type = function()
end

if slot == nil then
if slot == nil and PROFILEMAN then
slot = pn_to_profile_slot(PLAYER_1)
end

Expand All @@ -280,7 +279,7 @@ playerConfig.load = function(self, slot)
if next(x) == nil and next(globalSettings) ~= nil then
-- should be safe to do this
-- this doesnt create a copy, but globalSettings should never be accessed anywhere anyways
ms.ok("Loaded PlayerConfig settings from global PlayerConfig")
print("Loaded PlayerConfig settings from global PlayerConfig")
globalConfig:set_data(slot, globalSettings)
globalConfig:set_dirty(slot)
globalConfig:save(slot)
Expand Down Expand Up @@ -386,69 +385,71 @@ playerConfig.load = function(self, slot)
defaultConfig.GameplayXYCoordinates["12K"] = coords
defaultConfig.GameplayXYCoordinates["16K"] = coords
end

--
--------
force_table_elements_to_match_type = tmp
return tmp2(self, slot)
local loaded = tmp2(self, slot)

-- converting coordinates if aspect ratio changes across loads
local coords = self:get_data(slot).GameplayXYCoordinates
if coords and coords["4K"] then
-- converting all categories individually
for cat, t in pairs(self:get_data(slot).GameplayXYCoordinates) do
for e, v in pairs(t) do
-- dont scale defaulted coordinates
if defaultGameplayCoordinates[e] ~= nil and v ~= defaultGameplayCoordinates[e] then
if e:sub(-1) == "Y" then
-- convert y pos
t[e] = v / convertYPosRatio
elseif e:sub(-1) == "X" then
-- convert x pos
t[e] = v / convertXPosRatio
end
end
end
end

-- hacks for specifically the error bar this is really bad
local sz = self:get_data(slot).GameplaySizes
if sz and sz["4K"] then
for cat, t in pairs(sz) do
if t["ErrorBarWidth"] ~= defaultGameplaySizes["ErrorBarWidth"] then
sz[cat]["ErrorBarWidth"] = t["ErrorBarWidth"] / convertXPosRatio
end
if t["ErrorBarHeight"] ~= defaultGameplaySizes["ErrorBarHeight"] then
sz[cat]["ErrorBarHeight"] = t["ErrorBarHeight"] / convertYPosRatio
end
end
end
self:get_data(slot).ConvertedAspectRatio = true
end

return loaded
end
playerConfig:load()

-- shadow settings_mt.save to force save() to save in the player's slot instead of the global slot
local tmpsave = playerConfig.save
playerConfig.save = function(self, slot)
print("Saving PlayerConfig")
if slot == nil then
if slot == nil and PROFILEMAN then
slot = pn_to_profile_slot(PLAYER_1)
end
return tmpsave(self, slot)
end
-- shadow set_dirty to do the same thing again because set_dirty is required to save
local tmpdirty = playerConfig.set_dirty
playerConfig.set_dirty = function(self, slot)
if slot == nil then
if slot == nil and PROFILEMAN then
slot = pn_to_profile_slot(PLAYER_1)
end
return tmpdirty(self, slot)
end
-- shadow get_data to do the same thing again because this is how we load anything into the tables
local tmpget = playerConfig.get_data
playerConfig.get_data = function(self, slot)
if slot == nil then
if slot == nil and PROFILEMAN then
slot = pn_to_profile_slot(PLAYER_1)
end
return tmpget(self, slot)
end

-- converting coordinates if aspect ratio changes across loads
local coords = playerConfig:get_data().GameplayXYCoordinates
if coords and coords["4K"] then
-- converting all categories individually
for cat, t in pairs(playerConfig:get_data().GameplayXYCoordinates) do
for e, v in pairs(t) do
-- dont scale defaulted coordinates
if defaultGameplayCoordinates[e] ~= nil and v ~= defaultGameplayCoordinates[e] then
if e:sub(-1) == "Y" then
-- convert y pos
t[e] = v / convertYPosRatio
elseif e:sub(-1) == "X" then
-- convert x pos
t[e] = v / convertXPosRatio
end
end
end
end

-- hacks for specifically the error bar this is really bad
local sz = playerConfig:get_data().GameplaySizes
if sz and sz["4K"] then
for cat, t in pairs(sz) do
if t["ErrorBarWidth"] ~= defaultGameplaySizes["ErrorBarWidth"] then
sz[cat]["ErrorBarWidth"] = t["ErrorBarWidth"] / convertXPosRatio
end
if t["ErrorBarHeight"] ~= defaultGameplaySizes["ErrorBarHeight"] then
sz[cat]["ErrorBarHeight"] = t["ErrorBarHeight"] / convertYPosRatio
end
end
end
playerConfig:get_data().ConvertedAspectRatio = true
end

0 comments on commit 2c53bd5

Please sign in to comment.