Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------
- -- /lib/Logger
- -------------------------------
- --- This packages handles the debug log
- --os.loadAPI('lib/utils')
- debug = {} -- the public API to hold the logger functions
- local logfilename = "log.txt"
- -- store the log in the global table _G so that if multiple scripts do the os.loadAPI on this one it still adds to the same log
- --_G.debug_log = _G.debug_log or {}
- --local debug_log = _G.debug_log -- keep all messages of debug log here
- debug_log = {} -- keep all messages of debug log here
- --- Adds a message to the debug log file
- function debug.log(message)
- local fullmsg = message
- local timestamp = os.clock()
- --add to the log
- table.insert(debug_log, {time=timestamp,message=fullmsg})
- local log_msg = timestamp..": "..fullmsg.."\n"
- --save message to logfile
- if #debug_log == 1 then
- --if it is the first message then reset the log file
- file_write(log_msg, logfilename)
- else
- --append it to the log file
- file_append(log_msg, logfilename)
- end
- end
- local symbols = {
- "(X) ",
- "(-) "
- }
- local spin = 1
- --- Displays the game information in the terminal
- -- if detailed is true it diplays also the latest log events and the buildzone stats
- -- by default detailed is false
- function debug.printState(game, detailed)
- detailed = detailed or false
- --print("starting debug display")
- term.clear()
- term.setTextColor(colors.green)
- print("20.000 BLOCKS v."..game.version_number.." - (HOLD CTRL+T TO QUIT) "..symbols[spin])
- spin = spin +1
- if spin > #symbols then spin = 1 end
- if detailed then
- --[[ disabled for now until we deal with the TP glitches
- if number_of_players_adventure and number_of_players_creative then
- print("TOTAL PLAYERS: "..(number_of_players_adventure + number_of_players_creative).." - ADVENTURE [ "..number_of_players_adventure.." ], CREATIVE [ "..number_of_players_creative.." ]")
- end
- --]]
- --if number_of_players_adventure then
- print("TOTAL ADVENTURE MODE PLAYERS: "..(number_of_players_adventure or 0))
- --end
- term.setTextColor(colors.white)
- --local line = 2
- for i,kew in ipairs(game.queues) do
- local minutes = string.format("%02d",math.floor(kew.timer/60))
- local seconds = string.format("%02d",math.floor(kew.timer - (minutes*60)))
- print("BUILDZONE "..i.." | PHASE: "..kew.phase.." | TIME: "..math.floor(kew.timer).." | PLAYERS: "..tableLength(kew.playerlist))
- print("-LIST: "..tostring(kew.playerlist))
- --print(json.encode(kew.playerlist))
- end
- --use the remaining terminal lines to show the log
- -- the terminal has 19 lines, 18 available for printing, last one stays clear at all times
- term.setTextColor(colors.red)
- print("===== LATEST LOG:")
- for i=13-(2*#game.queues), 0, -1 do
- if #debug_log > i then
- print(debug_log[#debug_log-i].message:sub (1,51)) --trim the logged message to fit into a single line in the terminal
- end
- end
- end
- term.setTextColor(colors.white)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement