diff --git a/CONTRIBUTING b/CONTRIBUTING index c9bdbe5..8430af8 100644 --- a/CONTRIBUTING +++ b/CONTRIBUTING @@ -18,7 +18,7 @@ Please, open PR against the `develop` branch. Very nice to have an issue, which You fix should contains only changes, which are related to the issue. Also please keep the code style the same! -Thanks <3 +❤️ Thanks ❤️ ## Update Documentation @@ -48,3 +48,20 @@ On your repo fork: - Test the example by running the game - Create a pull request to the `develop` branch + +## Add or Update Unit Tests + +The unit tests was updated to cover more Druid's source code. So now I have more examples how to run and check some parts of the code. + +In case you face issue and want to reproduce it, you also can starts from the unit tests: + +All tests placed in the `/test/tests` directory. + +To run tests you need to set the bootstrap collection to `/test/test.collection` and run it. + +So the flow will be the similar: + +- Create a new branch for your changes +- Make your changes and commit them +- Push your changes to your fork +- Create a pull request to the Druid repository `develop` branch diff --git a/druid/component.lua b/druid/component.lua index 1515b4b..f92a9b0 100644 --- a/druid/component.lua +++ b/druid/component.lua @@ -107,9 +107,16 @@ end ---Set current component nodes, returned from `gui.clone_tree` function. ----@param nodes table +---@param nodes table|node|string|nil The nodes table from gui.clone_tree or prefab node to use for clone or node id to clone ---@return druid.component function M:set_nodes(nodes) + if type(nodes) == "string" then + nodes = self:get_node(nodes) + end + if type(nodes) == "userdata" then + nodes = gui.clone_tree(nodes) --[[@as table]] + end + self._meta.nodes = nodes return self end @@ -132,7 +139,7 @@ end ---Get Druid instance for inner component creation. ---@param template string|nil ----@param nodes table|nil +---@param nodes table|node|string|nil The nodes table from gui.clone_tree or prefab node to use for clone or node id to clone ---@return druid.instance function M:get_druid(template, nodes) local druid_instance = setmetatable({ @@ -396,7 +403,11 @@ function M.create_widget(self, widget_class, context) default_input_priority = const.PRIORITY_INPUT, _is_input_priority_changed = true, -- Default true for sort once time after GUI init } - instance._meta = { + + -- I'll hide a meta fields under metatable to hide this tables from pprint output + -- cause it's leads to recursive pprint's from (druid = self) + -- Wish this to be better, since it can reduce a memory usage + instance._meta = setmetatable({}, { __index = { druid = self, template = "", nodes = nil, @@ -406,7 +417,7 @@ function M.create_widget(self, widget_class, context) children = {}, parent = type(context) ~= "userdata" and context or nil, instance_class = widget_class - } + }}) -- Register if instance._meta.parent then diff --git a/druid/druid.lua b/druid/druid.lua index b5f0d55..e9b161a 100644 --- a/druid/druid.lua +++ b/druid/druid.lua @@ -33,8 +33,16 @@ end ---@param name string Module name ---@param module table Lua table with component function M.register(name, module) - druid_instance["new_" .. name] = function(self, ...) - return druid_instance.new(self, module, ...) + local is_custom_component = getmetatable(module) ~= nil + if is_custom_component then + druid_instance["new_" .. name] = function(self, ...) + return druid_instance.new(self, module, ...) + end + else + -- Just for some compatability. But better to use direct druid_instance:new_widget(module, ...) function + druid_instance["new_" .. name] = function(self, template, nodes, ...) + return druid_instance.new_widget(self, module, template, nodes, ...) + end end end diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index 457b647..08c8f33 100755 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -494,13 +494,6 @@ end function M:new_widget(widget, template, nodes, ...) local instance = create_widget(self, widget) - if type(nodes) == "string" then - nodes = gui.get_node(nodes) - end - if type(nodes) == "userdata" then - nodes = gui.clone_tree(nodes) --[[@as table]] - end - instance.druid = instance:get_druid(template, nodes) if instance.init then diff --git a/example/examples/widgets/examples_list.lua b/example/examples/widgets/examples_list.lua index 77a8867..0376eb2 100644 --- a/example/examples/widgets/examples_list.lua +++ b/example/examples/widgets/examples_list.lua @@ -16,7 +16,7 @@ function M.get_examples() information_text_id = "ui_example_widget_properties_panel_description", template = "properties_panel", root = "properties_panel/root", - code_url = "example/examples/widgets/properties_panel/properties_panel.lua", + code_url = "example/examples/widgets/examples_list.lua", widget_class = require("druid.widget.properties_panel.properties_panel"), on_create = function(instance, output_list) ---@cast instance druid.widget.properties_panel @@ -96,7 +96,7 @@ function M.get_examples() information_text_id = "ui_example_widget_property_input_description", template = "property_input", root = "property_input/root", - code_url = "druid/widget/properties_panel/properties/property_input.lua", + code_url = "example/examples/widgets/examples_list.lua", widget_class = require("druid.widget.properties_panel.properties.property_input"), }, { diff --git a/example/examples/widgets/go_widgets/go_widget.collection b/example/examples/widgets/go_widgets/go_with_widget.collection similarity index 90% rename from example/examples/widgets/go_widgets/go_widget.collection rename to example/examples/widgets/go_widgets/go_with_widget.collection index a0a9327..6179f83 100644 --- a/example/examples/widgets/go_widgets/go_widget.collection +++ b/example/examples/widgets/go_widgets/go_with_widget.collection @@ -7,12 +7,8 @@ embedded_instances { " component: \"/example/examples/widgets/go_widgets/go_widget.gui\"\n" "}\n" "components {\n" - " id: \"go_bindings\"\n" - " component: \"/example/examples/widgets/go_widgets/go_widget.script\"\n" - "}\n" - "components {\n" - " id: \"druid\"\n" - " component: \"/druid/druid.script\"\n" + " id: \"go_with_widget\"\n" + " component: \"/example/examples/widgets/go_widgets/go_with_widget.script\"\n" "}\n" "embedded_components {\n" " id: \"sprite\"\n" diff --git a/example/examples/widgets/go_widgets/go_widget.script b/example/examples/widgets/go_widgets/go_with_widget.script similarity index 96% rename from example/examples/widgets/go_widgets/go_widget.script rename to example/examples/widgets/go_widgets/go_with_widget.script index a65a4bd..bf0c537 100644 --- a/example/examples/widgets/go_widgets/go_widget.script +++ b/example/examples/widgets/go_widgets/go_with_widget.script @@ -1,6 +1,6 @@ local panthera = require("panthera.panthera") -local animation = require("example.examples.widgets.go_widgets.go_bindings_panthera") +local animation = require("example.examples.widgets.go_widgets.go_with_widget_panthera") local druid = require("druid.druid") local widget = require("example.examples.widgets.go_widgets.go_widget") @@ -8,6 +8,7 @@ local widget = require("example.examples.widgets.go_widgets.go_widget") function init(self) local gui_url = msg.url(nil, nil, "go_widget") self.go_widget = druid.get_widget(widget, gui_url) + self.go_widget:play_animation() self.go_widget:set_position(go.get_position()) diff --git a/example/examples/widgets/go_widgets/go_bindings_panthera.lua b/example/examples/widgets/go_widgets/go_with_widget_panthera.lua similarity index 99% rename from example/examples/widgets/go_widgets/go_bindings_panthera.lua rename to example/examples/widgets/go_widgets/go_with_widget_panthera.lua index 948de2e..5bb75ba 100644 --- a/example/examples/widgets/go_widgets/go_bindings_panthera.lua +++ b/example/examples/widgets/go_widgets/go_with_widget_panthera.lua @@ -89,7 +89,7 @@ return { fps = 60, gizmo_steps = { }, - gui_path = "/example/examples/widgets/go_widgets/go_widget.collection", + gui_path = "/example/examples/widgets/go_widgets/go_with_widget.collection", layers = { }, settings = { @@ -104,4 +104,4 @@ return { format = "json", type = "animation_editor", version = 1, -} \ No newline at end of file +}