-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.lua
96 lines (62 loc) · 2.22 KB
/
config.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
-- config.lua
-- Contains all the functions to load the config
g_ConfigDefaults =
[[
AxeRequired = false,
Collection = "pickups",
SurvivalOnly = false,
ReplantSapling = true,
SaplingPlantTime = 25,
ReplantSaplingRate = 0.2,
]]
function LoadDefaultSettings()
g_Config = loadstring("return {" .. g_ConfigDefaults .. "}")()
LoadItemCollection()
end
function LoadItemCollection()
if (type(g_Config.Collection) ~= 'string') then
LOGWARNING("[TreeAssist] The item collection is malformed. \"pickups\" will be used.")
g_Config.Collection = "pickups"
end
local CollType = g_Config.Collection:lower()
if (CollType == 'pickups') then
g_CollectionClass = cPickupCollection
elseif (CollType == "instantinventory") then
g_CollectionClass = cToInventoryCollection
else
LOGWARNING("[TreeAssist] item collector \"" .. CollType .. "\" is unknown. \"pickups\" will be used.")
g_CollectionClass = cPickupCollection
end
end
function LoadSettings()
local Path = g_Plugin:GetLocalFolder() .. "/config.cfg"
if (not cFile:IsFile(Path)) then
LOGWARNING("[TreeAssist] The config file doesn't exist. TreeAssist will use the default settings for now")
LoadDefaultSettings()
return
end
local ConfigContent = cFile:ReadWholeFile(Path)
if (ConfigContent == "") then
LOGWARNING("[TreeAssist] The config file is empty. TreeAssist will use the default settings for now")
LoadDefaultSettings()
return
end
local ConfigLoader, Error = loadstring("return {" .. ConfigContent .. "}")
if (not ConfigLoader) then
LOGWARNING("[TreeAssist] There is a problem in the config file. TreeAssist will use the default settings for now.")
LoadDefaultSettings()
return
end
local Result, ConfigTable, Error = pcall(ConfigLoader)
if (not Result) then
LOGWARNING("[TreeAssist] There is a problem in the config file. TreeAssist will use the default settings for now.")
LoadDefaultSettings()
return
end
if (ConfigTable.ReplantSapling and (type(ConfigTable.SaplingPlantTime) ~= 'number')) then
LOGWARNING("[TreeAssist] ReplantSapling is activated, but there is no time set. TreeAssist will use the default time (20 ticks)")
ConfigTable.SaplingPlantTime = 20
end
g_Config = ConfigTable
LoadItemCollection()
end