feat: running files with and block/item script reload
This commit is contained in:
parent
5394f202a1
commit
bcbfdd50c7
@ -46,16 +46,19 @@
|
||||
color="#FFFFFF80" size="16" pos="4,6"
|
||||
hover-color="#1080FF"></image>
|
||||
<panel orientation="horizontal" gravity="top-right"
|
||||
size="36,16" padding="8" interval="8" color="0">
|
||||
size="60,16" padding="8" interval="8" color="0">
|
||||
<image id="saveIcon" src="gui/save" tooltip="@Save"
|
||||
enabled="false" interactive="true"
|
||||
hover-color="#1080FF"
|
||||
onclick="save_current_file()"
|
||||
color="#FFFFFF80" size="16"></image>
|
||||
<image id="syncIcon" src="gui/check_mark" tooltip="@Sync"
|
||||
<image id="infoIcon" src="gui/info" tooltip="@editor.info.tooltip"
|
||||
enabled="true" interactive="true"
|
||||
color="#FFFFFF80" size="16"></image>
|
||||
<image id="syncIcon" src="gui/play" tooltip="@Run"
|
||||
enabled="true" interactive="true"
|
||||
hover-color="#1080FF"
|
||||
onclick="save_current_file()"
|
||||
onclick="run_current_file()"
|
||||
color="#FFFFFF80" size="16"></image>
|
||||
</panel>
|
||||
<label id="title" pos="26,8"></label>
|
||||
@ -76,9 +79,12 @@
|
||||
scroll-step='50'
|
||||
></textbox>
|
||||
</container>
|
||||
<panel id="traceback" gravity="bottom-left"
|
||||
padding="4" color="#000000A0" max-length="170">
|
||||
</panel>
|
||||
<splitbox orientation="horizontal" split-pos="0.4">
|
||||
<panel id="traceback" padding="4" color="#000000A0">
|
||||
</panel>
|
||||
<panel id="output" padding="4" color="#000000A0">
|
||||
</panel>
|
||||
</splitbox>
|
||||
</splitbox>
|
||||
</splitbox>
|
||||
<textbox id='prompt'
|
||||
|
||||
@ -18,6 +18,13 @@ local current_file = {
|
||||
mutable = nil
|
||||
}
|
||||
|
||||
local function xunpack(t)
|
||||
if t == nil then
|
||||
return nil
|
||||
end
|
||||
return unpack(t)
|
||||
end
|
||||
|
||||
events.on("core:warning", function (wtype, text, traceback)
|
||||
local full = wtype..": "..text
|
||||
if table.has(warnings_all, full) then
|
||||
@ -55,12 +62,14 @@ events.on("core:error", function (msg, traceback)
|
||||
end)
|
||||
|
||||
local function find_mutable(filename)
|
||||
local saved = writeables[file.prefix(filename)]
|
||||
local packid = file.prefix(filename)
|
||||
if packid == "core" then
|
||||
return
|
||||
end
|
||||
local saved = writeables[packid]
|
||||
if saved then
|
||||
return saved..":"..file.path(filename)
|
||||
end
|
||||
|
||||
local packid = file.prefix(filename)
|
||||
local packinfo = pack.get_info(packid)
|
||||
if not packinfo then
|
||||
return
|
||||
@ -93,7 +102,8 @@ function build_files_list(filenames, selected)
|
||||
filename = filename:gsub(selected, "**"..selected.."**")
|
||||
end
|
||||
local parent = file.parent(filename)
|
||||
local script_type = scripts_classification[actual_filename] or "file"
|
||||
local script_type, unit = xunpack(scripts_classification[actual_filename])
|
||||
script_type = script_type or "file"
|
||||
files_list:add(gui.template("script_file", {
|
||||
path = parent .. (parent[#parent] == ':' and '' or '/'),
|
||||
name = file.name(filename),
|
||||
@ -116,6 +126,8 @@ end
|
||||
function on_control_combination(keycode)
|
||||
if keycode == input.keycode("s") then
|
||||
save_current_file()
|
||||
elseif keycode == input.keycode("r") then
|
||||
run_current_file()
|
||||
end
|
||||
end
|
||||
|
||||
@ -132,6 +144,42 @@ function unlock_access()
|
||||
)
|
||||
end
|
||||
|
||||
function run_current_file()
|
||||
if not current_file.filename then
|
||||
return
|
||||
end
|
||||
local chunk, err = loadstring(document.editor.text, current_file.filename)
|
||||
clear_output()
|
||||
if not chunk then
|
||||
local line, message = err:match(".*:(%d*): (.*)")
|
||||
document.output:add(
|
||||
string.format(
|
||||
"<label color='#FF3030' enabled='false' margin='2'>%s: %s</label>",
|
||||
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(
|
||||
"<label enabled='false' multiline='true' margin='2'>%s</label>",
|
||||
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("<label enabled='false' margin='2'>@devtools.traceback</label>")
|
||||
end
|
||||
|
||||
function clear_output()
|
||||
local output = document.output
|
||||
output:clear()
|
||||
output:add("<label enabled='false' margin='2'>@devtools.output</label>")
|
||||
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("<label enabled='false' margin='2'>@devtools.traceback</label>")
|
||||
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
|
||||
|
||||
@ -30,7 +30,9 @@
|
||||
"gui/block",
|
||||
"gui/item",
|
||||
"gui/file",
|
||||
"gui/module"
|
||||
"gui/module",
|
||||
"gui/play",
|
||||
"gui/info"
|
||||
],
|
||||
"fonts": [
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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=Удалить весь поставляемый паком/паками контент из мира (безвозвратно)?
|
||||
|
||||
BIN
res/textures/gui/info.png
Normal file
BIN
res/textures/gui/info.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 129 B |
BIN
res/textures/gui/play.png
Normal file
BIN
res/textures/gui/play.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 130 B |
Loading…
x
Reference in New Issue
Block a user