Added format_time

This commit is contained in:
Cooldude2606
2019-03-24 16:58:20 +00:00
parent 7c4210f8b4
commit 6f6a1732ce
4 changed files with 114 additions and 3 deletions

View File

@@ -135,4 +135,66 @@ function Public.ext_require(path,...)
return Public.extract_keys(rtn,...)
end
--- Formats ticks into a time format - this is alot of work and will do later
-- time denominations: D,H,M,S,T days,hours,minutes,seconds,ticks
-- time prefixes (minutes as example): %m,%m,%M,%MM just the value, value with short tag, value with long tag
-- adding a number after the prefix AND denomination will show that many decimal palaces
-- examples: '%H %M' => '0H 0M'; '%MM and %SS3' => '0 Minutes and 0.000 Seconds'
function Public.format_time(ticks,format)
local has_days, has_hours, has_minutes, has_seconds, has_ticks = false,false,false,false,false
local max_days, max_hours = ticks/5184000, ticks/216000
local max_minutes, max_seconds, max_ticks = ticks/3600, ticks/60, ticks
local days, hours = max_days, max_hours-math.floor(max_days)*5184000
local minutes, seconds = max_minutes-math.floor(max_hours)*216000, max_seconds-math.floor(max_minutes)*3600
local tags = {}
return 'Use format_time_simple currently WIP'
end
--- Formats tick into a time format, this format is predefined to either H:M:S; HH MM SS or H Hours M Minutes S seconds
-- seconds are not required to be shown with option show_seconds = false, true to show them, default false
-- show_sub_seconds will show three decimal places for the seconds
-- long_format will use words rather than letters
-- tagged is default to true when false it will remove all letters and use :
-- @tparam ticks number the number of ticks that represents a time
-- @tparam options table a table of options to use for the format
function Public.format_time_simple(ticks,options)
-- Sets up the options
options = {
show_seconds = options.show_seconds or false,
show_sub_seconds = options.show_sub_seconds or false,
long_format = options.long_format or false,
tagged = options.tagged or true
}
-- Basic numbers that are used in calculations
local max_hours, max_minutes, max_seconds = ticks/216000, ticks/3600, ticks/60
local hours, minutes, seconds = max_hours, max_minutes-math.floor(max_hours)*216000, max_seconds-math.floor(max_minutes)*3600
-- Format options
local suffix = 'time-format.short-'
if options.long_format then
suffix = 'time-format.long-'
end
local div = 'time-format.simple-format-tagged'
if options.tagged then
div = 'time-format.simple-format-div'
suffix = false
end
-- The returned numbers in the right format
local rtn_hours, rtn_minutes, rtn_seconds = math.floor(hours), math.floor(minutes), math.floor(seconds)
if suffix then
rtn_hours = {suffix..'hours',rtn_hours}
rtn_minutes = {suffix..'minutes',rtn_minutes}
if options.show_sub_seconds then
rtn_seconds = {suffix..'seconds',string.format('%d03',seconds)}
else
rtn_seconds = {suffix..'seconds',rtn_seconds}
end
end
-- The final return is construed
local rtn = {div,rtn_hours,rtn_minutes}
if options.show_seconds then
rtn = {div,rtn,rtn_seconds}
end
return rtn
end
return Public

View File

@@ -14,4 +14,19 @@ invalid-param=Invalid Param "__1__"; __2__
command-help=__1__ - __2__
command-ran=Command Complete
command-fail=Command failed to run: __1__
command-error-log-format=[ERROR] command/__1__ :: __2__
command-error-log-format=[ERROR] command/__1__ :: __2__
[time-format]
simple-format-none=__1__
simple-format-div=__1__:__2__
simple-format-tagged=__1__ __2__
long-days=__1__ __plural_for_parameter_1_{1=Day|rest=Days}__
short-days=__1__D
long-hours=__1__ __plural_for_parameter_1_{1=Hour|rest=Hours}__
short-hours=__1__H
long-minutes=__1__ __plural_for_parameter_1_{1=Minute|rest=Minutes}__
short-minutes=__1__M
long-seconds=__1__ __plural_for_parameter_1_{1=Second|rest=Seconds}__
short-seconds=__1__S
long-ticks=__1__ __plural_for_parameter_1_{1=Tick|rest=Ticks}__
short-ticks=__1__T

View File

@@ -3,5 +3,38 @@ local Game = require 'utils.game'
local Global = require 'utils.global'
local Commands = require 'expcore.commands'
local config = require 'config.death_markers'
local opt_require = ext_require('expcore.common','opt_require')
opt_require 'config.command_auth_runtime_disable' -- if the file is present then we can disable the commands
local opt_require, format_time = ext_require('expcore.common','opt_require','format_time_simple')
opt_require 'config.command_auth_runtime_disable' -- if the file is present then we can disable the commands rather than not load them
local bodies = {
--{player_name='Cooldude2606',time_of_death='15H 15M',body=LuaEntity,tag=LuaCustomChartTag}
}
Global.register(bodies,function(tbl)
bodies = tbl
end)
--- Checks that all map tags are present and valid
-- adds missing ones, deletes expired ones
local function check_map_tags()
end
--- Teleports the owner of a body to the body
local function teleport_player(body)
end
--- Teleports the items in a body to a certain position putting it in chests
-- if there are no chests close by them some are created
local function teleport_items(body,position)
end
Event.add(defines.events.on_player_died,function(event)
end)
local check_period = 60*60*5 -- five minutes
Event.on_nth_tick(check_period,function(event)
end)

View File

@@ -5,6 +5,7 @@ local Common = require 'expcore.common'
-- modules that are loaded into the interface env to be accessed
local interface_modules = {
['Game']='utils.game',
['_C']=Common,
['Commands']=Commands,
['output']=Common.player_return,
['Group']='expcore.permission_groups'