From 17550d480f321551485c57150e014c86c2cf03a0 Mon Sep 17 00:00:00 2001 From: urnati Date: Thu, 6 Apr 2023 21:41:34 -0400 Subject: [PATCH] - Fix for copy profiles --- Titan/TitanVariables.lua | 74 ++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/Titan/TitanVariables.lua b/Titan/TitanVariables.lua index 9cb2f36..dae37bb 100644 --- a/Titan/TitanVariables.lua +++ b/Titan/TitanVariables.lua @@ -324,23 +324,6 @@ The cooresponding Defaults table holds the starting values. The original Titan (full width) bars values are used for default X and Y :DESC -]] -TitanBarPositions = {} -TitanBarPositionsDefaults = { - [TITAN_PANEL_DISPLAY_PREFIX.."Bar"] = {off_x=0, off_y=0, off_w = x_max, }, - [TITAN_PANEL_DISPLAY_PREFIX.."Bar2"] = {off_x=0, off_y=-(TITAN_PANEL_BAR_HEIGHT), off_w = x_max, }, - [TITAN_PANEL_DISPLAY_PREFIX.."AuxBar2"] = {off_x=0, off_y=(TITAN_PANEL_BAR_HEIGHT * 2), off_w = x_max, }, - [TITAN_PANEL_DISPLAY_PREFIX.."AuxBar"] = {off_x=0, off_y=(TITAN_PANEL_BAR_HEIGHT), off_w = x_max, }, - [TITAN_PANEL_DISPLAY_PREFIX.."Short01"] = {off_x=x_mid, off_y=Calc_Y(3), off_w = SHORT_WIDTH, }, - [TITAN_PANEL_DISPLAY_PREFIX.."Short02"] = {off_x=x_mid, off_y=Calc_Y(4), off_w = SHORT_WIDTH, }, - [TITAN_PANEL_DISPLAY_PREFIX.."Short03"] = {off_x=x_mid, off_y=Calc_Y(5), off_w = SHORT_WIDTH, }, - [TITAN_PANEL_DISPLAY_PREFIX.."Short04"] = {off_x=x_mid, off_y=Calc_Y(6), off_w = SHORT_WIDTH, }, - [TITAN_PANEL_DISPLAY_PREFIX.."Short05"] = {off_x=x_mid, off_y=Calc_Y(7), off_w = SHORT_WIDTH, }, - [TITAN_PANEL_DISPLAY_PREFIX.."Short06"] = {off_x=x_mid, off_y=Calc_Y(8), off_w = SHORT_WIDTH, }, - [TITAN_PANEL_DISPLAY_PREFIX.."Short07"] = {off_x=x_mid, off_y=Calc_Y(9), off_w = SHORT_WIDTH, }, - [TITAN_PANEL_DISPLAY_PREFIX.."Short08"] = {off_x=x_mid, off_y=Calc_Y(10), off_w = SHORT_WIDTH, }, - [TITAN_PANEL_DISPLAY_PREFIX.."Short09"] = {off_x=x_mid, off_y=Calc_Y(11), off_w = SHORT_WIDTH, }, - [TITAN_PANEL_DISPLAY_PREFIX.."Short10"] = {off_x=x_mid, off_y=Calc_Y(12), off_w = SHORT_WIDTH, }, -} TitanBarDataVars = {} TitanBarVarsDefaults = { ["Global"] = -- holds 'global' user settings; NOT for use in the frame loop! @@ -879,19 +862,11 @@ function TitanVariables_InitTitanSettings() TitanPlayerSettings["Plugins"] = {} TitanPlayerSettings["Panel"] = {} TitanPlayerSettings["Register"] = {} - TitanPlayerSettings["BarData"] = TitanBarPositionsDefaults -- New Mar 2023 TitanPlayerSettings["BarVars"] = TitanBarVarsDefaults -- New Mar 2023 new_toon = true end -- New Mar 2023 : TitanSettings.Players[player].BarData to hold Short bar data - if TitanSettings.Players[player].BarData then - -- All good - else - -- Set to defaults - TitanSettings.Players[player].BarData = TitanBarPositionsDefaults - end - -- New Mar 2023 : TitanSettings.Players[player].BarData to hold Short bar data if TitanSettings.Players[player].BarVars then -- All good else @@ -946,26 +921,26 @@ function TitanVariables_SetBarPos(self, reset, x_off, y_off, w_off) local force_reset = reset or false - if TitanBarPositions[bar_frame] then + if TitanBarDataVars[bar_frame] then if reset then -- Initial defaults calc on screen and scaling at that time - it could have changed! - TitanBarPositions[bar_frame].off_x = Calc_X() - TitanBarPositions[bar_frame].off_y = Calc_Y(TitanBarData[bar_frame].order-2) - TitanBarPositions[bar_frame].off_w = SHORT_WIDTH + TitanBarDataVars[bar_frame].off_x = Calc_X() + TitanBarDataVars[bar_frame].off_y = Calc_Y(TitanBarData[bar_frame].order-2) + TitanBarDataVars[bar_frame].off_w = SHORT_WIDTH else -- local to show bars as needed - TitanBarPositions[bar_frame].off_x = x_off - TitanBarPositions[bar_frame].off_y = y_off - TitanBarPositions[bar_frame].off_w = w_off + TitanBarDataVars[bar_frame].off_x = x_off + TitanBarDataVars[bar_frame].off_y = y_off + TitanBarDataVars[bar_frame].off_w = w_off end end --[[ print("_SetBarPos" .." "..tostring(self:GetName()).."" .." "..tostring(reset).."" -.." x: "..tostring(format("%0.1f", (TitanBarPositions[bar_frame].off_x or -1.0))).."" -.." y: "..tostring(format("%0.1f", (TitanBarPositions[bar_frame].off_y or -1.0))).."" -.." w: "..tostring(format("%0.1f", (TitanBarPositions[bar_frame].off_w or -1.0))).."" +.." x: "..tostring(format("%0.1f", (TitanBarDataVars[bar_frame].off_x or -1.0))).."" +.." y: "..tostring(format("%0.1f", (TitanBarDataVars[bar_frame].off_y or -1.0))).."" +.." w: "..tostring(format("%0.1f", (TitanBarDataVars[bar_frame].off_w or -1.0))).."" ) --]] end @@ -978,9 +953,25 @@ OUT: X, Y, Width --]] function TitanVariables_GetBarPos(frame_str) return - TitanBarPositions[frame_str].off_x, - TitanBarPositions[frame_str].off_y, - TitanBarPositions[frame_str].off_w + TitanBarDataVars[frame_str].off_x, + TitanBarDataVars[frame_str].off_y, + TitanBarDataVars[frame_str].off_w +end + +-- lua-users.org/wiki/CopyTable +local function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy end --[[ local @@ -1022,6 +1013,7 @@ TitanDebug("_UseSettings " TitanPlayerSettings = TitanSettings.Players[to_profile]; TitanPluginSettings = TitanPlayerSettings["Plugins"]; TitanPanelSettings = TitanPlayerSettings["Panel"]; + TitanBarDataVars = TitanPlayerSettings["BarVars"] TitanVariables_SyncRegisterSavedVariables(TITAN_PANEL_SAVED_VARIABLES, TitanPanelSettings) @@ -1035,7 +1027,7 @@ TitanDebug("_UseSettings " -- The requested profile at least exists so we can copy to it -- Copy from the from_profile to profile - not anything in saved vars -- Get the bar data settings - TitanBarPositions = Get_Saved_BarData(from_profile) +-- TitanBarPositions = Get_Saved_BarData(from_profile) if from_profile and TitanSettings.Players[from_profile] then old_player = TitanSettings.Players[from_profile] @@ -1047,6 +1039,10 @@ TitanDebug("_UseSettings " if old_player and old_player["Plugins"] then old_plugins = old_player["Plugins"] end + -- Copy Bar data + if old_player and old_player["BarVars"] then + TitanBarDataVars = deepcopy(old_player["BarVars"]) + end -- Copy the panel settings for index, id in pairs(old_panel) do TitanPanelSetVar(index, old_panel[index]); -- 1.7.9.5