2024-08-02 08:34:54 +02:00
|
|
|
local RawData = Object:extend()
|
2024-08-01 23:14:47 +02:00
|
|
|
local DataList = Object:extend()
|
|
|
|
|
2024-08-02 08:34:54 +02:00
|
|
|
local ListHolder = require "classes.dataholders.listholder"
|
|
|
|
local SimpleHolder = require "classes.dataholders.simpleholder"
|
2024-08-02 08:39:28 +02:00
|
|
|
local StatHolder = require "classes.dataholders.statholder"
|
2024-08-02 09:06:50 +02:00
|
|
|
local CompetenceHolder = require "classes.dataholders.competenceholder"
|
2024-08-10 19:32:28 +02:00
|
|
|
local ArmesHolder = require "classes.dataholders.armesholder"
|
|
|
|
local ArmureHolder = require "classes.dataholders.armureholder"
|
2024-08-02 08:34:54 +02:00
|
|
|
|
|
|
|
function RawData.fromLine(line)
|
2024-08-01 23:14:47 +02:00
|
|
|
line = utils.removeComment(line)
|
|
|
|
if (#line == 0) then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
local command = utils.split(line, "|")
|
|
|
|
local datas = utils.split(utils.trim(command[1]), ";")
|
|
|
|
local args = {}
|
|
|
|
name = utils.trim(datas[1])
|
|
|
|
for i, v in ipairs(datas) do
|
|
|
|
if (i > 1) then
|
2024-08-02 08:53:17 +02:00
|
|
|
local str = utils.trim(v)
|
|
|
|
if ((str ~= nil and str ~= "") or i < #datas) then
|
|
|
|
table.insert(args, str)
|
|
|
|
end
|
2024-08-01 23:14:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
local level = 0
|
|
|
|
if (command[2] ~= nil) then
|
|
|
|
levelString = utils.trim(command[2]);
|
|
|
|
level = tonumber(levelString) or 0
|
|
|
|
end
|
2024-08-02 08:34:54 +02:00
|
|
|
return RawData(name, commands.clean(args, name), level)
|
2024-08-01 23:14:47 +02:00
|
|
|
end
|
|
|
|
|
2024-08-02 08:34:54 +02:00
|
|
|
function RawData:new(name, arguments, level)
|
2024-08-01 23:14:47 +02:00
|
|
|
self.name = name
|
|
|
|
self.arguments = arguments
|
|
|
|
self.level = level
|
|
|
|
end
|
|
|
|
|
2024-08-02 08:34:54 +02:00
|
|
|
function RawData:canBeUsed(level)
|
|
|
|
return level >= self.level
|
|
|
|
end
|
|
|
|
|
|
|
|
function RawData:getKey()
|
|
|
|
return utils.split(self.name, ".", true)[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
function RawData:getCommand()
|
|
|
|
return utils.split(self.name, ".", true)[2] or ""
|
|
|
|
end
|
|
|
|
|
|
|
|
function DataList.getHolder(key, value)
|
2024-08-02 09:06:50 +02:00
|
|
|
if (value.dataType == "list") then
|
2024-08-02 08:34:54 +02:00
|
|
|
return ListHolder(key, value)
|
2024-08-02 09:06:50 +02:00
|
|
|
elseif (value.dataType == "comp") then
|
|
|
|
return CompetenceHolder(key, value)
|
2024-08-02 08:39:28 +02:00
|
|
|
elseif (value.dataType == "stat") then
|
|
|
|
return StatHolder(key, value)
|
2024-08-10 19:32:28 +02:00
|
|
|
elseif (value.dataType == "armure") then
|
|
|
|
return ArmureHolder(key, value)
|
|
|
|
elseif (value.dataType == "armes") then
|
|
|
|
return ArmesHolder(key, value)
|
2024-08-02 08:34:54 +02:00
|
|
|
end
|
|
|
|
return SimpleHolder(key, value)
|
|
|
|
end
|
|
|
|
|
2024-08-06 21:00:05 +02:00
|
|
|
function DataList:new(forceLevel)
|
|
|
|
self.forceLevel = forceLevel
|
2024-08-01 23:14:47 +02:00
|
|
|
self.list = {}
|
2024-08-02 08:34:54 +02:00
|
|
|
self.holders = {}
|
2024-08-01 23:56:04 +02:00
|
|
|
self.reducedList = {}
|
2024-08-01 23:14:47 +02:00
|
|
|
for key, value in pairs(commands.getDefaults()) do
|
2024-08-02 08:34:54 +02:00
|
|
|
table.insert(self.list, RawData(key, value, 0))
|
|
|
|
end
|
|
|
|
for key, struct in pairs(commands.structs) do
|
|
|
|
self.holders[key] = DataList.getHolder(key, struct)
|
2024-08-01 23:14:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function DataList:addLine(line)
|
2024-08-02 08:34:54 +02:00
|
|
|
table.insert(self.list, RawData.fromLine(line))
|
2024-08-01 23:14:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function DataList:reduce()
|
2024-08-02 08:34:54 +02:00
|
|
|
local level = 0
|
2024-08-10 19:32:28 +02:00
|
|
|
local mode = "creature"
|
2024-08-02 08:34:54 +02:00
|
|
|
for _, rawdata in ipairs(self.list) do
|
|
|
|
if (rawdata.name == "level") then
|
2024-08-02 09:09:17 +02:00
|
|
|
level = rawdata.arguments
|
2024-08-02 08:34:54 +02:00
|
|
|
end
|
2024-08-10 19:32:28 +02:00
|
|
|
if (rawdata.name == "mode") then
|
|
|
|
mode = rawdata.arguments
|
|
|
|
end
|
2024-08-02 08:34:54 +02:00
|
|
|
end
|
|
|
|
|
2024-08-10 19:32:28 +02:00
|
|
|
|
2024-08-06 21:00:05 +02:00
|
|
|
if (self.forceLevel ~= nil) then
|
|
|
|
level = self.forceLevel
|
|
|
|
end
|
|
|
|
|
2024-08-02 08:34:54 +02:00
|
|
|
for _, rawdata in ipairs(self.list) do
|
|
|
|
if (rawdata:canBeUsed(level)) then
|
|
|
|
self.holders[rawdata:getKey()]:applyCommand(rawdata:getCommand(), rawdata.arguments)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for key, holder in pairs(self.holders) do
|
2024-08-06 21:09:49 +02:00
|
|
|
--self.reducedList[key] = holder:reduce(level)
|
2024-08-10 19:32:28 +02:00
|
|
|
self:addToReducedList(key, holder:reduce(level, mode))
|
2024-08-02 08:34:54 +02:00
|
|
|
end
|
|
|
|
|
2024-08-06 21:00:05 +02:00
|
|
|
if (self.forceLevel ~= nil) then
|
|
|
|
self.reducedList["level"] = self.forceLevel
|
|
|
|
end
|
2024-08-01 23:14:47 +02:00
|
|
|
end
|
|
|
|
|
2024-08-06 21:09:49 +02:00
|
|
|
function DataList:addToReducedList(key, data)
|
|
|
|
local to = commands.structs[key].to or key
|
|
|
|
local toSplited = utils.split(to, ".", true)
|
|
|
|
if (#toSplited == 1) then
|
|
|
|
self.reducedList[to] = data
|
|
|
|
else
|
|
|
|
local list = self.reducedList
|
|
|
|
for i, toPart in ipairs(toSplited) do
|
|
|
|
if (i == #toSplited) then
|
|
|
|
list[toPart] = data
|
|
|
|
else
|
|
|
|
if (list[toPart] == nil) then
|
|
|
|
list[toPart] = {}
|
|
|
|
end
|
|
|
|
list = list[toPart]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-08-02 11:43:34 +02:00
|
|
|
function DataList:prepareJson(simplercreatures, creatures, parent)
|
2024-08-02 08:34:54 +02:00
|
|
|
self:reduce()
|
2024-08-02 10:31:28 +02:00
|
|
|
|
2024-08-02 11:43:34 +02:00
|
|
|
self.reducedList.parent = parent
|
|
|
|
|
2024-08-02 10:31:28 +02:00
|
|
|
table.insert(simplercreatures, {nom = self.reducedList.name, level = self.reducedList.level, nomType = self.reducedList.nomType, categorie = self.reducedList.categorie})
|
|
|
|
table.insert(creatures, self.reducedList)
|
2024-08-01 23:14:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return DataList
|