This commit is contained in:
Insality 2025-04-19 22:25:58 +03:00
parent 4cb16de782
commit c7b11562d5
8 changed files with 51 additions and 25 deletions

View File

@ -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

View File

@ -107,9 +107,16 @@ end
---Set current component nodes, returned from `gui.clone_tree` function.
---@param nodes table<hash, node>
---@param nodes table<hash, node>|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<hash, node>]]
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<hash, node>|nil
---@param nodes table<hash, node>|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

View File

@ -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

View File

@ -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<hash, node>]]
end
instance.druid = instance:get_druid(template, nodes)
if instance.init then

View File

@ -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"),
},
{

View File

@ -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"

View File

@ -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())

View File

@ -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 = {