Skip to content

Commit 7c2b6a2

Browse files
committed
fixing the last issues
1 parent e3658d7 commit 7c2b6a2

File tree

4 files changed

+3
-31
lines changed

4 files changed

+3
-31
lines changed

entity-component-system/src/main/java/com/iluwatar/Component.java

-19
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public abstract class Component {
3333

3434
private String name;
3535
private boolean isEnabled;
36-
private Entity parent;
3736

3837
/**
3938
* Default constructor for the component.
@@ -79,24 +78,6 @@ public void setEnabled(boolean isEnabled) {
7978
this.isEnabled = isEnabled;
8079
}
8180

82-
/**
83-
* Gets the parent entity of this component.
84-
*
85-
* @return the parent entity
86-
*/
87-
public Entity getParent() {
88-
return parent;
89-
}
90-
91-
/**
92-
* Sets the parent entity of this component.
93-
*
94-
* @param parent the parent entity to set
95-
*/
96-
public void setParent(Entity parent) {
97-
this.parent = parent;
98-
}
99-
10081
/**
10182
* Abstract method to update the component.
10283
* Subclasses must implement this method to define their update behavior.

entity-component-system/src/main/java/com/iluwatar/Entity.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Entity(String entityName) {
5656
name = entityName;
5757
components = new ArrayList<>();
5858
children = new ArrayList<>();
59-
final UUID entityId = UUID.randomUUID(); // Generates a unique UUID for this entity
59+
entityId = UUID.randomUUID(); // Generates a unique UUID for this entity
6060
transform = new TransformComponent(new float[] {0.0f, 0.0f, 0.0f}, new float[] {0.0f, 0.0f, 0.0f}, new float[] {1.0f, 1.0f, 1.0f});
6161
addComponent(transform);
6262

@@ -71,7 +71,6 @@ public void addComponent(Component component) {
7171
if (component != null) {
7272
components.add(component);
7373
component.setEnabled(isEnabled);
74-
component.setParent(this);
7574
}
7675
}
7776

entity-component-system/src/test/java/com/iluwatar/AppTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ void testFinalEntityStateAfterSimulation() {
106106
GameSystem gameSystem = new GameSystem();
107107
gameSystem.addEntity(entity1);
108108
gameSystem.addEntity(entity2);
109-
TransformComponent Testtransform = new TransformComponent(new float[]{5.0f, 0.0f, 0.0f},
109+
TransformComponent TestTransform = new TransformComponent(new float[]{5.0f, 0.0f, 0.0f},
110110
new float[]{0.0f, 45.0f, 0.0f}, new float[]{1.0f, 1.0f, 1.0f});
111-
entity1.setTransformComponent(Testtransform);
111+
entity1.setTransformComponent(TestTransform);
112112

113113
for (int i = 0; i < 10; i++) {
114114
gameSystem.update(1.0f / 60.0f);

entity-component-system/src/test/java/com/iluwatar/ComponentTest.java

-8
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,4 @@ void testComponentEnabled() {
5656
assertFalse(component.getEnabled(), "The component should be disabled.");
5757
}
5858

59-
@Test
60-
void testComponentParent() {
61-
Component component = new HealthComponent(100);
62-
Entity parentEntity = new Entity("ParentEntity");
63-
64-
component.setParent(parentEntity);
65-
assertEquals(parentEntity, component.getParent(), "The component's parent should be set correctly.");
66-
}
6759
}

0 commit comments

Comments
 (0)