Files
Extension-Druid/druid/editor_scripts/druid.editor_script
Insality 138b2613ab Up
2025-11-11 01:36:18 +02:00

108 lines
3.2 KiB
Lua

local assign_layers = require("druid.editor_scripts.assign_layers")
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 druid_settings = require("druid.editor_scripts.druid_settings")
local asset_store = require("druid.editor_scripts.core.asset_store")
-- Reuse tip: copy the snippet below into another editor script to open a custom store.
-- asset_store.open({
-- store_url = "https://example.com/store.json",
-- info_url = "https://example.com/docs",
-- title = "My Library Store",
-- install_prefs_key = "my_lib.asset_install_folder",
-- default_install_folder = "/my_widgets",
-- })
local M = {}
local DEFAULT_WIDGET_TEMPLATE_PATH = "/druid/templates/widget_full.lua.template"
local DEFAULT_GUI_SCRIPT_TEMPLATE_PATH = "/druid/templates/druid.gui_script.template"
local DEFAULT_ASSET_INSTALL_FOLDER = "/widget"
---Define preferences schema
function M.get_prefs_schema()
return {
["druid.widget_template_path"] = editor.prefs.schema.string({
default = DEFAULT_WIDGET_TEMPLATE_PATH,
scope = editor.prefs.SCOPE.PROJECT
}),
["druid.gui_script_template_path"] = editor.prefs.schema.string({
default = DEFAULT_GUI_SCRIPT_TEMPLATE_PATH,
scope = editor.prefs.SCOPE.PROJECT
}),
["druid.asset_install_folder"] = editor.prefs.schema.string({
default = DEFAULT_ASSET_INSTALL_FOLDER,
scope = editor.prefs.SCOPE.PROJECT
})
}
end
---Define the editor commands
function M.get_commands()
return {
{
label = "[Druid] Assign Layers",
locations = { "Edit" },
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 assign_layers.assign_layers(opts.selection)
end
},
{
label = "[Druid] Create Druid Widget",
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_widget.create_druid_widget(opts.selection)
end
},
{
label = "[Druid] Create Druid GUI Script",
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_gui_script.create_druid_gui_script(opts.selection)
end
},
{
label = "[Druid] Asset Store",
locations = { "Edit" },
run = function()
return asset_store.open({
store_url = "https://insality.github.io/core/druid_widget_store.json",
info_url = "https://github.com/Insality/core/blob/main/druid_widget_store.md",
title = "Druid Asset Store",
install_prefs_key = "druid.asset_install_folder",
default_install_folder = DEFAULT_ASSET_INSTALL_FOLDER,
})
end
},
{
label = "[Druid] Settings",
locations = { "Edit" },
run = function()
return druid_settings.open_settings()
end
}
}
end
return M