mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 18:37:44 +02:00
Update generate component script
This commit is contained in:
parent
6bb5ee59a8
commit
760946765c
@ -8,18 +8,19 @@
|
|||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
---@class {COMPONENT_TYPE}: druid.base_component{COMPONENT_ANNOTATIONS}
|
---@class {COMPONENT_TYPE}: druid.base_component{COMPONENT_ANNOTATIONS}
|
||||||
|
---@field druid druid_instance
|
||||||
local {COMPONENT_NAME} = component.create("{COMPONENT_TYPE}")
|
local {COMPONENT_NAME} = component.create("{COMPONENT_TYPE}")
|
||||||
|
|
||||||
local SCHEME = {
|
local SCHEME = {
|
||||||
{SCHEME_LIST}
|
{SCHEME_LIST}
|
||||||
}
|
}
|
||||||
{COMPONENT_FUNCTIONS}
|
|
||||||
|
|
||||||
---@param template string
|
---@param template string
|
||||||
---@param nodes table<hash, node>
|
---@param nodes table<hash, node>
|
||||||
function {COMPONENT_NAME}:init(template, nodes)
|
function {COMPONENT_NAME}:init(template, nodes)
|
||||||
self:set_template(template)
|
self:set_template(template)
|
||||||
self:set_nodes(nodes)
|
self:set_nodes(nodes)
|
||||||
self.root = self:get_node(SCHEME.ROOT)
|
|
||||||
self.druid = self:get_druid(){COMPONENT_DEFINE}
|
self.druid = self:get_druid(){COMPONENT_DEFINE}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -27,5 +28,5 @@ end
|
|||||||
function {COMPONENT_NAME}:on_remove()
|
function {COMPONENT_NAME}:on_remove()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
{COMPONENT_FUNCTIONS}
|
||||||
return {COMPONENT_NAME}
|
return {COMPONENT_NAME}
|
||||||
|
@ -6,7 +6,7 @@ import sys
|
|||||||
import deftree
|
import deftree
|
||||||
|
|
||||||
current_filepath = os.path.abspath(os.path.dirname(__file__))
|
current_filepath = os.path.abspath(os.path.dirname(__file__))
|
||||||
TEMPLATE_FILE = open(current_filepath + "/component.lua_template", "r")
|
TEMPLATE_PATH = current_filepath + "/component.lua_template"
|
||||||
|
|
||||||
component_annotations = ""
|
component_annotations = ""
|
||||||
component_functions = ""
|
component_functions = ""
|
||||||
@ -26,6 +26,10 @@ def process_component(node_name, component_name):
|
|||||||
global component_functions
|
global component_functions
|
||||||
global component_define
|
global component_define
|
||||||
|
|
||||||
|
if node_name == "root":
|
||||||
|
component_annotations += "\n---@field root node"
|
||||||
|
component_define += "\n\tself.root = self:get_node(SCHEME.ROOT)"
|
||||||
|
|
||||||
if node_name.startswith("button"):
|
if node_name.startswith("button"):
|
||||||
component_annotations += "\n---@field {0} druid.button".format(node_name)
|
component_annotations += "\n---@field {0} druid.button".format(node_name)
|
||||||
component_functions += "\nfunction {1}:_on_{0}()\n\tprint(\"Click on {0}\")\nend\n\n".format(node_name, component_name)
|
component_functions += "\nfunction {1}:_on_{0}()\n\tprint(\"Click on {0}\")\nend\n\n".format(node_name, component_name)
|
||||||
@ -112,7 +116,10 @@ def main():
|
|||||||
if len(component_define) > 2:
|
if len(component_define) > 2:
|
||||||
component_define = "\n" + component_define
|
component_define = "\n" + component_define
|
||||||
|
|
||||||
filedata = TEMPLATE_FILE.read()
|
template_file = open(TEMPLATE_PATH, "r")
|
||||||
|
filedata = template_file.read()
|
||||||
|
template_file.close()
|
||||||
|
|
||||||
filedata = filedata.replace("{COMPONENT_NAME}", component_name)
|
filedata = filedata.replace("{COMPONENT_NAME}", component_name)
|
||||||
filedata = filedata.replace("{COMPONENT_TYPE}", component_type)
|
filedata = filedata.replace("{COMPONENT_TYPE}", component_type)
|
||||||
filedata = filedata.replace("{COMPONENT_PATH}", component_require_path)
|
filedata = filedata.replace("{COMPONENT_PATH}", component_require_path)
|
||||||
@ -124,7 +131,9 @@ def main():
|
|||||||
output_file = open(output_full_path, "w")
|
output_file = open(output_full_path, "w")
|
||||||
output_file.write(filedata)
|
output_file.write(filedata)
|
||||||
output_file.close()
|
output_file.close()
|
||||||
|
|
||||||
print("Success: The file is created")
|
print("Success: The file is created")
|
||||||
print("File:", output_full_path)
|
print("File:", output_full_path)
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user