diff --git a/res/layouts/console.xml.lua b/res/layouts/console.xml.lua
index e5b72e6f..5a5a1101 100644
--- a/res/layouts/console.xml.lua
+++ b/res/layouts/console.xml.lua
@@ -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(
"",
diff --git a/res/layouts/templates/script_file.xml b/res/layouts/templates/script_file.xml
index 2df77df1..94e1afd2 100644
--- a/res/layouts/templates/script_file.xml
+++ b/res/layouts/templates/script_file.xml
@@ -1,10 +1,11 @@
-
+
diff --git a/res/modules/internal/scripts_registry.lua b/res/modules/internal/scripts_registry.lua
index 405dc15c..de685224 100644
--- a/res/modules/internal/scripts_registry.lua
+++ b/res/modules/internal/scripts_registry.lua
@@ -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
diff --git a/res/preload.json b/res/preload.json
index 394f0429..1cfd0747 100644
--- a/res/preload.json
+++ b/res/preload.json
@@ -34,7 +34,8 @@
"gui/play",
"gui/info",
"gui/world",
- "gui/hud"
+ "gui/hud",
+ "gui/entity"
],
"fonts": [
{
diff --git a/res/textures/gui/entity.png b/res/textures/gui/entity.png
new file mode 100644
index 00000000..53207e8b
Binary files /dev/null and b/res/textures/gui/entity.png differ
diff --git a/src/logic/scripting/lua/libs/libentity.cpp b/src/logic/scripting/lua/libs/libentity.cpp
index cecac6e9..28a7bd84 100644
--- a/src/logic/scripting/lua/libs/libentity.cpp
+++ b/src/logic/scripting/lua/libs/libentity.cpp
@@ -223,6 +223,18 @@ static int l_raycast(lua::State* L) {
return 0;
}
+static int l_reload_component(lua::State* L) {
+ std::string name = lua::require_string(L, 1);
+ size_t pos = name.find(':');
+ if (pos == std::string::npos) {
+ throw std::runtime_error("missing entry point");
+ }
+ auto filename = name.substr(0, pos + 1) + "scripts/components/" +
+ name.substr(pos + 1) + ".lua";
+ scripting::load_entity_component(name, filename, filename);
+ return 0;
+}
+
const luaL_Reg entitylib[] = {
{"exists", lua::wrap},
{"def_index", lua::wrap},
@@ -238,5 +250,6 @@ const luaL_Reg entitylib[] = {
{"get_all_in_box", lua::wrap},
{"get_all_in_radius", lua::wrap},
{"raycast", lua::wrap},
+ {"reload_component", lua::wrap},
{NULL, NULL}
};