Splendid!
Pretty sad we cannot yet modify collection files. I tried to make an editor script that automatizes creating collection of levels, and catched this error:
ERROR:EXT: Pack levels's "run" in /main/collection_packer.editor_script failed:
ERROR:EXT: No method in multimethod 'transaction-action->txs' for dispatch value: ["set" :editor.collection/CollectionNode "text"]
The code:
local M = {}
M.target_file = nil
function M.get_commands()
return {
{
label = 'Pack levels',
locations = {'Assets'},
query = {
selection = { type = 'resource', cardinality = 'many' }
},
active = function(opts)
for _, node_id in ipairs(opts.selection) do
if not M.is_collection(node_id) then
return false
end
end
return true
end,
run = M.pack_collections,
},
{
label = 'Set as levels collection',
locations = {'Assets'},
query = {
selection = { type = 'resource', cardinality = 'one' }
},
active = function(opts)
return M.is_collection(opts.selection)
end,
run = function(opts)
local path = editor.get(opts.selection, 'path')
print('Pack target is set to '..path)
M.target_file = opts.selection
end,
}
}
end
function M.is_collection(node_id)
local path = editor.get(node_id, 'path')
return path:find('.collection', nil, true)
end
local function make_embedded_factory(path, exclude)
return [[embedded_instances {
id: "]]..path..[["
data: "embedded_components {\n"
" id: \"collectionproxy\"\n"
" type: \"collectionproxy\"\n"
" data: \"collection: \\\"]]..path..[[\\\"\\n"
"exclude: ]]..tostring(exclude)..[[\\n"
"\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
]]
end
function M.pack_collections(opts)
assert(M.target_file, 'No target file specified. Use "Set as levels collection" first')
local content = [[name: "pack"
scale_along_z: 0
]]
for _, node_id in ipairs(opts.selection) do
filename = editor.get(node_id, 'path')
content = content .. make_embedded_factory(filename, false)
end
return {
{
action = 'set',
node_id = M.target_file,
property = 'text',
value = content,
},
}
end
return M