mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Add my editor scripts for gui
This commit is contained in:
parent
80ad0dc3b5
commit
69dd2ce9e3
76
editor_scripts/gui_scheme.editor_script
Normal file
76
editor_scripts/gui_scheme.editor_script
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
--- @license MIT, Insality 2020
|
||||||
|
--- @source https://github.com/Insality/druid
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
|
||||||
|
local function ends_with(str, ending)
|
||||||
|
return ending == "" or str:sub(-#ending) == ending
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.get_commands()
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
label = "Print gui scheme",
|
||||||
|
|
||||||
|
locations = { "Outline" },
|
||||||
|
|
||||||
|
query = {
|
||||||
|
selection = {type = "outline", cardinality = "many"}
|
||||||
|
},
|
||||||
|
|
||||||
|
active = function(opts)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
|
||||||
|
run = function(opts)
|
||||||
|
print("local SCHEME = {")
|
||||||
|
|
||||||
|
for i = 1, #opts.selection do
|
||||||
|
local file = opts.selection[i]
|
||||||
|
if editor.can_get(file, "id") then
|
||||||
|
local id = editor.get(file, "id")
|
||||||
|
print("\t" .. string.upper(id) .. " = \"" .. id .. "\",")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
print("}")
|
||||||
|
print("")
|
||||||
|
end
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
label = "Assign layers",
|
||||||
|
|
||||||
|
locations = {"Edit"},
|
||||||
|
|
||||||
|
query = {
|
||||||
|
selection = {type = "resource", cardinality = "one"}
|
||||||
|
},
|
||||||
|
|
||||||
|
active = function(opts)
|
||||||
|
local path = editor.get(opts.selection, "path")
|
||||||
|
return ends_with(path, ".gui")
|
||||||
|
end,
|
||||||
|
|
||||||
|
run = function(opts)
|
||||||
|
local file = opts.selection
|
||||||
|
print("Run script for", editor.get(file, "path"))
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
action = "shell",
|
||||||
|
command = {
|
||||||
|
"bash",
|
||||||
|
"./editor_scripts/setup_layers.sh",
|
||||||
|
"." .. editor.get(file, "path")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return M
|
44
editor_scripts/setup_layers.py
Normal file
44
editor_scripts/setup_layers.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# @license MIT, Insality 2020
|
||||||
|
# @source https://github.com/Insality/druid
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import deftree
|
||||||
|
|
||||||
|
def main():
|
||||||
|
filename = sys.argv[1]
|
||||||
|
print("Auto setup layers for file", filename)
|
||||||
|
tree = deftree.parse(filename)
|
||||||
|
root = tree.get_root()
|
||||||
|
|
||||||
|
layers = []
|
||||||
|
for texture in root.iter_elements("textures"):
|
||||||
|
layers.append(texture.get_attribute("name").value)
|
||||||
|
|
||||||
|
for fonts in root.iter_elements("fonts"):
|
||||||
|
layers.append(fonts.get_attribute("name").value)
|
||||||
|
|
||||||
|
to_remove_layers = []
|
||||||
|
for layer in root.iter_elements("layers"):
|
||||||
|
to_remove_layers.append(layer)
|
||||||
|
for layer in to_remove_layers:
|
||||||
|
root.remove(layer)
|
||||||
|
|
||||||
|
for layer in layers:
|
||||||
|
new_layer = root.add_element("layers")
|
||||||
|
new_layer.add_attribute("name", layer)
|
||||||
|
|
||||||
|
for node in root.iter_elements("nodes"):
|
||||||
|
texture = node.get_attribute("texture")
|
||||||
|
font = node.get_attribute("font")
|
||||||
|
|
||||||
|
if texture:
|
||||||
|
layer = texture.value.split("/")[0]
|
||||||
|
node.set_attribute("layer", layer)
|
||||||
|
|
||||||
|
if font:
|
||||||
|
layer = font.value
|
||||||
|
node.set_attribute("layer", layer)
|
||||||
|
|
||||||
|
tree.write()
|
||||||
|
|
||||||
|
main()
|
8
editor_scripts/setup_layers.sh
Executable file
8
editor_scripts/setup_layers.sh
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# @license MIT, Insality 2020
|
||||||
|
# @source https://github.com/Insality/druid
|
||||||
|
|
||||||
|
echo "Run bash for $1"
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
|
||||||
|
/usr/local/bin/python3.7 $DIR/setup_layers.py $@
|
Loading…
x
Reference in New Issue
Block a user