1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

Merge pull request #734 from grilledham/debugger/player

Allow debugger to dump game.player
This commit is contained in:
Matthew 2019-02-02 14:20:14 -05:00 committed by GitHub
commit f549808650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 36 deletions

View File

@ -3,9 +3,8 @@ local Model = require 'features.gui.debug.model'
local Color = require 'resources.color_presets'
local dump = Model.dump
local dump_text = Model.dump_text
local concat = table.concat
local loadstring = loadstring
local pcall = pcall
local Public = {}
@ -97,23 +96,14 @@ Gui.on_click(
end
)
local function update_dump(text_input, data)
local func = loadstring('return ' .. text_input.text)
if not func then
text_input.style.font_color = Color.red
return
end
local suc, var = pcall(func)
local function update_dump(text_input, data, player)
local suc, ouput = dump_text(text_input.text, player)
if not suc then
text_input.style.font_color = Color.red
return
else
text_input.style.font_color = Color.black
data.right_panel.text = ouput
end
text_input.style.font_color = Color.black
local right_panel = data.right_panel
right_panel.text = dump(var)
end
Gui.on_text_changed(
@ -122,7 +112,7 @@ Gui.on_text_changed(
local element = event.element
local data = Gui.get_data(element)
update_dump(element, data)
update_dump(element, data, event.player)
end
)
@ -134,7 +124,7 @@ Gui.on_click(
local input_text_box = data.input_text_box
update_dump(input_text_box, data)
update_dump(input_text_box, data, event.player)
end
)

View File

@ -6,6 +6,8 @@ local type = type
local concat = table.concat
local inspect = table.inspect
local pcall = pcall
local loadstring = loadstring
local rawset = rawset
local Public = {}
@ -123,4 +125,23 @@ function Public.dump_function(func)
return concat(res)
end
function Public.dump_text(text, player)
local func = loadstring('return ' .. text)
if not func then
return false
end
rawset(game, 'player', player)
local suc, var = pcall(func)
rawset(game, 'player', nil)
if not suc then
return false
end
return true, dump(var)
end
return Public

View File

@ -5,9 +5,8 @@ local Color = require 'resources.color_presets'
local Model = require 'features.gui.debug.model'
local dump = Model.dump
local dump_text = Model.dump_text
local concat = table.concat
local loadstring = loadstring
local pcall = pcall
local Public = {}
@ -93,23 +92,14 @@ Gui.on_click(
end
)
local function update_dump(text_input, data)
local func = loadstring('return ' .. text_input.text)
if not func then
text_input.style.font_color = Color.red
return
end
local suc, var = pcall(func)
local function update_dump(text_input, data, player)
local suc, ouput = dump_text(text_input.text, player)
if not suc then
text_input.style.font_color = Color.red
return
else
text_input.style.font_color = Color.black
data.right_panel.text = ouput
end
text_input.style.font_color = Color.black
local right_panel = data.right_panel
right_panel.text = dump(var)
end
Gui.on_text_changed(
@ -118,7 +108,7 @@ Gui.on_text_changed(
local element = event.element
local data = Gui.get_data(element)
update_dump(element, data)
update_dump(element, data, event.player)
end
)
@ -130,7 +120,7 @@ Gui.on_click(
local input_text_box = data.input_text_box
update_dump(input_text_box, data)
update_dump(input_text_box, data, event.player)
end
)