bdd-creature/libs/commands.lua

71 lines
1.8 KiB
Lua
Raw Normal View History

2024-08-01 23:14:47 +02:00
local struct = require "struct"
local commands = {}
local defaults = {}
local functions = {}
print("Compilation des commandes")
local function addCommands(command, parent, default)
commands[command] = parent
if (default ~= nil) then
defaults[command] = default
end
end
local function addStatCommands(name, value)
addCommands(name .. ".base", name, value.default)
2024-08-06 22:22:43 +02:00
addCommands(name .. ".lvl", name, value.lvl or 0)
2024-08-01 23:14:47 +02:00
addCommands(name .. ".add", name, 0)
addCommands(name .. ".bonus", name, 0)
end
2024-08-02 09:06:50 +02:00
local function addCompCommands(name, value)
addCommands(name, name)
addCommands(name .. ".reset", name)
addCommands(name .. ".lvl", name)
addCommands(name .. ".add", name)
addCommands(name .. ".bonus", name)
end
2024-08-01 23:14:47 +02:00
local function addListCommands(name, value)
addCommands(name, name)
addCommands(name .. ".replace", name)
addCommands(name .. ".reset", name)
end
for key, value in pairs(struct) do
if (value.dataType == "stat") then
addStatCommands(key, value)
elseif (value.dataType == "list") then
addListCommands(key, value)
elseif (value.dataType == "comp") then
2024-08-02 09:06:50 +02:00
addCompCommands(key, value)
2024-08-01 23:14:47 +02:00
else
2024-08-01 23:26:55 +02:00
addCommands(key, key, value.default)
2024-08-01 23:14:47 +02:00
end
end
function functions.getDefaults()
return defaults
end
2024-08-01 23:56:04 +02:00
function functions.clean(args, command)
local baseCommand = commands[command]
if (baseCommand == nil) then
2024-08-02 09:06:50 +02:00
error("Command " .. command .. " doesn't exists")
2024-08-01 23:56:04 +02:00
end
2024-08-02 08:53:17 +02:00
local commandData = struct[baseCommand]
if (commandData.args == nil or commandData.args == 1) then
2024-08-01 23:56:04 +02:00
local arg = args[1]
2024-08-02 08:53:17 +02:00
if (commandData.contentType == "number") then
2024-08-01 23:56:04 +02:00
arg = tonumber(arg)
end
return arg
end
return args
end
2024-08-02 08:34:54 +02:00
functions.structs = struct
2024-08-01 23:14:47 +02:00
return functions