Skip to content

Commit b5598d8

Browse files
authored
Merge pull request #96 from GsLogiMaker:feature/add-entity-clear-method
Add `GFEntity.clear` method
2 parents b58ccbb + 9990172 commit b5598d8

File tree

9 files changed

+91
-5
lines changed

9 files changed

+91
-5
lines changed

cpp/src/doc_classes/GFComponent.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<class name="GFComponent" inherits="GFRegisterableEntity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
2+
<class name="GFComponent" inherits="GFRegisterableEntity"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
34
<brief_description>
45
A reference to a Glecs component from a [GFWorld] that is attatached to an entity.
56
</brief_description>
@@ -76,6 +77,12 @@
7677
Overrides [method GFEntity.addv].
7778
</description>
7879
</method>
80+
<method name="clear">
81+
<return type="GFComponent" />
82+
<description>
83+
Overrides [method GFEntity.clear].
84+
</description>
85+
</method>
7986
<method name="emit">
8087
<return type="GFComponent" />
8188
<param index="0" name="entity" type="Variant" />

cpp/src/doc_classes/GFEntity.xml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<class name="GFEntity" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
2+
<class name="GFEntity" inherits="RefCounted"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
34
<brief_description>
45
A reference to an entity from a [GFWorld].
56
</brief_description>
@@ -114,6 +115,24 @@
114115
This method returns [code]self[/code] for chaining.
115116
</description>
116117
</method>
118+
<method name="clear">
119+
<return type="GFEntity" />
120+
<description>
121+
Removes all added entities, pairs, and components.
122+
[codeblock]
123+
var fruit:= GFEntity.new()
124+
var edible:= GFEntity.new()
125+
var apple:= GFEntity.new()
126+
apple.add(fruit)
127+
apple.add(edible)
128+
129+
apple.has(fruit) and apple.has(edible) # true
130+
apple.clear()
131+
apple.has(fruit) or apple.has(edible) # false
132+
[/codeblock]
133+
This method returns [code]self[/code] for chaining.
134+
</description>
135+
</method>
117136
<method name="delete" qualifiers="const">
118137
<return type="void" />
119138
<description>
@@ -251,6 +270,13 @@
251270
[/codeblock]
252271
</description>
253272
</method>
273+
<method name="get_target_for" qualifiers="const">
274+
<return type="GFEntity" />
275+
<param index="0" name="relationship" type="Variant" />
276+
<param index="1" name="index" type="int" default="0" />
277+
<description>
278+
</description>
279+
</method>
254280
<method name="get_world" qualifiers="const">
255281
<return type="GFWorld" />
256282
<description>
@@ -333,6 +359,12 @@
333359
See [method inherit].
334360
</description>
335361
</method>
362+
<method name="is_owner_of" qualifiers="const">
363+
<return type="bool" />
364+
<param index="0" name="_unnamed_arg0" type="Variant" />
365+
<description>
366+
</description>
367+
</method>
336368
<method name="is_pair" qualifiers="const">
337369
<return type="bool" />
338370
<description>

cpp/src/doc_classes/GFModule.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<class name="GFModule" inherits="GFRegisterableEntity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
2+
<class name="GFModule" inherits="GFRegisterableEntity"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
34
<brief_description>
45
</brief_description>
56
<description>
@@ -60,6 +61,12 @@
6061
Overrides [method GFEntity.addv].
6162
</description>
6263
</method>
64+
<method name="clear">
65+
<return type="GFModule" />
66+
<description>
67+
Overrides [method GFEntity.clear].
68+
</description>
69+
</method>
6370
<method name="emit">
6471
<return type="GFModule" />
6572
<param index="0" name="entity" type="Variant" />

cpp/src/doc_classes/GFPair.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<class name="GFPair" inherits="GFEntity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
2+
<class name="GFPair" inherits="GFEntity"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
34
<brief_description>
45
A reference to a pair of entity IDs.
56
</brief_description>
@@ -62,6 +63,12 @@
6263
Overrides [method GFEntity.addv].
6364
</description>
6465
</method>
66+
<method name="clear">
67+
<return type="GFPair" />
68+
<description>
69+
Overrides [method GFEntity.clear].
70+
</description>
71+
</method>
6572
<method name="emit">
6673
<return type="GFPair" />
6774
<param index="0" name="entity" type="Variant" />

cpp/src/doc_classes/GFRegisterableEntity.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
<description>
6868
</description>
6969
</method>
70+
<method name="clear">
71+
<return type="GFRegisterableEntity" />
72+
<description>
73+
</description>
74+
</method>
7075
<method name="emit">
7176
<return type="GFRegisterableEntity" />
7277
<param index="0" name="entity" type="Variant" />

cpp/src/doc_classes/GFTag.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<class name="GFTag" inherits="GFRegisterableEntity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
2+
<class name="GFTag" inherits="GFRegisterableEntity"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
34
<brief_description>
45
A reference to an entity with no data.
56
</brief_description>
@@ -63,6 +64,12 @@
6364
Overrides [method GFEntity.addv].
6465
</description>
6566
</method>
67+
<method name="clear">
68+
<return type="GFTag" />
69+
<description>
70+
Overrides [method GFEntity.clear].
71+
</description>
72+
</method>
6673
<method name="emit">
6774
<return type="GFTag" />
6875
<param index="0" name="entity" type="Variant" />

cpp/src/entity.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ Ref<GFEntity> GFEntity::set_pairv (
394394
return Ref(this);
395395
}
396396

397+
Ref<GFEntity> GFEntity::clear() {
398+
ecs_clear(get_world()->raw(), get_id());
399+
return this;
400+
}
401+
397402
void GFEntity::delete_() const {
398403
ecs_delete(get_world()->raw(), get_id());
399404
}

cpp/src/entity.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Ref<Self> add_child(const Variant v0) { return GFEntity::add_child(v0); } \
1919
Ref<Self> add_sibling(const Variant v0) { return GFEntity::add_sibling(v0); } \
2020
Ref<Self> add_componentv(const Variant v0, const Variant v1) { return GFEntity::add_componentv(v0, v1); } \
21+
Ref<Self> clear() { return GFEntity::clear(); } \
2122
Ref<Self> set_componentv(const Variant v0, const Variant v1) { return GFEntity::set_componentv(v0, v1); } \
2223
Ref<Self> set_pairv(const Variant v0, const Variant v1, const Variant v2) { return GFEntity::set_pairv(v0, v1, v2); } \
2324
Ref<Self> add_pairv(const Variant v0, const Variant v1, const Variant v2) { return GFEntity::add_pairv(v0, v1, v2); } \
@@ -36,6 +37,7 @@
3637
godot::ClassDB::bind_method(D_METHOD("add_child", "entity"), &Self::add_child); \
3738
godot::ClassDB::bind_method(D_METHOD("add_sibling", "entity"), &Self::add_sibling); \
3839
godot::ClassDB::bind_method(D_METHOD("addv", "component", "members"), &Self::add_componentv, Array()); \
40+
godot::ClassDB::bind_method(D_METHOD("clear"), &Self::clear); \
3941
godot::ClassDB::bind_method(D_METHOD("setv", "component", "members"), &Self::set_componentv); \
4042
godot::ClassDB::bind_method(D_METHOD("add_pairv", "first", "second", "members"), &Self::add_pairv, Array()); \
4143
godot::ClassDB::bind_method(D_METHOD("set_pairv", "first", "second", "members"), &Self::set_pairv); \
@@ -130,6 +132,7 @@ namespace godot {
130132
Ref<GFEntity> set_name(const String);
131133
Ref<GFEntity> set_parent(const Variant entity);
132134

135+
Ref<GFEntity> clear();
133136
void delete_() const;
134137

135138
Ref<GFEntity> get_child(const String) const;

unittests/test_entities.gd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,19 @@ func test_is_owner_of():
364364
assert_true(voyager.has(pos), "Expected voyager to have pos")
365365
assert_true(voyager.has(rot), "Expected voyager to have rot")
366366

367+
func test_clear():
368+
var tag:= GFEntity.new_in_world(world).set_name("tag")
369+
370+
var e:= GFEntity.new_in_world(world) \
371+
.set_name("Entity") \
372+
.add(tag)
373+
374+
assert_true(e.has(tag))
375+
376+
e.clear()
377+
378+
assert_false(e.has(tag))
379+
367380
#endregion
368381

369382
#region Classes

0 commit comments

Comments
 (0)