Awesome!
I just pushed some little tweaks to my parser so it works with editor_scripts. They don’t have access to vmath
, so the parser can’t convert transform data to vectors and quats, so they just stay as normal tables with x, y, z, w fields. They also don’t have socket
, which I was using to check the time it took to parse, so I just took that out. And I removed or commented out all the debug print statements.
Here’s a stupid-simple little editor_script to count the number of embedded game objects in a collection file:
(Put it in a folder with the parser module and double-check the require path.)
Code
local M = {}
local parser = require "editor_scripts/collection_parser"
local commands = {
{
label = "Count Embedded Instances",
locations = {"Assets", "Outline"},
query = {
selection = { type = "resource", cardinality = "many" }
},
run = function(opts)
for i,node_id in ipairs(opts.selection) do
local path = editor.get(node_id, "path")
path = string.sub(path, 2) -- Cut off "/" prefix.
local extension = string.match(path, "^.*%.(.*)$")
if path and extension == "collection" then
local file, err = io.open(path, "r")
if not file then
print(err)
else
local data = parser.decodeFile(file, path)
file:close()
if data then
local inst = data.embedded_instances
local count = inst and #inst or 0
print("", count .. " embedded_instances in " .. path .. ".")
end
end
end
end
end
}
}
function M.get_commands()
print("Collection Parser Test Extension Loaded.")
return commands
end
return M