Added Tick To Display Format

This commit is contained in:
Cooldude2606
2017-07-14 17:46:42 +01:00
parent 97d3fd0596
commit a2e2a7a27d
3 changed files with 13 additions and 7 deletions

View File

@@ -18,15 +18,21 @@ local credits = {{
}}
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
--Please Only Edit Below This Line-----------------------------------------------------------
--this converts ticks to 12H 34M format or 8.97M when less than 10
function tick_to_display_format(tick)
if tick_to_min(tick) < 10 then
return string.format('%.2f M',tick/(3600*game.speed))
else
return string.format('%d H %d M',tick_to_hour(tick),tick_to_min(tick)-60*tick_to_hour(tick))
end
end
--this will convert ticks into hours based on game speed
function tick_to_hour (tick)
local hour = tostring(math.floor(tick/(216000*game.speed)))
return hour
return math.floor(tick/(216000*game.speed))
end
--this will convert ticks into minutes based on game speed
function tick_to_min (tick)
local minutes = math.floor(tick/(3600*game.speed))
return minutes
return math.floor(tick/(3600*game.speed))
end
--i stole this from somewhere a long time ago but this and the other two functions convert a table into a string
function table.val_to_str ( v )

View File

@@ -19,14 +19,14 @@ local credits = {{
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
--Please Only Edit Below This Line-----------------------------------------------------------
--[[
How to add ranks:
Name is what will be used in the scripts and is offten the best chose for display in text.
short_hand is what can be used when short on space but the rank still need to be displayed.
tag is the tag the player will gain when moved to the rank, it can be nil.
time is used for auto rank feature where you are moved to the rank after a certain play time in minutes.
colour is the rgb value that can be used to emphaise gui elelemts based on rank.
power is not in the list below as it is auto defined but allows compairison between ranks.
power is not in the list below as it is auto defined by index but allows compairison between ranks.
disallow is a list containing input acttion that the user can not preform.
For disallow add to the list the end part of the input action
Example: defines.input_action.drop_item -> 'drop_item'
http://lua-api.factorio.com/latest/defines.html#defines.input_action

View File

@@ -110,7 +110,7 @@ function player_table_functions.draw(player,frame,filters,input_location)
if p.connected == true
then player_table.add{name=p.name.."status", type="label", caption="Online"}
else player_table.add{name=p.name.."s", type="label", caption="Offline"} end
player_table.add{name=p.name.."online_time", type="label", caption=(tick_to_hour(p.online_time)..'H '..(tick_to_min(p.online_time)-60*tick_to_hour(p.online_time))..'M')}
player_table.add{name=p.name.."online_time", type="label", caption=tick_to_display_format(p.online_time)}
player_table.add{name=p.name.."rank", type="label", caption=get_rank(p).short_hand}
end
end