From 09581b436ddc922f88dce6b8f8696ac1757c0fbb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 1 Aug 2024 23:56:04 +0200 Subject: [PATCH] feat: add lines to data --- classes/beastfile.lua | 2 +- classes/datalist.lua | 7 ++++--- libs/commands.lua | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/classes/beastfile.lua b/classes/beastfile.lua index c6c442a..146b399 100644 --- a/classes/beastfile.lua +++ b/classes/beastfile.lua @@ -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() diff --git a/classes/datalist.lua b/classes/datalist.lua index dab8d74..e0924b8 100644 --- a/classes/datalist.lua +++ b/classes/datalist.lua @@ -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() diff --git a/libs/commands.lua b/libs/commands.lua index 4c6a78a..d1917eb 100644 --- a/libs/commands.lua +++ b/libs/commands.lua @@ -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 \ No newline at end of file