add core:internal/scripts_registry module
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
local export = {}
|
||||
|
||||
local function collect_components(dirname, dest)
|
||||
if file.isdir(dirname) then
|
||||
local files = file.list(dirname)
|
||||
for i, filename in ipairs(files) do
|
||||
if file.ext(filename) == "lua" then
|
||||
table.insert(dest, filename)
|
||||
export.classification[filename] = {
|
||||
type="entity",
|
||||
unit=file.prefix(filename)..":"..file.name(filename)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function collect_scripts(dirname, dest)
|
||||
if file.isdir(dirname) then
|
||||
local files = file.list(dirname)
|
||||
for i, filename in ipairs(files) do
|
||||
if file.name(filename) == "components" then
|
||||
collect_components(filename, dest)
|
||||
elseif file.isdir(filename) then
|
||||
collect_scripts(filename, dest)
|
||||
elseif file.ext(filename) == "lua" then
|
||||
table.insert(dest, filename)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function load_scripts_list()
|
||||
local packs = pack.get_installed()
|
||||
for _, packid in ipairs(packs) do
|
||||
collect_scripts(packid..":modules", export.filenames)
|
||||
end
|
||||
|
||||
for _, filename in ipairs(export.filenames) do
|
||||
export.classification[filename] = {
|
||||
type="module",
|
||||
unit=file.prefix(filename)..":"..filename:sub(filename:find("/")+1)
|
||||
}
|
||||
end
|
||||
|
||||
for _, packid in ipairs(packs) do
|
||||
collect_scripts(packid..":scripts", export.filenames)
|
||||
end
|
||||
end
|
||||
|
||||
function export.build_classification()
|
||||
local classification = {}
|
||||
for id, props in pairs(block.properties) do
|
||||
classification[props["script-file"]] = {type="block", unit=block.name(id)}
|
||||
end
|
||||
for id, props in pairs(item.properties) do
|
||||
classification[props["script-file"]] = {type="item", unit=item.name(id)}
|
||||
end
|
||||
local packs = pack.get_installed()
|
||||
for _, packid in ipairs(packs) do
|
||||
classification[packid..":scripts/world.lua"] = {type="world", unit=packid}
|
||||
classification[packid..":scripts/hud.lua"] = {type="hud", unit=packid}
|
||||
end
|
||||
export.classification = classification
|
||||
export.filenames = {}
|
||||
|
||||
load_scripts_list()
|
||||
end
|
||||
|
||||
function export.get_info(filename)
|
||||
return export.classification[filename]
|
||||
end
|
||||
|
||||
return export
|
||||
Reference in New Issue
Block a user