require "defines" require "utils" -------------------------------------------------------------------------------------- script.on_init( -- called once when a new world is created function() end ) -------------------------------------------------------------------------------------- script.on_load( -- called every time a world is loaded (and after a save, as a reload) function() debug_level = -1 end ) -------------------------------------------------------------------------------------- script.on_event(defines.events.on_tick, function(event) if player1 == nil then player1 = game.player -- only ok in single player, will fail in multi ! debug(nil) -- flush the debug mem if player1.gui.top.timebar_frame == nil then player1.gui.top.add({type = "frame", name = "timebar_frame", caption = "", direction = "horizontal", style = "timebar_frame_style"}) player1.gui.top.timebar_frame.add({type = "button", name = "but_time", caption = "00:00", style = "timebar_button_style"}) player1.gui.top.timebar_frame.but_time.style.font_color = iif( game.always_day, yellow, white ) player1.gui.top.timebar_frame.add({type = "button", name = "but_slower", caption = "<" , font_color = white, style = "timebar_button_style"}) player1.gui.top.timebar_frame.add({type = "button", name = "but_speed", caption = "=1" , font_color = white, style = "timebar_button_style"}) player1.gui.top.timebar_frame.add({type = "button", name = "but_faster", caption = ">" , font_color = white, style = "timebar_button_style"}) end sp = 1.0 game.speed = sp else -- update time button if game.tick % 5 == 0 then -- daytime : 0.0 to 1.0, noon to noon, max light to max light... tim = game.daytime tim = (tim*24+12) % 24.00 tim_h = math.floor(tim) tim_m = math.floor((tim-tim_h)*60) player1.gui.top.timebar_frame.but_time.caption = string.format("%02.f:%02.f", tim_h, tim_m ) end end end ) -------------------------------------------------------------------------------------- script.on_event(defines.events.on_gui_click, function(event) if event.element.name == "but_time" then game.always_day = not game.always_day player1.gui.top.timebar_frame.but_time.style.font_color = iif( game.always_day, yellow, white ) elseif event.element.name == "but_slower" then if sp >= 0.2 then sp = sp / 2 end game.speed = sp update_speed() elseif event.element.name == "but_faster" then if sp < 16 then sp = sp * 2 end game.speed = sp update_speed() elseif event.element.name == "but_speed" then if sp == 1 then sp = 16 else sp = 1 end game.speed = sp update_speed() end end ) script.on_event(defines.events.on_rocket_launched, function () guirocket = player1.gui.left.rocket_score if guirocket then player1.print( "Rockets sent : " .. guirocket.rocket_count.caption ) guirocket.destroy() end end ) -------------------------------------------------------------------------------------- function update_speed() if sp == 1 then player1.gui.top.timebar_frame.but_speed.caption = "x1" player1.gui.top.timebar_frame.but_speed.style.font_color = white elseif sp < 1 then player1.gui.top.timebar_frame.but_speed.caption = string.format("/%1.0f", 1/sp ) player1.gui.top.timebar_frame.but_speed.style.font_color = green elseif sp > 1 then player1.gui.top.timebar_frame.but_speed.caption = string.format("x%1.0f", sp ) player1.gui.top.timebar_frame.but_speed.style.font_color = red end end