Formatting

This commit is contained in:
AliasAlreadyTaken 2024-04-12 00:01:13 +02:00
parent d0f0a5fb14
commit c66412c415
5 changed files with 16 additions and 25 deletions

21
api.lua
View File

@ -17,25 +17,22 @@ local function set_task(at, func, params, owner, notes)
-- Defense -- Defense
-- Those values come from files and chatcommands -- Those values come from files and chatcommands
local validate_success, validate_message = yl_scheduler.validate(at, func, params, owner, notes) local validate_success, validate_message =
if (validate_success == false) then yl_scheduler.validate(at, func, params, owner, notes)
return false, validate_message if (validate_success == false) then return false, validate_message end
end
local task = {} local task = {}
-- UUID -- UUID
local get_uuid_success, UUID = yl_scheduler.create_uuid() local get_uuid_success, UUID = yl_scheduler.create_uuid()
if get_uuid_success == false then if get_uuid_success == false then return false, UUID end
return false, UUID
end
task.id = UUID task.id = UUID
-- at -- at
-- Try to find what timeformat we are -- Try to find what timeformat we are
-- Caclulate utc time from this given time format -- Caclulate utc time from this given time format
task.at = at task.at = at
-- func -- func
@ -48,14 +45,12 @@ local function set_task(at, func, params, owner, notes)
task.owner = owner task.owner = owner
-- notes, optional -- notes, optional
task.notes= notes or "" task.notes = notes or ""
-- save to file -- save to file
local write_file_success = yl_scheduler.save_json(UUID, task) local write_file_success = yl_scheduler.save_json(UUID, task)
if write_file_success == false then if write_file_success == false then return false, "Cannot write file" end
return false, "Cannot write file"
end
-- store in table -- store in table
table.insert(yl_scheduler.tasks, task) table.insert(yl_scheduler.tasks, task)

View File

@ -1,4 +1,4 @@
dofile(yl_scheduler.modpath .. "chatcommand_scheduler_add.lua") dofile(yl_scheduler.modpath .. "chatcommand_scheduler_add.lua")
dofile(yl_scheduler.modpath .. "chatcommand_scheduler_remove.lua") dofile(yl_scheduler.modpath .. "chatcommand_scheduler_remove.lua")
dofile(yl_scheduler.modpath .. "chatcommand_scheduler_list.lua") dofile(yl_scheduler.modpath .. "chatcommand_scheduler_list.lua")
dofile(yl_scheduler.modpath .. "chatcommand_scheduler_clean.lua") dofile(yl_scheduler.modpath .. "chatcommand_scheduler_clean.lua")

View File

@ -2,9 +2,7 @@ local timer = 0
local gs = function(dtime) local gs = function(dtime)
timer = timer + dtime timer = timer + dtime
if timer <= yl_scheduler.config.interval then if timer <= yl_scheduler.config.interval then return end
return
end
timer = 0 timer = 0
-- do stuff -- do stuff

View File

@ -1,9 +1,7 @@
-- Version 0.0.1 -- Version 0.0.1
-- Author AliasAlreadyTaken -- Author AliasAlreadyTaken
-- License MIT -- License MIT
-- Changelog -- Changelog
local mod_start_time = minetest.get_us_time() local mod_start_time = minetest.get_us_time()
minetest.log("action", "[MOD] yl_scheduler loading") minetest.log("action", "[MOD] yl_scheduler loading")
@ -26,7 +24,7 @@ dofile(yl_scheduler.modpath .. "setup.lua")
dofile(yl_scheduler.modpath .. "internal.lua") dofile(yl_scheduler.modpath .. "internal.lua")
dofile(yl_scheduler.modpath .. "api.lua") dofile(yl_scheduler.modpath .. "api.lua")
dofile(yl_scheduler.modpath .. "initialize.lua") dofile(yl_scheduler.modpath .. "initialize.lua")
--dofile(yl_scheduler.modpath .. "globalsteps.lua") -- dofile(yl_scheduler.modpath .. "globalsteps.lua")
dofile(yl_scheduler.modpath .. "chatcommands.lua") dofile(yl_scheduler.modpath .. "chatcommands.lua")
local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000 local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000

View File

@ -226,7 +226,6 @@ local function load_all_tasks()
end end
-- Sort table for "at" -- Sort table for "at"
-- TODO: What's more efficient? Sort by at? use index with UUID?
yl_scheduler.tasks = sort_by_timestamp(tasks) yl_scheduler.tasks = sort_by_timestamp(tasks)
if bad == 0 then if bad == 0 then
@ -326,16 +325,17 @@ local function cmd_scheduler_add(name, c_params)
"Separate time, function, parameters, mask and notes with $\n" .. "Separate time, function, parameters, mask and notes with $\n" ..
"Example: /scheduler_add 1712679465$minetest.log$action,mytext$string,string$mynotes\n" "Example: /scheduler_add 1712679465$minetest.log$action,mytext$string,string$mynotes\n"
elseif c_params == "helpmask" then elseif c_params == "helpmask" then
return true, "Provide a parameter mask to convert the parameters to number or table" .. return true,
"Allowed values are \"string\",\"number\",\"table\"" .. "Provide a parameter mask to convert the parameters to number or table" ..
"If your use case requires other types, please create a wrapper function." "Allowed values are \"string\",\"number\",\"table\"" ..
"If your use case requires other types, please create a wrapper function."
end end
local t_parameters = string.split(c_params, "$", true) local t_parameters = string.split(c_params, "$", true)
local at = tonumber(t_parameters[1]) local at = tonumber(t_parameters[1])
local func = t_parameters[2] local func = t_parameters[2]
--local string_params = string.split(t_parameters[3], ",") -- optional -- local string_params = string.split(t_parameters[3], ",") -- optional
local params = string.split(t_parameters[3], ",") -- optional local params = string.split(t_parameters[3], ",") -- optional
local mask = string.split(t_parameters[4], ",") or {} -- optional local mask = string.split(t_parameters[4], ",") or {} -- optional
local owner = name or "N/A" local owner = name or "N/A"