-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solve #119 Add script for create custom component
- Loading branch information
Showing
7 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ nodes { | |
nodes { | ||
position { | ||
x: 0.0 | ||
y: 2.0 | ||
y: 3.0 | ||
z: 0.0 | ||
w: 1.0 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- For component interest functions | ||
--- see https://github.com/Insality/druid/blob/develop/docs_md/02-creating_custom_components.md | ||
|
||
local component = require("druid.component") | ||
|
||
---@class {COMPONENT_TYPE} : druid.base_component | ||
local {COMPONENT_NAME} = component.create("{COMPONENT_TYPE}") | ||
|
||
local SCHEME = { | ||
{SCHEME_LIST} | ||
} | ||
|
||
|
||
--- Create this component via druid:new({COMPONENT_NAME}, template, nodes) | ||
---@param template string | ||
---@param nodes table<hash, node> | ||
function {COMPONENT_NAME}:init(template, nodes) | ||
self:set_template(template) | ||
self:set_nodes(nodes) | ||
self.root = self:get_node(SCHEME.ROOT) | ||
self.druid = self:get_druid() | ||
end | ||
|
||
|
||
function {COMPONENT_NAME}:on_remove() | ||
end | ||
|
||
|
||
return {COMPONENT_NAME} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# @license MIT, Insality 2021 | ||
# @source https://github.com/Insality/druid | ||
|
||
import os | ||
import sys | ||
import deftree | ||
|
||
current_filepath = os.path.abspath(os.path.dirname(__file__)) | ||
TEMPLATE_FILE = open(current_filepath + "/component_template.lua", "r") | ||
|
||
def to_camel_case(snake_str): | ||
components = snake_str.split('_') | ||
return ''.join(x.title() for x in components[0:]) | ||
|
||
def main(): | ||
filename = sys.argv[1] | ||
print("Create Druid component from gui file", filename) | ||
tree = deftree.parse(filename) | ||
root = tree.get_root() | ||
|
||
output_directory = os.path.dirname(filename) | ||
output_filename = os.path.splitext(os.path.basename(filename))[0] | ||
|
||
output_full_path = os.path.join(output_directory, output_filename + ".lua") | ||
is_already_exists = os.path.exists(output_full_path) | ||
if is_already_exists: | ||
print("Error: The file is already exists") | ||
print("File:", output_full_path) | ||
return | ||
|
||
component_name = to_camel_case(output_filename) | ||
component_type = output_filename | ||
scheme_list = [] | ||
# Gather nodes from GUI scene | ||
for node in root.iter_elements("nodes"): | ||
name = node.get_attribute("id").value | ||
scheme_list.append("\t" + name.upper() + " = \"" + name + "\"") | ||
|
||
filedata = TEMPLATE_FILE.read() | ||
filedata = filedata.replace("{COMPONENT_NAME}", component_name) | ||
filedata = filedata.replace("{COMPONENT_TYPE}", component_type) | ||
filedata = filedata.replace("{SCHEME_LIST}", ",\n".join(scheme_list)) | ||
|
||
output_file = open(output_full_path, "w") | ||
output_file.write(filedata) | ||
output_file.close() | ||
print("Success: The file is created") | ||
print("File:", output_full_path) | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
# @license MIT, Insality 2022 | ||
# @source https://github.com/Insality/druid | ||
|
||
echo "Run bash for $1" | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
is_defree_installed=$(pip3 list --disable-pip-version-check | grep -E "deftree") | ||
if [ -z "$is_defree_installed" ]; then | ||
echo "The python deftree is not installed. Installing..." | ||
pip3 install deftree | ||
fi | ||
|
||
python3 $DIR/create_druid_component.py $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters