2018-12-22 10:42:19 +02:00
|
|
|
-- A small debugging tool that writes the contents of _ENV to a file when the game loads.
|
|
|
|
-- Useful for ensuring you get the same information when loading
|
|
|
|
-- the reference and desync levels in desync reports.
|
2019-01-15 15:27:48 +02:00
|
|
|
-- dependencies
|
|
|
|
local table = require 'utils.table'
|
2018-12-22 10:42:19 +02:00
|
|
|
local Event = require 'utils.event'
|
2019-01-15 15:27:48 +02:00
|
|
|
|
|
|
|
-- localized functions
|
2018-12-22 10:42:19 +02:00
|
|
|
local inspect = table.inspect
|
|
|
|
|
2019-01-15 15:27:48 +02:00
|
|
|
-- local constants
|
|
|
|
local filename = 'env_dump.lua'
|
|
|
|
|
2018-12-22 10:42:19 +02:00
|
|
|
-- Removes metatables and the package table
|
|
|
|
local filter = function(item, path)
|
|
|
|
if path[#path] ~= inspect.METATABLE and item ~= 'package' then
|
|
|
|
return item
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function player_joined(event)
|
2019-02-28 22:05:34 +02:00
|
|
|
game.tick_paused = true
|
2018-12-22 10:42:19 +02:00
|
|
|
local dump_string = inspect(_ENV, {process = filter})
|
|
|
|
if dump_string then
|
|
|
|
local s = string.format('tick on join: %s\n%s', event.tick, dump_string)
|
|
|
|
game.write_file(filename, s)
|
|
|
|
game.print('_ENV dumped into ' .. filename)
|
|
|
|
else
|
|
|
|
game.print('_ENV not dumped, dump_string was nil')
|
|
|
|
end
|
2019-02-28 22:05:34 +02:00
|
|
|
game.print('Game is paused. Use /c game.tick_paused = false to resume play')
|
2018-12-22 10:42:19 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
Event.add(defines.events.on_player_joined_game, player_joined)
|