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
-- Those values come from files and chatcommands
local validate_success, validate_message = yl_scheduler.validate(at, func, params, owner, notes)
if (validate_success == false) then
return false, validate_message
end
local validate_success, validate_message =
yl_scheduler.validate(at, func, params, owner, notes)
if (validate_success == false) then return false, validate_message end
local task = {}
-- UUID
local get_uuid_success, UUID = yl_scheduler.create_uuid()
if get_uuid_success == false then
return false, UUID
end
if get_uuid_success == false then return false, UUID end
task.id = UUID
-- at
-- Try to find what timeformat we are
-- Caclulate utc time from this given time format
-- Try to find what timeformat we are
-- Caclulate utc time from this given time format
task.at = at
-- func
@ -48,14 +45,12 @@ local function set_task(at, func, params, owner, notes)
task.owner = owner
-- notes, optional
task.notes= notes or ""
task.notes = notes or ""
-- save to file
local write_file_success = yl_scheduler.save_json(UUID, task)
if write_file_success == false then
return false, "Cannot write file"
end
if write_file_success == false then return false, "Cannot write file" end
-- store in table
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_remove.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)
timer = timer + dtime
if timer <= yl_scheduler.config.interval then
return
end
if timer <= yl_scheduler.config.interval then return end
timer = 0
-- do stuff

View File

@ -1,9 +1,7 @@
-- Version 0.0.1
-- Author AliasAlreadyTaken
-- License MIT
-- Changelog
local mod_start_time = minetest.get_us_time()
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 .. "api.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")
local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000

View File

@ -226,7 +226,6 @@ local function load_all_tasks()
end
-- Sort table for "at"
-- TODO: What's more efficient? Sort by at? use index with UUID?
yl_scheduler.tasks = sort_by_timestamp(tasks)
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" ..
"Example: /scheduler_add 1712679465$minetest.log$action,mytext$string,string$mynotes\n"
elseif c_params == "helpmask" then
return true, "Provide a parameter mask to convert the parameters to number or table" ..
"Allowed values are \"string\",\"number\",\"table\"" ..
"If your use case requires other types, please create a wrapper function."
return true,
"Provide a parameter mask to convert the parameters to number or table" ..
"Allowed values are \"string\",\"number\",\"table\"" ..
"If your use case requires other types, please create a wrapper function."
end
local t_parameters = string.split(c_params, "$", true)
local at = tonumber(t_parameters[1])
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 mask = string.split(t_parameters[4], ",") or {} -- optional
local owner = name or "N/A"