mirror of
https://github.com/Insality/druid.git
synced 2025-11-26 19:00:50 +01:00
Add create Druid collection script
This commit is contained in:
59
druid/editor_scripts/create_druid_collection.lua
Normal file
59
druid/editor_scripts/create_druid_collection.lua
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.create_druid_collection(selection)
|
||||||
|
local gui_filepath = editor.get(selection, "path")
|
||||||
|
print("Create Druid Collection for", gui_filepath)
|
||||||
|
|
||||||
|
local absolute_project_path = editor.external_file_attributes(".").path
|
||||||
|
local collection_resource_path = gui_filepath:gsub("%.gui$", ".collection")
|
||||||
|
local new_collection_absolute_path = absolute_project_path .. collection_resource_path
|
||||||
|
|
||||||
|
local filename = gui_filepath:match("([^/]+)%.gui$")
|
||||||
|
|
||||||
|
-- Check if file already exists
|
||||||
|
local f = io.open(new_collection_absolute_path, "r")
|
||||||
|
if f then
|
||||||
|
f:close()
|
||||||
|
print("Collection file already exists at " .. new_collection_absolute_path)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Template content
|
||||||
|
local template = [[name: "%s"
|
||||||
|
scale_along_z: 0
|
||||||
|
embedded_instances {
|
||||||
|
id: "go"
|
||||||
|
data: "components {\n"
|
||||||
|
" id: \"%s\"\n"
|
||||||
|
" component: \"%s\"\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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]
|
||||||
|
local content = string.format(template, filename, filename, gui_filepath)
|
||||||
|
|
||||||
|
-- Write file
|
||||||
|
local file, err = io.open(new_collection_absolute_path, "w")
|
||||||
|
if not file then
|
||||||
|
print("Error creating collection file:", err)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
file:write(content)
|
||||||
|
file:close()
|
||||||
|
|
||||||
|
print("Collection created: " .. collection_resource_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
local assign_layers = require("druid.editor_scripts.assign_layers")
|
local assign_layers = require("druid.editor_scripts.assign_layers")
|
||||||
local create_druid_widget = require("druid.editor_scripts.create_druid_widget")
|
local create_druid_widget = require("druid.editor_scripts.create_druid_widget")
|
||||||
local create_druid_gui_script = require("druid.editor_scripts.create_druid_gui_script")
|
local create_druid_gui_script = require("druid.editor_scripts.create_druid_gui_script")
|
||||||
|
local create_druid_collection = require("druid.editor_scripts.create_druid_collection")
|
||||||
local druid_settings = require("druid.editor_scripts.druid_settings")
|
local druid_settings = require("druid.editor_scripts.druid_settings")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@@ -65,6 +66,19 @@ function M.get_commands()
|
|||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
label = "[Druid] Create Druid Collection",
|
||||||
|
locations = { "Edit", "Assets" },
|
||||||
|
query = { selection = {type = "resource", cardinality = "one"} },
|
||||||
|
active = function(opts)
|
||||||
|
local path = editor.get(opts.selection, "path")
|
||||||
|
return path:match("%.gui$") ~= nil
|
||||||
|
end,
|
||||||
|
run = function(opts)
|
||||||
|
return create_druid_collection.create_druid_collection(opts.selection)
|
||||||
|
end
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
label = "[Druid] Settings",
|
label = "[Druid] Settings",
|
||||||
locations = { "Edit" },
|
locations = { "Edit" },
|
||||||
|
|||||||
Reference in New Issue
Block a user