feat: component script reloading

This commit is contained in:
MihailRis
2025-03-16 22:03:37 +03:00
parent 267aebe7bd
commit 4761c520d5
6 changed files with 42 additions and 22 deletions
+16 -11
View File
@@ -96,10 +96,15 @@ function build_files_list(filenames, selected)
end
local parent = file.parent(filename)
local info = registry.get_info(actual_filename)
local icon = "file"
if info then
icon = info.type == "component" and "entity" or info.type
end
files_list:add(gui.template("script_file", {
path = parent .. (parent[#parent] == ':' and '' or '/'),
name = file.name(filename),
type = info and info.type or "file",
icon = icon,
unit = info and info.unit or '',
filename = actual_filename
}))
end
@@ -153,6 +158,7 @@ function run_current_file()
end
local info = registry.get_info(current_file.filename)
local script_type = info and info.type or "file"
local unit = info and info.unit
save_current_file()
local func = function()
@@ -160,16 +166,15 @@ function run_current_file()
xpcall(chunk, function(msg) __vc__error(msg, 1, 1, stack_size) end)
end
if script_type == "block" then
func = function() block.reload_script(info.unit) end
elseif script_type == "item" then
func = function() item.reload_script(info.unit) end
elseif script_type == "world" then
func = function() world.reload_script(info.unit) end
elseif script_type == "hud" then
func = function() hud.reload_script(info.unit) end
end
local output = core.capture_output(func)
local funcs = {
block = block.reload_script,
item = item.reload_script,
world = world.reload_script,
hud = hud.reload_script,
component = entities.reload_component,
}
func = funcs[script_type] or func
local output = core.capture_output(function() func(unit) end)
document.output:add(
string.format(
"<label enabled='false' multiline='true' margin='2'>%s</label>",
+2 -1
View File
@@ -1,10 +1,11 @@
<container size="18">
<image src="gui/%{type}" size="16"></image>
<image src="gui/%{icon}" size="16"></image>
<label hover-color='#30A0FF'
pos="20,2"
interactive="true"
onclick='open_file_in_editor("%{filename}")'
markup='md'
tooltip='%{unit}'
sizefunc="-1,-1">
[#FFFFFF80]%{path}[#FFFFFFFF]%{name}
</label>
+9 -9
View File
@@ -7,19 +7,19 @@ local function collect_components(dirname, dest)
if file.ext(filename) == "lua" then
table.insert(dest, filename)
export.classification[filename] = {
type="entity",
unit=file.prefix(filename)..":"..file.name(filename)
type="component",
unit=file.prefix(filename)..":"..file.stem(filename)
}
end
end
end
end
local function collect_scripts(dirname, dest)
local function collect_scripts(dirname, dest, ismodule)
if file.isdir(dirname) then
local files = file.list(dirname)
for i, filename in ipairs(files) do
if file.name(filename) == "components" then
if file.name(filename) == "components" and not ismodule then
collect_components(filename, dest)
elseif file.isdir(filename) then
collect_scripts(filename, dest)
@@ -33,18 +33,18 @@ end
local function load_scripts_list()
local packs = pack.get_installed()
for _, packid in ipairs(packs) do
collect_scripts(packid..":modules", export.filenames)
collect_scripts(packid..":modules", export.filenames, true)
end
for _, filename in ipairs(export.filenames) do
export.classification[filename] = {
type="module",
unit=file.prefix(filename)..":"..filename:sub(filename:find("/")+1)
unit=file.join(file.parent(file.prefix(filename)..":"..
filename:sub(filename:find("/")+1)),
file.stem(filename))
}
end
for _, packid in ipairs(packs) do
collect_scripts(packid..":scripts", export.filenames)
collect_scripts(packid..":scripts", export.filenames, false)
end
end
+2 -1
View File
@@ -34,7 +34,8 @@
"gui/play",
"gui/info",
"gui/world",
"gui/hud"
"gui/hud",
"gui/entity"
],
"fonts": [
{
Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B