feat: add lines to data
This commit is contained in:
parent
3687f5297f
commit
09581b436d
3 changed files with 20 additions and 4 deletions
|
@ -12,7 +12,7 @@ function BeastFile:new(folder, name)
|
|||
end
|
||||
|
||||
function BeastFile:readLines()
|
||||
local lines = parseFile(self.filepath, function (line) print(line) end)
|
||||
local lines = parseFile(self.filepath, function (line) self.datas:addLine(line) end)
|
||||
end
|
||||
|
||||
function BeastFile:prepareJson()
|
||||
|
|
|
@ -12,7 +12,7 @@ function Data.fromLine(line)
|
|||
name = utils.trim(datas[1])
|
||||
for i, v in ipairs(datas) do
|
||||
if (i > 1) then
|
||||
table.insert(utils.trim(v))
|
||||
table.insert(args, utils.trim(v))
|
||||
end
|
||||
end
|
||||
local level = 0
|
||||
|
@ -20,7 +20,7 @@ function Data.fromLine(line)
|
|||
levelString = utils.trim(command[2]);
|
||||
level = tonumber(levelString) or 0
|
||||
end
|
||||
return Data(name, args, level)
|
||||
return Data(name, commands.clean(args, name), level)
|
||||
end
|
||||
|
||||
function Data:new(name, arguments, level)
|
||||
|
@ -31,13 +31,14 @@ end
|
|||
|
||||
function DataList:new()
|
||||
self.list = {}
|
||||
self.reducedList = {}
|
||||
for key, value in pairs(commands.getDefaults()) do
|
||||
table.insert(self.list, Data(key, value, 0))
|
||||
end
|
||||
end
|
||||
|
||||
function DataList:addLine(line)
|
||||
table.insert(self.list, Data.line(line))
|
||||
table.insert(self.list, Data.fromLine(line))
|
||||
end
|
||||
|
||||
function DataList:reduce()
|
||||
|
|
|
@ -42,4 +42,19 @@ function functions.getDefaults()
|
|||
return defaults
|
||||
end
|
||||
|
||||
function functions.clean(args, command)
|
||||
local baseCommand = commands[command]
|
||||
if (baseCommand == nil) then
|
||||
error("Command " .. baseCommand .. " doesn't exists")
|
||||
end
|
||||
if (baseCommand.args == nil or baseCommand.args == 1) then
|
||||
local arg = args[1]
|
||||
if (baseCommand.contentType == "number") then
|
||||
arg = tonumber(arg)
|
||||
end
|
||||
return arg
|
||||
end
|
||||
return args
|
||||
end
|
||||
|
||||
return functions
|
Loading…
Reference in a new issue