PageRenderTime 102ms CodeModel.GetById 60ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/Tukui/core/configui.lua

http://github.com/Asphyxia/Tukui
Lua | 60 lines | 48 code | 7 blank | 5 comment | 28 complexity | 9980bbb8a14060fdbd78d443d8c5da51 MD5 | raw file
 1----------------------------------------------------------------------------
 2-- This Module loads new user settings if TukUI_ConfigUI is loaded
 3----------------------------------------------------------------------------
 4local T, C, L = unpack(select(2, ...)) -- Import Functions/Constants, Config, Locales
 5
 6local myPlayerRealm = GetCVar("realmName")
 7local myPlayerName  = UnitName("player")
 8
 9if not IsAddOnLoaded("TukUI_ConfigUI") then return end
10
11if not TukuiConfigAll then TukuiConfigAll = {} end		
12if (TukuiConfigAll[myPlayerRealm] == nil) then TukuiConfigAll[myPlayerRealm] = {} end
13if (TukuiConfigAll[myPlayerRealm][myPlayerName] == nil) then TukuiConfigAll[myPlayerRealm][myPlayerName] = false end
14
15if TukuiConfigAll[myPlayerRealm][myPlayerName] == true and not TukuiConfig then return end
16if TukuiConfigAll[myPlayerRealm][myPlayerName] == false and not TukuiConfigSettings then return end
17
18
19if TukuiConfigAll[myPlayerRealm][myPlayerName] == true then
20	for group,options in pairs(TukuiConfig) do
21		if C[group] then
22			local count = 0
23			for option,value in pairs(options) do
24				if C[group][option] ~= nil then
25					if C[group][option] == value then
26						TukuiConfig[group][option] = nil	
27					else
28						count = count+1
29						C[group][option] = value
30					end
31				end
32			end
33			-- keeps TukuiConfig clean and small
34			if count == 0 then TukuiConfig[group] = nil end
35		else
36			TukuiConfig[group] = nil
37		end
38	end
39else
40	for group,options in pairs(TukuiConfigSettings) do
41		if C[group] then
42			local count = 0
43			for option,value in pairs(options) do
44				if C[group][option] ~= nil then
45					if C[group][option] == value then
46						TukuiConfigSettings[group][option] = nil	
47					else
48						count = count+1
49						C[group][option] = value
50					end
51				end
52			end
53			-- keeps TukuiConfig clean and small
54			if count == 0 then TukuiConfigSettings[group] = nil end
55		else
56			TukuiConfigSettings[group] = nil
57		end
58	end
59end
60