Skip to content

Commit c7b1156

Browse files
committed
Update
1 parent 4cb16de commit c7b1156

File tree

8 files changed

+51
-25
lines changed

8 files changed

+51
-25
lines changed

CONTRIBUTING

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Please, open PR against the `develop` branch. Very nice to have an issue, which
1818

1919
You fix should contains only changes, which are related to the issue. Also please keep the code style the same!
2020

21-
Thanks <3
21+
❤️ Thanks ❤️
2222

2323
## Update Documentation
2424

@@ -48,3 +48,20 @@ On your repo fork:
4848
- Test the example by running the game
4949
- Create a pull request to the `develop` branch
5050

51+
52+
## Add or Update Unit Tests
53+
54+
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.
55+
56+
In case you face issue and want to reproduce it, you also can starts from the unit tests:
57+
58+
All tests placed in the `/test/tests` directory.
59+
60+
To run tests you need to set the bootstrap collection to `/test/test.collection` and run it.
61+
62+
So the flow will be the similar:
63+
64+
- Create a new branch for your changes
65+
- Make your changes and commit them
66+
- Push your changes to your fork
67+
- Create a pull request to the Druid repository `develop` branch

druid/component.lua

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,16 @@ end
107107

108108

109109
---Set current component nodes, returned from `gui.clone_tree` function.
110-
---@param nodes table<hash, node>
110+
---@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
111111
---@return druid.component
112112
function M:set_nodes(nodes)
113+
if type(nodes) == "string" then
114+
nodes = self:get_node(nodes)
115+
end
116+
if type(nodes) == "userdata" then
117+
nodes = gui.clone_tree(nodes) --[[@as table<hash, node>]]
118+
end
119+
113120
self._meta.nodes = nodes
114121
return self
115122
end
@@ -132,7 +139,7 @@ end
132139

133140
---Get Druid instance for inner component creation.
134141
---@param template string|nil
135-
---@param nodes table<hash, node>|nil
142+
---@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
136143
---@return druid.instance
137144
function M:get_druid(template, nodes)
138145
local druid_instance = setmetatable({
@@ -396,7 +403,11 @@ function M.create_widget(self, widget_class, context)
396403
default_input_priority = const.PRIORITY_INPUT,
397404
_is_input_priority_changed = true, -- Default true for sort once time after GUI init
398405
}
399-
instance._meta = {
406+
407+
-- I'll hide a meta fields under metatable to hide this tables from pprint output
408+
-- cause it's leads to recursive pprint's from (druid = self)
409+
-- Wish this to be better, since it can reduce a memory usage
410+
instance._meta = setmetatable({}, { __index = {
400411
druid = self,
401412
template = "",
402413
nodes = nil,
@@ -406,7 +417,7 @@ function M.create_widget(self, widget_class, context)
406417
children = {},
407418
parent = type(context) ~= "userdata" and context or nil,
408419
instance_class = widget_class
409-
}
420+
}})
410421

411422
-- Register
412423
if instance._meta.parent then

druid/druid.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,16 @@ end
3333
---@param name string Module name
3434
---@param module table Lua table with component
3535
function M.register(name, module)
36-
druid_instance["new_" .. name] = function(self, ...)
37-
return druid_instance.new(self, module, ...)
36+
local is_custom_component = getmetatable(module) ~= nil
37+
if is_custom_component then
38+
druid_instance["new_" .. name] = function(self, ...)
39+
return druid_instance.new(self, module, ...)
40+
end
41+
else
42+
-- Just for some compatability. But better to use direct druid_instance:new_widget(module, ...) function
43+
druid_instance["new_" .. name] = function(self, template, nodes, ...)
44+
return druid_instance.new_widget(self, module, template, nodes, ...)
45+
end
3846
end
3947
end
4048

druid/system/druid_instance.lua

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,6 @@ end
494494
function M:new_widget(widget, template, nodes, ...)
495495
local instance = create_widget(self, widget)
496496

497-
if type(nodes) == "string" then
498-
nodes = gui.get_node(nodes)
499-
end
500-
if type(nodes) == "userdata" then
501-
nodes = gui.clone_tree(nodes) --[[@as table<hash, node>]]
502-
end
503-
504497
instance.druid = instance:get_druid(template, nodes)
505498

506499
if instance.init then

example/examples/widgets/examples_list.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function M.get_examples()
1616
information_text_id = "ui_example_widget_properties_panel_description",
1717
template = "properties_panel",
1818
root = "properties_panel/root",
19-
code_url = "example/examples/widgets/properties_panel/properties_panel.lua",
19+
code_url = "example/examples/widgets/examples_list.lua",
2020
widget_class = require("druid.widget.properties_panel.properties_panel"),
2121
on_create = function(instance, output_list)
2222
---@cast instance druid.widget.properties_panel
@@ -96,7 +96,7 @@ function M.get_examples()
9696
information_text_id = "ui_example_widget_property_input_description",
9797
template = "property_input",
9898
root = "property_input/root",
99-
code_url = "druid/widget/properties_panel/properties/property_input.lua",
99+
code_url = "example/examples/widgets/examples_list.lua",
100100
widget_class = require("druid.widget.properties_panel.properties.property_input"),
101101
},
102102
{

example/examples/widgets/go_widgets/go_widget.collection renamed to example/examples/widgets/go_widgets/go_with_widget.collection

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ embedded_instances {
77
" component: \"/example/examples/widgets/go_widgets/go_widget.gui\"\n"
88
"}\n"
99
"components {\n"
10-
" id: \"go_bindings\"\n"
11-
" component: \"/example/examples/widgets/go_widgets/go_widget.script\"\n"
12-
"}\n"
13-
"components {\n"
14-
" id: \"druid\"\n"
15-
" component: \"/druid/druid.script\"\n"
10+
" id: \"go_with_widget\"\n"
11+
" component: \"/example/examples/widgets/go_widgets/go_with_widget.script\"\n"
1612
"}\n"
1713
"embedded_components {\n"
1814
" id: \"sprite\"\n"

example/examples/widgets/go_widgets/go_widget.script renamed to example/examples/widgets/go_widgets/go_with_widget.script

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
local panthera = require("panthera.panthera")
22

3-
local animation = require("example.examples.widgets.go_widgets.go_bindings_panthera")
3+
local animation = require("example.examples.widgets.go_widgets.go_with_widget_panthera")
44

55
local druid = require("druid.druid")
66
local widget = require("example.examples.widgets.go_widgets.go_widget")
77

88
function init(self)
99
local gui_url = msg.url(nil, nil, "go_widget")
1010
self.go_widget = druid.get_widget(widget, gui_url)
11+
1112
self.go_widget:play_animation()
1213
self.go_widget:set_position(go.get_position())
1314

example/examples/widgets/go_widgets/go_bindings_panthera.lua renamed to example/examples/widgets/go_widgets/go_with_widget_panthera.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ return {
8989
fps = 60,
9090
gizmo_steps = {
9191
},
92-
gui_path = "/example/examples/widgets/go_widgets/go_widget.collection",
92+
gui_path = "/example/examples/widgets/go_widgets/go_with_widget.collection",
9393
layers = {
9494
},
9595
settings = {
@@ -104,4 +104,4 @@ return {
104104
format = "json",
105105
type = "animation_editor",
106106
version = 1,
107-
}
107+
}

0 commit comments

Comments
 (0)