2016-01-16 01:26:33 -05:00
|
|
|
-----------------------------------
|
|
|
|
|
-- switch
|
|
|
|
|
-----------------------------------
|
|
|
|
|
|
|
|
|
|
function switch(c)
|
2022-05-28 18:59:26 +03:00
|
|
|
local swtbl =
|
|
|
|
|
{
|
2018-05-01 21:53:02 -04:00
|
|
|
casevar = c,
|
|
|
|
|
caseof = function(self, code)
|
2018-06-22 03:20:06 -04:00
|
|
|
local f
|
2022-11-04 10:44:34 -04:00
|
|
|
if self.casevar then
|
2018-06-22 03:20:06 -04:00
|
|
|
f = code[self.casevar] or code.default
|
2018-05-01 21:53:02 -04:00
|
|
|
else
|
2018-06-22 03:20:06 -04:00
|
|
|
f = code.missing or code.default
|
2018-05-01 21:53:02 -04:00
|
|
|
end
|
2022-11-22 14:42:58 -05:00
|
|
|
|
2022-11-04 10:44:34 -04:00
|
|
|
if f then
|
2023-08-28 21:02:28 -04:00
|
|
|
if type(f) == 'function' then
|
2018-06-22 03:20:06 -04:00
|
|
|
return f(self.casevar, self)
|
2018-05-01 21:53:02 -04:00
|
|
|
else
|
2023-08-28 21:02:28 -04:00
|
|
|
error('case '..tostring(self.casevar)..' not a function')
|
2018-05-01 21:53:02 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-06-22 03:20:06 -04:00
|
|
|
}
|
|
|
|
|
return swtbl
|
|
|
|
|
end
|
2016-01-16 01:26:33 -05:00
|
|
|
|
|
|
|
|
-----------------------------------
|
|
|
|
|
-- printf
|
|
|
|
|
-----------------------------------
|
|
|
|
|
|
2020-07-27 19:35:52 -07:00
|
|
|
function printf(s, ...)
|
2018-06-22 03:20:06 -04:00
|
|
|
print(s:format(...))
|
|
|
|
|
end
|
2016-01-16 01:26:33 -05:00
|
|
|
|
2020-02-23 07:05:57 -08:00
|
|
|
-----------------------------------
|
|
|
|
|
-- set()
|
|
|
|
|
-- Returns a set that can be checked against
|
|
|
|
|
-----------------------------------
|
|
|
|
|
function set(list)
|
|
|
|
|
local set = {}
|
|
|
|
|
for _, item in pairs(list) do
|
|
|
|
|
set[item] = true
|
|
|
|
|
end
|
2022-11-22 14:42:58 -05:00
|
|
|
|
2020-02-23 07:05:57 -08:00
|
|
|
return set
|
|
|
|
|
end
|
|
|
|
|
|
2018-06-22 03:20:06 -04:00
|
|
|
-----------------------------------
|
|
|
|
|
-- getVanaMidnight(day)
|
|
|
|
|
-- Returns earth time value for midnight for current (or supplied day) in epoch format
|
|
|
|
|
-----------------------------------
|
|
|
|
|
|
|
|
|
|
function getVanaMidnight(day)
|
2025-07-03 21:20:08 -04:00
|
|
|
local curtime = GetSystemTime()
|
2025-04-24 07:29:40 -04:00
|
|
|
local secondsToMidnight = xi.vanaTime.DAY - (VanadielTime() % xi.vanaTime.DAY)
|
|
|
|
|
|
2018-06-22 03:20:06 -04:00
|
|
|
if day ~= nil then
|
2025-04-24 07:29:40 -04:00
|
|
|
secondsToMidnight = secondsToMidnight + (day * xi.vanaTime.DAY)
|
2018-06-22 03:20:06 -04:00
|
|
|
end
|
2022-11-22 14:42:58 -05:00
|
|
|
|
2025-04-24 07:29:40 -04:00
|
|
|
return curtime + secondsToMidnight
|
2018-06-22 03:20:06 -04:00
|
|
|
end
|