-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameContextFactory.java
More file actions
35 lines (29 loc) · 1014 Bytes
/
Copy pathGameContextFactory.java
File metadata and controls
35 lines (29 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import core.Context;
import core.Entity;
import core.Relation;
public final class GameContextFactory {
private GameContextFactory() {
}
public static Context create(Entity<? extends Relation> world) {
Context context = new Context();
registerEntity(context, world);
for (Relation child : world.getChildren()) {
if (child instanceof Entity<?> childEntity) {
registerEntity(context, childEntity);
context.getGraph().addRelation(
world.getId(),
world.getLabel(),
childEntity.getId(),
childEntity.getLabel()
);
} else {
context.getEntities().add(child);
}
}
return context;
}
private static void registerEntity(Context context, Entity<?> entity) {
context.getEntities().add(entity);
context.getGraph().addEntity(entity.getId(), entity.getLabel());
}
}