From 29d8c4bbb879e94fc66b594d1754d3ab35240dfc Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 19 Nov 2024 07:32:03 +0300 Subject: [PATCH] add Lua traceback inspector (WIP) && add chat prototype --- res/layouts/console.xml | 38 +++++++- res/layouts/console.xml.lua | 120 ++++++++++++++++++++++++-- res/layouts/templates/problem.xml | 3 +- res/layouts/templates/stack_frame.xml | 3 + res/scripts/stdcmd.lua | 8 ++ res/texts/en_US.txt | 2 + res/texts/ru_RU.txt | 8 ++ 7 files changed, 174 insertions(+), 8 deletions(-) create mode 100644 res/layouts/templates/stack_frame.xml diff --git a/res/layouts/console.xml b/res/layouts/console.xml index bae396bf..96d01191 100644 --- a/res/layouts/console.xml +++ b/res/layouts/console.xml @@ -1,5 +1,18 @@ - + + + + + + + + + + + + + + + - + @devtools.traceback") + for _, frame in ipairs(traceback.frames) do + local callback = "" + local framestr = "" + if frame.what == "C" then + framestr = "C/C++ " + else + framestr = frame.source..":"..tostring(frame.currentline).." " + if file.exists(frame.source) then + callback = "local source = file.read('"..frame.source.."') ".. + "document.editor.text = source ".. + "document.editor.focused = true ".. + "time.post_runnable(function() document.editor.caret = document.editor:linePos(".. + tostring(frame.currentline-1)..") end)" + else + callback = "document.editor.text = 'Could not open source file'" + end + callback = callback.." document.title.text = gui.str('File')..' - " + ..frame.source.."'" + end + if frame.name then + framestr = framestr.."("..tostring(frame.name)..")" + end + local color = "#FFFFFF" + if frame.source:starts_with("core:") then + color = "#C0D0C5" + end + tb_list:add(gui.template("stack_frame", { + location=framestr, + color=color, + callback=callback + })) + end + tb_list.size = srcsize +end) + function setup_variables() local pid = hud.get_player() local x,y,z = player.get_pos(pid) @@ -56,10 +128,19 @@ function add_to_history(text) end function submit(text) + text = text:trim() add_to_history(text) + + if console_mode == "chat" then + if not text:starts_with("/") then + text = "chat "..string.escape(text) + else + text = text:sub(2) + end + end + setup_variables() - text = text:trim() local name for s in text:gmatch("%S+") do name = s @@ -84,6 +165,35 @@ function submit(text) document.prompt.focused = true end -function on_open() - document.prompt.focused = true +function set_mode(mode) + local show_prompt = mode == 'chat' or mode == 'console' + + document.title.text = "" + document.editorContainer.visible = mode == 'debug' + document.logContainer.visible = mode ~= 'debug' + + if mode == 'debug' then + document.root.color = {16, 18, 20, 220} + else + document.root.color = {0, 0, 0, 128} + end + + document.traceback.visible = mode == 'debug' + document.prompt.visible = show_prompt + if show_prompt then + document.prompt.focused = true + end + console_mode = mode +end + +function on_open() + if modes == nil then + modes = RadioGroup({ + chat=document.s_chat, + console=document.s_console, + debug=document.s_debug + }, function (mode) + set_mode(mode) + end, "console") + end end diff --git a/res/layouts/templates/problem.xml b/res/layouts/templates/problem.xml index 0dfb2794..ea70022a 100644 --- a/res/layouts/templates/problem.xml +++ b/res/layouts/templates/problem.xml @@ -1,4 +1,5 @@ - + + %{location} + diff --git a/res/scripts/stdcmd.lua b/res/scripts/stdcmd.lua index 98609688..ccb65a71 100644 --- a/res/scripts/stdcmd.lua +++ b/res/scripts/stdcmd.lua @@ -256,6 +256,14 @@ console.add_command( end ) +console.add_command( + "chat text:str", + "Send chat message", + function (args, kwargs) + console.log("[you] "..args[1]) + end +) + console.cheats = { "blocks.fill", "tp", diff --git a/res/texts/en_US.txt b/res/texts/en_US.txt index 9c9cc2a5..c19fe00a 100644 --- a/res/texts/en_US.txt +++ b/res/texts/en_US.txt @@ -11,6 +11,8 @@ world.delete-confirm=Do you want to delete world forever? world.generators.default=Default world.generators.flat=Flat +devtools.traceback=Traceback (most recent call first) + # Tooltips graphics.gamma.tooltip=Lighting brightness curve graphics.backlight.tooltip=Backlight to prevent total darkness diff --git a/res/texts/ru_RU.txt b/res/texts/ru_RU.txt index 74717336..346c5993 100644 --- a/res/texts/ru_RU.txt +++ b/res/texts/ru_RU.txt @@ -12,7 +12,15 @@ Dependencies=Зависимости Description=Описание Converting world...=Выполняется конвертация мира... Unlimited=Неограниченно +Chat=Чат +Console=Консоль +Log=Лог +Problems=Проблемы +Monitor=Мониторинг +Debug=Отладка +File=Файл +devtools.traceback=Стек вызовов (от последнего) error.pack-not-found=Не удалось найти пакет error.dependency-not-found=Используемая зависимость не найдена pack.remove-confirm=Удалить весь поставляемый паком/паками контент из мира (безвозвратно)?