Skip to content

Commit 6299555

Browse files
committed
add helper relation methods
1 parent 145bb49 commit 6299555

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/main/java/com/github/elebras1/flecs/Entity.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ public Entity childOf(Entity parent) {
101101
return this.childOf(parent.id());
102102
}
103103

104+
public Entity parent() {
105+
long parentId = this.target(FlecsConstants.EcsChildOf, 0);
106+
if (parentId != 0) {
107+
return new Entity(this.world, parentId);
108+
}
109+
return null;
110+
}
111+
104112
public Entity isA(long entityId) {
105113
return this.addRelation(FlecsConstants.EcsIsA, entityId);
106114
}
@@ -110,6 +118,24 @@ public Entity removeRelation(long relation, long target) {
110118
return this.remove(pair);
111119
}
112120

121+
public boolean hasRelation(long relation, long target) {
122+
long pair = flecs_h.ecs_make_pair(relation, target);
123+
return this.has(pair);
124+
}
125+
126+
public <T> T get(long relation, long target) {
127+
long pair = flecs_h.ecs_make_pair(relation, target);
128+
return this.get(pair);
129+
}
130+
131+
public Entity removeRelation(long relation) {
132+
return this.removeRelation(relation, FlecsConstants.EcsWildcard);
133+
}
134+
135+
public boolean hasRelation(long relation) {
136+
return this.hasRelation(relation, FlecsConstants.EcsWildcard);
137+
}
138+
113139
@SuppressWarnings("unchecked")
114140
public <T> Entity set(T data) {
115141
Class<T> componentClass = (Class<T>) data.getClass();

0 commit comments

Comments
 (0)