Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Add day time and brightness display
Browse files Browse the repository at this point in the history
Closes #3.

This also reorganizes the GUI control script to split it into more
modular pieces, each of which is only concerned with one piece of
functionality.
  • Loading branch information
narc0tiq committed Jul 23, 2015
1 parent 516c7d0 commit efa9406
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 19 deletions.
78 changes: 61 additions & 17 deletions evoGUI.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,72 @@
require "defines"

if not evogui then evogui = {} end
evogui.previous = -1
evogui.update_delay = 60 -- ticks to wait between each GUI update
evogui.previous = nil -- game tick when we did our last GUI update

local function update_gui()
local run_time_seconds = math.floor(game.tick/60)
local run_time_minutes = math.floor(run_time_seconds/60)
local run_time_hours = math.floor(run_time_minutes/60)

if evogui.previous ~= run_time_seconds then
if evogui.previous == nil or (game.tick - evogui.previous) >= evogui.update_delay then
for i, player in ipairs(game.players) do
if player.gui.top.evoGUI == nil then
player.gui.top.add{type="frame", name="evoGUI", direction = "vertical"}
player.gui.top.evoGUI.add{type="label", name="evolution_factor"}
player.gui.top.evoGUI.add{type="label", name="run_time"}
evogui.create_or_update(player)

if player.gui.top.evoGUI then
evogui.update_evolution(player.gui.top.evoGUI)
evogui.update_run_time(player.gui.top.evoGUI)
evogui.update_day_time(player.gui.top.evoGUI)
end
player.gui.top.evoGUI.evolution_factor.caption = string.format("Biter evolution: %0.1f%%", game.evolution_factor * 100)
player.gui.top.evoGUI.run_time.caption = string.format("Play time: %d:%02d:%02d",
run_time_hours,
run_time_minutes % 60,
run_time_seconds % 60)
end
evogui.previous = run_time_seconds
evogui.previous = game.tick
end
end

evogui.update_gui = update_gui

local function create_or_update(player)
if not player.gui.top.evoGUI then
player.gui.top.add{type="frame", name="evoGUI", direction = "vertical"}
player.gui.top.evoGUI.add{type="label", name="day_time"}
player.gui.top.evoGUI.add{type="label", name="evolution_factor"}
player.gui.top.evoGUI.add{type="label", name="run_time"}
end

if not player.gui.top.evoGUI.day_time or
not player.gui.top.evoGUI.evolution_factor or
not player.gui.top.evoGUI.run_time then
player.gui.top.evoGUI.destroy()
end
end
evogui.create_or_update = create_or_update

local function update_evolution(evoGUI)
evoGUI.evolution_factor.caption = string.format("Biter evolution: %0.1f%%", game.evolution_factor * 100)
end
evogui.update_evolution = update_evolution

local function update_run_time(evoGUI)
local run_time_seconds = math.floor(game.tick/60)
local run_time_minutes = math.floor(run_time_seconds/60)
local run_time_hours = math.floor(run_time_minutes/60)

evoGUI.run_time.caption = string.format("Play time: %d:%02d:%02d",
run_time_hours,
run_time_minutes % 60,
run_time_seconds % 60)
end
evogui.update_run_time = update_run_time

local function update_day_time(evoGUI)
-- 0.5 is midnight; let's make days *start* at midnight instead.
local day_time = math.fmod(game.daytime + 0.5, 1)

local day_time_minutes = math.floor(day_time * 24 * 60)
local day_time_hours = math.floor(day_time_minutes / 60)

local rounded_minutes = day_time_minutes - (day_time_minutes % 15)

local brightness = math.floor((1 - game.darkness) * 100)

evoGUI.day_time.caption = string.format("The time is: %d:%02d. Brightness: %d%%",
day_time_hours,
rounded_minutes % 60,
brightness)
end
evogui.update_day_time = update_day_time
4 changes: 2 additions & 2 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "EvoGUI",
"version": "0.1.1",
"version": "0.2.0",
"title": "Evolution Factor Indicator",
"author": "Octav \"narc\" Sandulescu",
"contact": "[email protected]",
"homepage": "None right now",
"homepage": "https://github.com/narc0tiq/evoGUI/",
"description": "Places an indicator on your UI telling you the current biter evolution factor (as a percentage). It also tells you how long you've been playing.",
"dependencies": ["base >= 0.12.0"]
}

0 comments on commit efa9406

Please sign in to comment.