Miscellaneous fixes in loading of sprees, rules and greetings

* fixed counts being returned
* implement some checks for TOML parsing
This commit is contained in:
Timo Smit 2019-01-18 15:36:06 +01:00
parent 11c0903b95
commit 2d145254fe
3 changed files with 29 additions and 15 deletions

View file

@ -53,11 +53,13 @@ function rules.load()
local fileTable = toml.parse(fileString)
local amount
local amount = 0
for _, rule in ipairs(fileTable["rule"]) do
if rule["shortcut"] and rule["rule"] then
data[rule["shortcut"]] = rule["rule"]
amount = amount + 1
end
end

View file

@ -127,7 +127,7 @@ function sprees.load()
local fileTable = toml.parse(fileString)
local amount
local amount = 0
for name, block in pairs(fileTable) do
for _, spree in ipairs(block) do
@ -135,6 +135,8 @@ function sprees.load()
table.insert(spreeMessagesByType[sprees.getRecordTypeByName(name)], spree)
spreeMessages[sprees.getRecordTypeByName(name)][spree["amount"]] = spree
amount = amount + 1
end
end
end

View file

@ -103,25 +103,35 @@ function greetings.load()
local fileTable = toml.parse(fileString)
for _, greeting in ipairs(fileTable["level"]) do
if greeting["greeting"] then
levelGreetings[greeting["level"]] = {
["text"] = greeting["greeting"],
["sound"] = greeting["sound"]
}
local amount = 0
if fileTable["level"] then
for _, greeting in ipairs(fileTable["level"]) do
if greeting["greeting"] then
levelGreetings[greeting["level"]] = {
["text"] = greeting["greeting"],
["sound"] = greeting["sound"]
}
amount = amount + 1
end
end
end
for _, greeting in ipairs(fileTable["user"]) do
if greeting["greeting"] then
userGreetings[greeting["guid"]] = {
["text"] = greeting["greeting"],
["sound"] = greeting["sound"]
}
if fileTable["user"] then
for _, greeting in ipairs(fileTable["user"]) do
if greeting["greeting"] then
userGreetings[greeting["guid"]] = {
["text"] = greeting["greeting"],
["sound"] = greeting["sound"]
}
amount = amount + 1
end
end
end
return #fileTable["level"] + #fileTable["user"]
return amount
else
-- compatibility for 1.1.* and lower
outputDebug("Using .cfg files is deprecated as of 1.2.0. Please consider updating to .toml files.", 3)