-
Notifications
You must be signed in to change notification settings - Fork 46
/
settings.go
276 lines (235 loc) · 9.27 KB
/
settings.go
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package main
import (
"log"
"os"
"github.com/adrg/xdg"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
const (
SettingsPath = "MasterPlan/settings08.json"
SettingsLegacyPath = "masterplan-settings08.json"
SettingsTheme = "Theme"
SettingsWindowPosition = "WindowPosition"
SettingsSaveWindowPosition = "SaveWindowPosition"
SettingsCustomFontPath = "CustomFontPath"
SettingsTargetFPS = "TargetFPS"
SettingsUnfocusedFPS = "UnfocusedFPS"
SettingsBorderlessWindow = "BorderlessWindow"
SettingsOutlineWindow = "OutlineWindow"
SettingsAlwaysShowNumbering = "AlwaysShowNumbering"
SettingsNumberTopLevelCards = "NumberTopLevelCards"
SettingsDisplayMessages = "DisplayMessages"
SettingsDoubleClickMode = "DoubleClickMode"
SettingsShowGrid = "ShowGrid"
SettingsFlashSelected = "FlashSelected"
SettingsFocusOnElapsedTimers = "FocusOnElapsedTimers"
SettingsNotifyOnElapsedTimers = "NotifyOnElapsedTimers"
SettingsPlayAlarmSound = "PlayAlarmSound"
SettingsShowAboutDialogOnStart = "ShowAboutDialogOnStart"
SettingsReversePan = "ReversePan"
SettingsAutoLoadLastProject = "AutoLoadLastProject"
SettingsScreenshotPath = "ScreenshotPath"
SettingsSmoothMovement = "SmoothMovement"
SettingsFocusOnSelectingWithKeys = "FocusOnSelectingWithKeys"
SettingsWindowTransparency = "Window Transparency"
SettingsWindowTransparencyMode = "Transparency Mode"
SettingsFocusOnUndo = "FocusOnUndo"
SettingsSuccessfulLoad = "SuccesfulLoad"
SettingsAutoBackup = "Automatic Backups"
SettingsAutoBackupTime = "Backup Timer"
SettingsMaxAutoBackups = "Max Automatic Backup Count"
SettingsMouseWheelSensitivity = "Mouse Wheel Sensitivity"
SettingsZoomToCursor = "Zoom to Cursor"
SettingsCardShadows = "Card Shadows"
SettingsFlashDeadlines = "Flash Deadlines"
SettingsDeadlineDisplay = "Display Deadlines As"
SettingsMaxInternalImageSize = "Max Internal Image Buffer Size"
SettingsPlaceNewCardsInStack = "Position New Cards in Stack"
SettingsHideGridOnZoomOut = "Hide Grid on Zoom out"
SettingsDisplayNumberedPercentagesAs = "Display Numbered Percentages"
SettingsShowTableHeaders = "Display Table Headers"
SettingsBrowserPath = "Browser Path"
SettingsBrowserUserDataPath = "Browser User Data Path"
// SettingsCacheAudioBeforePlayback = "Cache Audio Before Playback"
SettingsAudioVolume = "AudioVolume"
SettingsAudioBufferSize = "Audio Playback Buffer Size"
SettingsAudioSampleRate = "Audio Playback Sample Rate"
DeadlineDisplayCountdown = "Days"
DeadlineDisplayDate = "Date"
DeadlineDisplayIcons = "Icons"
DoubleClickLast = "Creates card of prev. type"
DoubleClickCheckbox = "Creates Checkbox card"
DoubleClickNothing = "Does nothing"
WindowTransparencyNever = "Never"
WindowTransparencyAlways = "Always"
WindowTransparencyMouse = "When mouse is outside window"
WindowTransparencyWindow = "When window is inactive"
)
const (
NumberedPercentagePercent = "Percent"
NumberedPercentageOff = "Off"
NumberedPercentageCurrentMax = "X / Y"
)
const (
Percentage10 = "10%"
Percentage25 = "25%"
Percentage50 = "50%"
Percentage75 = "75%"
Percentage100 = "100%"
Percentage150 = "150%"
Percentage200 = "200%"
Percentage300 = "300%"
Percentage400 = "400%"
Percentage800 = "800%"
)
const (
AudioSampleRate11025 = "11025"
AudioSampleRate22050 = "22050"
AudioSampleRate44100 = "44100"
AudioSampleRate48000 = "48000"
AudioSampleRate88200 = "88200"
AudioSampleRate96000 = "96000"
// AudioSampleRate192000 = "192000"
)
const (
AudioBufferSize32 = "32"
AudioBufferSize64 = "64"
AudioBufferSize128 = "128"
AudioBufferSize256 = "256"
AudioBufferSize512 = "512"
AudioBufferSize1024 = "1024"
AudioBufferSize2048 = "2048"
AudioBufferSize4096 = "4096"
AudioBufferSize8192 = "8192"
AudioBufferSize16384 = "16384"
)
var percentageToNumber map[string]float32 = map[string]float32{
Percentage10: 0.1,
Percentage25: 0.25,
Percentage50: 0.5,
Percentage75: 0.75,
Percentage100: 1,
Percentage150: 1.5,
Percentage200: 2,
Percentage300: 3,
Percentage400: 4,
Percentage800: 8,
}
const (
ImageBufferSize512 = "512"
ImageBufferSize1024 = "1024"
ImageBufferSize2048 = "2048"
ImageBufferSize4096 = "4096"
ImageBufferSize8192 = "8192"
ImageBufferSize16384 = "16384"
ImageBufferSizeMax = "Max"
)
const (
TableHeadersSelected = "Selected"
TableHeadersHover = "Hovering"
TableHeadersAlways = "Always"
)
func NewProgramSettings() *Properties {
// We're setting the defaults here; after setting them, we'll attempt to load settings from a preferences file below
props := NewProperties()
props.Get(SettingsTheme).Set("Moonlight")
props.Get(SettingsTargetFPS).Set(60.0)
props.Get(SettingsUnfocusedFPS).Set(60.0)
props.Get(SettingsDisplayMessages).Set(true)
props.Get(SettingsDoubleClickMode).Set(DoubleClickLast)
props.Get(SettingsShowGrid).Set(true)
props.Get(SettingsSaveWindowPosition).Set(true)
props.Get(SettingsFlashSelected).Set(true)
props.Get(SettingsFocusOnElapsedTimers).Set(false)
props.Get(SettingsNotifyOnElapsedTimers).Set(true)
props.Get(SettingsPlayAlarmSound).Set(true)
props.Get(SettingsShowAboutDialogOnStart).Set(true)
props.Get(SettingsReversePan).Set(false)
props.Get(SettingsCustomFontPath).Set("")
props.Get(SettingsScreenshotPath).Set("")
props.Get(SettingsBrowserPath).Set("")
props.Get(SettingsBrowserUserDataPath).Set("")
props.Get(SettingsAutoLoadLastProject).Set(false)
props.Get(SettingsSmoothMovement).Set(true)
props.Get(SettingsNumberTopLevelCards).Set(true)
props.Get(SettingsFocusOnSelectingWithKeys).Set(true)
props.Get(SettingsFocusOnUndo).Set(true)
props.Get(SettingsOutlineWindow).Set(false)
props.Get(SettingsAutoBackup).Set(true)
props.Get(SettingsAutoBackupTime).Set(10.0)
props.Get(SettingsMaxAutoBackups).Set(6.0)
props.Get(SettingsMouseWheelSensitivity).Set(Percentage100)
props.Get(SettingsZoomToCursor).Set(true)
props.Get(SettingsCardShadows).Set(true)
props.Get(SettingsFlashDeadlines).Set(true)
props.Get(SettingsMaxInternalImageSize).Set(ImageBufferSize2048)
props.Get(SettingsPlaceNewCardsInStack).Set(true)
props.Get(SettingsHideGridOnZoomOut).Set(true)
props.Get(SettingsDisplayNumberedPercentagesAs).Set(NumberedPercentagePercent)
props.Get(SettingsShowTableHeaders).Set(TableHeadersSelected)
// Audio settings; not shown in MasterPlan because it's very rarely necessary to tweak
props.Get(SettingsAudioVolume).Set(80.0)
props.Get(SettingsAudioSampleRate).Set(AudioSampleRate44100)
props.Get(SettingsAudioBufferSize).Set(AudioBufferSize512)
transparency := props.Get(SettingsWindowTransparency)
transparency.Set(1.0)
transparency.OnChange = func() {
globals.WindowTargetTransparency = transparency.AsFloat()
}
props.Get(SettingsWindowTransparencyMode).Set(WindowTransparencyNever)
borderless := props.Get(SettingsBorderlessWindow)
borderless.Set(false)
borderless.OnChange = func() {
if globals.Window != nil {
globals.Window.SetBordered(!borderless.AsBool())
}
}
path, _ := xdg.ConfigFile(SettingsPath)
// Attempt to load the properties here
if FileExists(path) {
jsonData, err := os.ReadFile(path)
if err != nil {
panic(err)
}
globals.SettingsLoaded = true
data := gjson.Get(string(jsonData), "properties").String()
props.Deserialize(data)
recentFiles := gjson.Get(string(jsonData), "recent files")
if recentFiles.Exists() {
array := recentFiles.Array()
for i := 0; i < len(array); i++ {
globals.RecentFiles = append(globals.RecentFiles, array[i].String())
}
}
globals.Keybindings.Deserialize(string(jsonData))
}
props.OnChange = func(property *Property) {
SaveSettings()
}
return props
}
func SaveSettings() {
path, _ := xdg.ConfigFile(SettingsPath)
saveData, _ := sjson.Set("{}", "version", globals.Version.String())
saveData, _ = sjson.SetRaw(saveData, "properties", globals.Settings.Serialize(false))
saveData, _ = sjson.Set(saveData, "recent files", globals.RecentFiles)
saveData, _ = sjson.SetRaw(saveData, "keybindings", globals.Keybindings.Serialize())
saveData = gjson.Get(saveData, "@pretty").String()
if file, err := os.Create(path); err != nil {
log.Println(err)
} else {
file.Write([]byte(saveData))
file.Close()
}
}
// func (ps *OldProgramSettings) CleanUpRecentPlanList() {
// newList := []string{}
// for i, s := range ps.RecentPlanList {
// _, err := os.Stat(s)
// if err == nil {
// newList = append(newList, ps.RecentPlanList[i]) // We could alter the slice to cut out the strings that are invalid, but this is visually cleaner and easier to understand
// }
// }
// ps.RecentPlanList = newList
// }