-
Notifications
You must be signed in to change notification settings - Fork 0
/
globalData.lua
73 lines (58 loc) · 1.62 KB
/
globalData.lua
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
-- globalData.lua
local json = require 'json'
local const = require 'constants'
local GD = {
paletteName = 'NATURAL',
colorBaize = const.COLORS.Tan,
colorTile = const.COLORS.Ivory,
colorTappy = const.COLORS.Moccasin,
colorSelected = const.COLORS.Gold,
colorRoboto = const.COLORS.Silver,
}
-- GD.statusbar
-- GD.wordbar
-- GD.grid
-- GD.toolbar
-- GD.mode
-- GD.dim
-- GD.groupGrid -- child of Twitty sceneGroup
-- GD.groupUI -- child of Twitty sceneGroup
function GD:setPalette(paletteName)
self.paletteName = paletteName
local paletteValues = const.PALETTE[paletteName]
if not paletteValues then
paletteValues = const.PALETTE.NATURAL
end
self.colorBaize = paletteValues.baize
self.colorTile = paletteValues.tile
self.colorTappy = paletteValues.tappy
self.colorSelected = paletteValues.selected
self.colorRoboto = paletteValues.roboto
end
local filePath = system.pathForFile('settings.json', system.DocumentsDirectory)
function GD:loadSettings()
local file, msg = io.open(filePath, 'r')
if file then
local contents = file:read('*a')
io.close(file)
trace('settings loaded from', filePath)
local settings = json.decode(contents)
if settings.paletteName then
self:setPalette(settings.paletteName)
end
else
trace('cannot open', filePath, msg)
end
end
function GD:saveSettings()
local settings = {paletteName = self.paletteName}
local file, msg = io.open(filePath, 'w')
if file then
file:write(json.encode(settings, {indent=true}))
trace('settings written to', filePath)
io.close(file)
else
trace('cannot open', filePath, msg)
end
end
return GD