From ba1ab07e0d2e539eb2482a43e1e00b6bfdd905b4 Mon Sep 17 00:00:00 2001 From: Insality Date: Thu, 29 Aug 2024 09:28:54 +0300 Subject: [PATCH] Update new component template, replace component name with M as module name --- druid/editor_scripts/component.lua_template | 8 ++++---- druid/editor_scripts/create_druid_component.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/druid/editor_scripts/component.lua_template b/druid/editor_scripts/component.lua_template index d50db11..457284f 100644 --- a/druid/editor_scripts/component.lua_template +++ b/druid/editor_scripts/component.lua_template @@ -9,7 +9,7 @@ local component = require("druid.component") ---@class {COMPONENT_TYPE}: druid.base_component{COMPONENT_ANNOTATIONS} ---@field druid druid_instance -local {COMPONENT_NAME} = component.create("{COMPONENT_TYPE}") +local M = component.create("{COMPONENT_TYPE}") local SCHEME = { {SCHEME_LIST} @@ -18,15 +18,15 @@ local SCHEME = { ---@param template string ---@param nodes table -function {COMPONENT_NAME}:init(template, nodes) +function M:init(template, nodes) self:set_template(template) self:set_nodes(nodes) self.druid = self:get_druid(){COMPONENT_DEFINE} end -function {COMPONENT_NAME}:on_remove() +function M:on_remove() end {COMPONENT_FUNCTIONS} -return {COMPONENT_NAME} +return M diff --git a/druid/editor_scripts/create_druid_component.py b/druid/editor_scripts/create_druid_component.py index 054bfa3..b88c1a1 100644 --- a/druid/editor_scripts/create_druid_component.py +++ b/druid/editor_scripts/create_druid_component.py @@ -32,7 +32,7 @@ def process_component(node_name, component_name): if node_name.startswith("button"): 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 M:_on_{0}()\n\tprint(\"Click on {0}\")\nend\n\n".format(node_name) component_define += "\n\tself.{0} = self.druid:new_button(SCHEME.{1}, self._on_{0})".format(node_name, get_id(node_name)) if node_name.startswith("text"): @@ -66,7 +66,7 @@ def process_component(node_name, component_name): component_annotations += "\n---@field {0} druid.slider".format(node_name) component_define += "\n--TODO: Replace slider end position. It should be only vertical or horizontal" component_define += "\n\tself.{0} = self.druid:new_slider(SCHEME.{1}, vmath.vector3(100, 0, 0), self._on_{0}_change)".format(node_name, get_id(node_name)) - component_functions += "\nfunction {1}:_on_{0}_change(value)\n\tprint(\"Slider change:\", value)\nend\n\n".format(node_name, component_name) + component_functions += "\nfunction M:_on_{0}_change(value)\n\tprint(\"Slider change:\", value)\nend\n\n".format(node_name) if node_name.startswith("progress"): component_annotations += "\n---@field {0} druid.progress".format(node_name) @@ -75,7 +75,7 @@ def process_component(node_name, component_name): if node_name.startswith("timer"): component_annotations += "\n---@field {0} druid.timer".format(node_name) component_define += "\n\tself.{0} = self.druid:new_timer(SCHEME.{1}, 59, 0, self._on_{0}_end)".format(node_name, get_id(node_name)) - component_functions += "\nfunction {1}:_on_{0}_end()\n\tprint(\"Timer {0} trigger\")\nend\n\n".format(node_name, component_name) + component_functions += "\nfunction M:_on_{0}_end()\n\tprint(\"Timer {0} trigger\")\nend\n\n".format(node_name) def main():