2019-03-10 00:17:19 +02:00
|
|
|
local DebugView = require 'utils.debug.main_view'
|
2019-10-26 00:05:52 +02:00
|
|
|
local Model = require 'model'
|
|
|
|
|
|
|
|
local loadstring = loadstring
|
|
|
|
local pcall = pcall
|
|
|
|
local dump = Model.dump
|
|
|
|
local log = log
|
2019-03-10 00:17:19 +02:00
|
|
|
|
|
|
|
commands.add_command(
|
|
|
|
'debug',
|
|
|
|
'Opens the debugger',
|
2019-10-26 00:05:52 +02:00
|
|
|
function(_)
|
2019-03-10 00:17:19 +02:00
|
|
|
local player = game.player
|
|
|
|
local p
|
|
|
|
if player then
|
|
|
|
p = player.print
|
|
|
|
if not player.admin then
|
|
|
|
p('Only admins can use this command.')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
else
|
|
|
|
p = player.print
|
|
|
|
end
|
2019-07-06 16:38:03 +02:00
|
|
|
DebugView.open_dubug(player)
|
2019-03-10 00:17:19 +02:00
|
|
|
end
|
|
|
|
)
|
2019-10-26 00:05:52 +02:00
|
|
|
|
2020-06-24 12:40:18 +02:00
|
|
|
if _DEBUG then
|
|
|
|
commands.add_command(
|
|
|
|
'dump-log',
|
|
|
|
'Dumps value to log',
|
|
|
|
function(args)
|
|
|
|
local player = game.player
|
|
|
|
local p
|
|
|
|
if player then
|
|
|
|
p = player.print
|
|
|
|
if not player.admin then
|
|
|
|
p('Only admins can use this command.')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
else
|
|
|
|
p = player.print
|
|
|
|
end
|
|
|
|
if args.parameter == nil then
|
2019-10-26 00:05:52 +02:00
|
|
|
return
|
|
|
|
end
|
2020-06-24 12:40:18 +02:00
|
|
|
local func, err = loadstring('return ' .. args.parameter)
|
2019-10-26 00:05:52 +02:00
|
|
|
|
2020-06-24 12:40:18 +02:00
|
|
|
if not func then
|
|
|
|
p(err)
|
|
|
|
return
|
|
|
|
end
|
2019-10-26 00:05:52 +02:00
|
|
|
|
2020-06-24 12:40:18 +02:00
|
|
|
local suc, value = pcall(func)
|
2019-10-26 00:05:52 +02:00
|
|
|
|
2020-06-24 12:40:18 +02:00
|
|
|
if not suc then
|
|
|
|
p(value)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
log(dump(value))
|
2019-10-26 00:05:52 +02:00
|
|
|
end
|
2020-06-24 12:40:18 +02:00
|
|
|
)
|
2019-10-26 00:05:52 +02:00
|
|
|
|
2020-06-24 12:40:18 +02:00
|
|
|
commands.add_command(
|
|
|
|
'dump-file',
|
|
|
|
'Dumps value to dump.lua',
|
|
|
|
function(args)
|
|
|
|
local player = game.player
|
|
|
|
local p
|
|
|
|
if player then
|
|
|
|
p = player.print
|
|
|
|
if not player.admin then
|
|
|
|
p('Only admins can use this command.')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
else
|
|
|
|
p = player.print
|
|
|
|
end
|
|
|
|
if args.parameter == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local func, err = loadstring('return ' .. args.parameter)
|
2019-10-26 00:05:52 +02:00
|
|
|
|
2020-06-24 12:40:18 +02:00
|
|
|
if not func then
|
|
|
|
p(err)
|
2019-10-26 00:05:52 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-06-24 12:40:18 +02:00
|
|
|
local suc, value = pcall(func)
|
2019-10-26 00:05:52 +02:00
|
|
|
|
2020-06-24 12:40:18 +02:00
|
|
|
if not suc then
|
|
|
|
p(value)
|
|
|
|
return
|
|
|
|
end
|
2019-10-26 00:05:52 +02:00
|
|
|
|
2020-06-24 12:40:18 +02:00
|
|
|
value = dump(value)
|
|
|
|
game.write_file('dump.lua', value, false)
|
2019-10-26 00:05:52 +02:00
|
|
|
end
|
2020-06-24 12:40:18 +02:00
|
|
|
)
|
|
|
|
end
|