From bcbfdd50c7749619494541057cdcdbc005081ad5 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 13 Mar 2025 22:08:22 +0300 Subject: [PATCH] feat: running files with and block/item script reload --- res/layouts/console.xml | 18 +++++--- res/layouts/console.xml.lua | 81 ++++++++++++++++++++++++++++++++---- res/preload.json | 4 +- res/texts/en_US.txt | 2 + res/texts/ru_RU.txt | 5 +++ res/textures/gui/info.png | Bin 0 -> 129 bytes res/textures/gui/play.png | Bin 0 -> 130 bytes 7 files changed, 94 insertions(+), 16 deletions(-) create mode 100644 res/textures/gui/info.png create mode 100644 res/textures/gui/play.png diff --git a/res/layouts/console.xml b/res/layouts/console.xml index 6e5cc6c0..7b9bad3f 100644 --- a/res/layouts/console.xml +++ b/res/layouts/console.xml @@ -46,16 +46,19 @@ color="#FFFFFF80" size="16" pos="4,6" hover-color="#1080FF"> + size="60,16" padding="8" interval="8" color="0"> - + @@ -76,9 +79,12 @@ scroll-step='50' > - - + + + + + + %s: %s", + gui.str("Error at line %{0}"):gsub("%%{0}", line), message) + ) + return + end + local script_type, unit = xunpack(scripts_classification[current_file.filename]) + save_current_file() + + local func = function() + local stack_size = debug.count_frames() + xpcall(chunk, function(msg) __vc__error(msg, 1, 1, stack_size) end) + end + + if script_type == "block" then + func = function() block.reload_script(unit) end + elseif script_type == "item" then + func = function() item.reload_script(unit) end + end + local output = core.capture_output(func) + document.output:add( + string.format( + "", + output) + ) +end + function save_current_file() if not current_file.mutable then return @@ -161,14 +209,26 @@ function open_file_in_editor(filename, line, mutable) document.saveIcon.enabled = current_file.modified end +function clear_traceback() + local tb_list = document.traceback + tb_list:clear() + tb_list:add("") +end + +function clear_output() + local output = document.output + output:clear() + output:add("") +end + events.on("core:open_traceback", function(traceback_b64) local traceback = bjson.frombytes(base64.decode(traceback_b64)) modes:set('debug') + clear_traceback() + local tb_list = document.traceback local srcsize = tb_list.size - tb_list:clear() - tb_list:add("") for _, frame in ipairs(traceback.frames) do local callback = "" local framestr = "" @@ -322,10 +382,10 @@ end local function build_scripts_classification() for id, props in pairs(block.properties) do - scripts_classification[props["script-file"]] = "block" + scripts_classification[props["script-file"]] = {"block", block.name(id)} end for id, props in pairs(item.properties) do - scripts_classification[props["script-file"]] = "item" + scripts_classification[props["script-file"]] = {"item", item.name(id)} end end @@ -336,7 +396,7 @@ local function load_scripts_list() end for _, filename in ipairs(filenames) do - scripts_classification[filename] = "module" + scripts_classification[filename] = {"module"} end for _, packid in ipairs(packs) do @@ -364,6 +424,9 @@ function on_open(mode) build_files_list(filenames) document.editorContainer:setInterval(200, refresh_file_title) + + clear_traceback() + clear_output() elseif mode then modes:set(mode) end diff --git a/res/preload.json b/res/preload.json index 2b00a440..b5c24d09 100644 --- a/res/preload.json +++ b/res/preload.json @@ -30,7 +30,9 @@ "gui/block", "gui/item", "gui/file", - "gui/module" + "gui/module", + "gui/play", + "gui/info" ], "fonts": [ { diff --git a/res/texts/en_US.txt b/res/texts/en_US.txt index 732e2d66..57a6cb6b 100644 --- a/res/texts/en_US.txt +++ b/res/texts/en_US.txt @@ -11,7 +11,9 @@ world.delete-confirm=Do you want to delete world forever? world.generators.default=Default world.generators.flat=Flat +editor.info.tooltip=CTRL+S - Save\nCTRL+R - Run\nCTRL+Z - Undo\nCTRL+Y - Redo devtools.traceback=Traceback (most recent call first) +devtools.output=Output # Tooltips graphics.gamma.tooltip=Lighting brightness curve diff --git a/res/texts/ru_RU.txt b/res/texts/ru_RU.txt index 92eec3e8..65db4507 100644 --- a/res/texts/ru_RU.txt +++ b/res/texts/ru_RU.txt @@ -22,8 +22,13 @@ File=Файл Read only=Только для чтения Save=Сохранить Grant %{0} pack modification permission?=Выдать разрешение на модификацию пака %{0}? +Error at line %{0}=Ошибка на строке %{0} +Run=Запустить +editor.info.tooltip=CTRL+S - Сохранить\nCTRL+R - Запустить\nCTRL+Z - Отменить\nCTRL+Y - Повторить devtools.traceback=Стек вызовов (от последнего) +devtools.output=Вывод + error.pack-not-found=Не удалось найти пакет error.dependency-not-found=Используемая зависимость не найдена pack.remove-confirm=Удалить весь поставляемый паком/паками контент из мира (безвозвратно)? diff --git a/res/textures/gui/info.png b/res/textures/gui/info.png new file mode 100644 index 0000000000000000000000000000000000000000..a7bb70302217ff3fdee6aee497895e619c1bc946 GIT binary patch literal 129 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`9-c0aAr*6y6Bh_)PYsAsomiz?~t?9a4DEz?dPv;nF$Q7b_>GFekJL b7%?#9Y>@F(np>>}G?T&8)z4*}Q$iB}Mo1(m literal 0 HcmV?d00001 diff --git a/res/textures/gui/play.png b/res/textures/gui/play.png new file mode 100644 index 0000000000000000000000000000000000000000..2442b02ca5bd251e47abee9c7aa4683e07f74b1b GIT binary patch literal 130 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`o}Mm_Ar*6y6Bh_<2)Nqt-+^I~ zWMhMp_=F^ZIDLU+fxyIu^9qxg1ZO*@9A(<%c%|1ZiScHfg0;ZOKDSN6LN`5Uiu6{* bIsolx?3IW-_weFjprH(&u6{1-oD!M<@V_V< literal 0 HcmV?d00001