forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefs.lua
More file actions
133 lines (111 loc) · 3.52 KB
/
prefs.lua
File metadata and controls
133 lines (111 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
--*****************************************************************************
--* File: lua/modules/ui/prefs.lua
--* Author: Chris Blackwell
--* Summary: Access to preferences that are used in the UI
--*
--* Copyright © 2006 Gas Powered Games, Inc. All rights reserved.
--*****************************************************************************
local optionsLogic = import('/lua/options/optionsLogic.lua')
-- check if there are any profiles defined
function ProfilesExist()
local profiles = GetPreference("profile.profiles")
if (not profiles) or (table.getn(profiles) == 0) then
return false
end
return true
end
function GetProfileCount()
local profiles = GetPreference("profile.profiles")
if profiles then
return table.getn(profiles)
else
return 0
end
end
-- creates a profile and sets it as current
-- if it returns false, the name is already chosen
function CreateProfile(name)
local profiles = GetPreference("profile.profiles")
if not profiles then
profiles = {}
end
local foundName = 0
for key, value in profiles do
if value.Name == name then
foundName = key
end
end
local primaryAdapter = GetOption('primary_adapter')
local secondaryAdapter = GetOption('secondary_adapter')
if primaryAdapter == 'overridden' then
primaryAdapter = '1024,768,60'
end
if secondaryAdapter == 'overridden' then
secondaryAdapter = 'disabled'
end
if foundName == 0 then
table.insert(profiles, {Name = name})
SetPreference("profile.current", table.getn(profiles)) -- table.insert adds to the end of the table
else
return false
end
SetPreference("profile.profiles", profiles)
-- set default video options in to new profile, but don't actually cause any functions to get set
SetToCurrentProfile('options', {primary_adapter = primaryAdapter, secondary_adapter = secondaryAdapter})
SavePreferences()
return true
end
function GetCurrentProfile()
local current = nil
local profile = GetPreference('profile')
if profile then
if profile.current then
current = profile.profiles[profile.current]
end
end
return current
end
-- Get the map last requested by the player
function GetFromCurrentProfile(fieldName)
local scenario = nil
local profile = GetCurrentProfile()
if profile then
scenario = profile[fieldName]
end
return scenario
end
-- set the map
function SetToCurrentProfile(fieldName, data)
local profile = GetPreference('profile')
if profile.current then
if profile.profiles[profile.current] then
profile.profiles[profile.current][fieldName] = data
SetPreference('profile', profile)
end
end
end
-- read from the current options set, find and return default if not available
function GetOption(optionKey)
local ret = GetOptions(optionKey)
if ret == nil then
for section, secInfo in optionsLogic.GetOptionsData() do
for index, item in secInfo.items do
if item.key == optionKey then
ret = item.default
break
end
end
end
end
return ret
end
function SetOption(optionKey, newValue)
local tempOptionTable = optionsLogic.GetCurrent()
for i, v in tempOptionTable do
if i == optionKey then
tempOptionTable[i] = newValue
break
end
end
optionsLogic.SetCurrent(tempOptionTable)
end