45 lines
No EOL
1.1 KiB
Lua
45 lines
No EOL
1.1 KiB
Lua
EventUtils = {}
|
|
|
|
-- steps utils
|
|
|
|
function EventUtils.getStepStructure(stepName)
|
|
local stepTypeList = require "game.events.arguments"
|
|
return stepTypeList[stepName]
|
|
end
|
|
|
|
function EventUtils.stepExists(stepName)
|
|
return (EventUtils.getStepStructure(stepName) ~= nil)
|
|
end
|
|
|
|
function EventUtils.validateStep(stepBaseDatas)
|
|
local structure = EventUtils.getStepStructure(stepBaseDatas[1])
|
|
if (structure == nil) then
|
|
return false
|
|
else
|
|
return ((#structure + 2) == #stepBaseDatas)
|
|
end
|
|
end
|
|
|
|
function EventUtils.getStepDatas(stepBaseDatas)
|
|
local stepData = {}
|
|
stepData.name = stepBaseDatas[1]
|
|
|
|
if (EventUtils.validateStep(stepBaseDatas)) then
|
|
stepData.condition = stepBaseDatas[2]
|
|
|
|
local structure = EventUtils.getStepStructure(stepData.name)
|
|
|
|
stepData.arguments = {}
|
|
|
|
for i, argumentName in ipairs(structure) do
|
|
local argumentContent = stepBaseDatas[i + 2]
|
|
stepData.arguments[argumentName] = argumentContent
|
|
end
|
|
|
|
return stepData
|
|
else
|
|
error("L'étape " .. stepData.name .. " à un nbr d'argument incorrect")
|
|
end
|
|
end
|
|
|
|
return EventUtils |