From a2e2a7a27d0b77fca75e06045bd11e8ce02ef3af Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 14 Jul 2017 17:46:42 +0100 Subject: [PATCH] Added Tick To Display Format --- locale/ExpGaming-Core/ExpGaming - Lib.lua | 14 ++++++++++---- locale/ExpGaming-Core/ExpGaming - Rank Table.lua | 4 ++-- .../GUI/ExpGaming - Player Table.lua | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/locale/ExpGaming-Core/ExpGaming - Lib.lua b/locale/ExpGaming-Core/ExpGaming - Lib.lua index 9bc0d51a..8573c28b 100644 --- a/locale/ExpGaming-Core/ExpGaming - Lib.lua +++ b/locale/ExpGaming-Core/ExpGaming - Lib.lua @@ -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 ) diff --git a/locale/ExpGaming-Core/ExpGaming - Rank Table.lua b/locale/ExpGaming-Core/ExpGaming - Rank Table.lua index 0f38bbfe..006673e9 100644 --- a/locale/ExpGaming-Core/ExpGaming - Rank Table.lua +++ b/locale/ExpGaming-Core/ExpGaming - Rank Table.lua @@ -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 diff --git a/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua b/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua index 4fde1e24..95337d5c 100644 --- a/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua +++ b/locale/ExpGaming-Core/GUI/ExpGaming - Player Table.lua @@ -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