1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-24 03:47:58 +02:00
ComfyFactorio/utils/debug/command.lua

111 lines
2.6 KiB
Lua
Raw Normal View History

2019-03-09 23:17:19 +01:00
local DebugView = require 'utils.debug.main_view'
2024-03-28 23:37:14 +01:00
local Server = require 'utils.server'
2019-03-09 23:17:19 +01:00
commands.add_command(
'debug',
'Opens the debugger',
2019-10-26 00:05:52 +02:00
function(_)
2019-03-09 23:17:19 +01:00
local player = game.player
2020-10-10 20:37:28 +02:00
if not player or not player.valid then
return
2019-03-09 23:17:19 +01: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
2024-03-28 23:37:14 +01:00
local secs = Server.get_current_time()
local admins = Server.get_admins_data()
if secs and not admins[player.name] then
player.print('Only admins can use this command.')
return
end
2021-04-04 13:51:27 +02:00
2020-10-10 20:37:28 +02:00
DebugView.open_debug(player)
2019-03-09 23:17:19 +01: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