From 69dd2ce9e3508bd744d0bbdbaea78619dbaab231 Mon Sep 17 00:00:00 2001 From: Insality Date: Thu, 18 Jun 2020 01:58:42 +0300 Subject: [PATCH] Add my editor scripts for gui --- editor_scripts/gui_scheme.editor_script | 76 +++++++++++++++++++++++++ editor_scripts/setup_layers.py | 44 ++++++++++++++ editor_scripts/setup_layers.sh | 8 +++ 3 files changed, 128 insertions(+) create mode 100644 editor_scripts/gui_scheme.editor_script create mode 100644 editor_scripts/setup_layers.py create mode 100755 editor_scripts/setup_layers.sh diff --git a/editor_scripts/gui_scheme.editor_script b/editor_scripts/gui_scheme.editor_script new file mode 100644 index 0000000..aa7235f --- /dev/null +++ b/editor_scripts/gui_scheme.editor_script @@ -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 diff --git a/editor_scripts/setup_layers.py b/editor_scripts/setup_layers.py new file mode 100644 index 0000000..94b1374 --- /dev/null +++ b/editor_scripts/setup_layers.py @@ -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() \ No newline at end of file diff --git a/editor_scripts/setup_layers.sh b/editor_scripts/setup_layers.sh new file mode 100755 index 0000000..f2191c4 --- /dev/null +++ b/editor_scripts/setup_layers.sh @@ -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 $@ \ No newline at end of file