1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/utils/debug/command.lua

106 lines
2.4 KiB
Lua
Raw Normal View History

2019-03-10 00:17:19 +02:00
local DebugView = require 'utils.debug.main_view'
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
2020-10-10 20:37:28 +02:00
if not player or not player.valid then
return
2019-03-10 00:17:19 +02:00
end
2020-10-10 20:37:28 +02:00
if not player.admin then
player.print('Only admins can use this command.')
return
end
2021-03-28 17:01:39 +02:00
2021-05-01 21:19:45 +02:00
-- if (player.name ~= 'Gerkiz' and not _DEBUG) then
-- return
-- end
2021-04-04 13:51:27 +02:00
2020-10-10 20:37:28 +02:00
DebugView.open_debug(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
2020-10-10 20:37:28 +02:00
local Model = require 'model'
local loadstring = loadstring
local pcall = pcall
local dump = Model.dump
local log = log
2020-06-24 12:40:18 +02:00
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