forked from MovingBlocks/Terasology
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'entitySystemPrototype' of https://github.com/immortius/…
…Terasology into entitySystemPrototype
- Loading branch information
Showing
18 changed files
with
744 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
package org.terasology.entitySystem; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* @author Immortius <[email protected]> | ||
*/ | ||
public abstract class AbstractComponent implements Component { | ||
|
||
public String getName() { | ||
int index = getClass().getSimpleName().lastIndexOf("Component"); | ||
if (index != -1) { | ||
return getClass().getSimpleName().substring(0, index).toLowerCase(); | ||
String className = getClass().getSimpleName().toLowerCase(); | ||
|
||
if (className.endsWith("component")) { | ||
return className.substring(0, className.lastIndexOf("component")); | ||
} | ||
|
||
return className; | ||
} | ||
|
||
public Component clone() { | ||
try { | ||
return (Component) super.clone(); | ||
} catch (CloneNotSupportedException e) { | ||
// this shouldn't happen | ||
throw new InternalError(); | ||
} | ||
return getClass().getSimpleName().toLowerCase(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.terasology.entitySystem; | ||
|
||
import com.google.common.base.Objects; | ||
|
||
/** | ||
* @todo javadoc | ||
*/ | ||
public abstract class AbstractPrefab implements Prefab { | ||
|
||
private String name; | ||
|
||
protected AbstractPrefab(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Prefab clone() { | ||
try { | ||
return (Prefab) super.clone(); | ||
} catch (CloneNotSupportedException e) { | ||
// this shouldn't happen | ||
throw new InternalError(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o instanceof Prefab) { | ||
return Objects.equal(name, ((Prefab) o).getName()); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Prefab(" + name + "){ components: " + this.listOwnComponents() + ", parents: " + this.getParents() + " }"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
* | ||
* @author Immortius <[email protected]> | ||
*/ | ||
public interface Component extends Persistable { | ||
public interface Component extends Persistable, Cloneable { | ||
public String getName(); | ||
|
||
public Component clone(); | ||
} |
118 changes: 62 additions & 56 deletions
118
...rg/terasology/entitySystem/PrefabRef.java → src/org/terasology/entitySystem/Prefab.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,62 @@ | ||
package org.terasology.entitySystem; | ||
|
||
/** | ||
* An entity prefab describes the recipe for creating an entity. | ||
* Like an entity it groups a collection of components. | ||
* @author Immortius <[email protected]> | ||
*/ | ||
public interface PrefabRef { | ||
/** | ||
* @return The identifier for this prefab | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* | ||
* @param newName | ||
* @throws IllegalArgumentException If the new name is already in use | ||
*/ | ||
void rename(String newName); | ||
|
||
/** | ||
* | ||
* @param componentClass | ||
* @param <T> | ||
* @return The requested component, or null if the entity doesn't have a component of this class | ||
*/ | ||
<T extends Component> T getComponent(Class<T> componentClass); | ||
|
||
/** | ||
* Adds a component to this entity. If the entity already has a component of the same class it is replaced. | ||
* @param component | ||
*/ | ||
<T extends Component> T addComponent(T component); | ||
|
||
/** | ||
* @param componentClass | ||
*/ | ||
void removeComponent(Class<? extends Component> componentClass); | ||
|
||
/** | ||
* @param component | ||
*/ | ||
void saveComponent(Component component); | ||
|
||
/** | ||
* Iterates over all the components | ||
* @return | ||
*/ | ||
Iterable<Component> iterateComponents(); | ||
|
||
/** | ||
* Removes this prefab from the prefab manager | ||
*/ | ||
void destroy(); | ||
|
||
} | ||
package org.terasology.entitySystem; | ||
|
||
/** | ||
* An entity prefab describes the recipe for creating an entity. | ||
* Like an entity it groups a collection of components. | ||
* | ||
* @author Immortius <[email protected]> | ||
*/ | ||
public interface Prefab extends Cloneable{ | ||
|
||
/** | ||
* @return The identifier for this prefab | ||
*/ | ||
public String getName(); | ||
|
||
/** | ||
* | ||
* @param componentClass | ||
* @param <T> | ||
* @return The requested component, or null if the entity doesn't have a component of this class | ||
*/ | ||
public <T extends Component> T getComponent(Class<T> componentClass); | ||
|
||
/** | ||
* Adds a component to this entity. If the entity already has a component of the same class it is replaced. | ||
* @param component | ||
*/ | ||
public <T extends Component> T setComponent(T component); | ||
|
||
/** | ||
* @param componentClass | ||
*/ | ||
public void removeComponent(Class<? extends Component> componentClass); | ||
|
||
/** | ||
* Iterates over all the components | ||
* @return | ||
*/ | ||
public Iterable<Component> listComponents(); | ||
|
||
/** | ||
* Iterate only over OWN components, excluding inheritance. | ||
* Required for proper serializing | ||
* | ||
* @return | ||
*/ | ||
public Iterable<Component> listOwnComponents(); | ||
|
||
/** | ||
* Return parents prefabs | ||
* | ||
* @return | ||
*/ | ||
public Iterable<Prefab> getParents(); | ||
|
||
public void addParent(Prefab parent); | ||
|
||
public void removeParent(Prefab parent); | ||
|
||
public Prefab clone(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,29 @@ | ||
package org.terasology.entitySystem; | ||
|
||
/** | ||
* | ||
* @todo Write javadoc | ||
* @author Immortius <[email protected]> | ||
*/ | ||
public interface PrefabManager { | ||
|
||
/** | ||
* @param name | ||
* @return A new PrefabRef | ||
* @throws IllegalArgumentException when name is already in use | ||
*/ | ||
PrefabRef create(String name); | ||
public Prefab createPrefab(String name); | ||
|
||
PrefabRef get(String name); | ||
public Prefab getPrefab(String name); | ||
|
||
boolean exists(String name); | ||
|
||
/** | ||
* @param oldName | ||
* @param name | ||
* @return A new PrefabRef with the new name | ||
* @throws IllegalArgumentException if either the oldName isn't in use or the new name is already in use | ||
*/ | ||
PrefabRef rename(String oldName, String name); | ||
|
||
void destroy(String name); | ||
|
||
<T extends Component> T getComponent(String name, Class<T> componentClass); | ||
void addComponent(String name, Component component); | ||
<T extends Component> void removeComponent(String name, Class<T> componentClass); | ||
void saveComponent(String name, Component component); | ||
public boolean exists(String name); | ||
|
||
public Prefab registerPrefab(Prefab prefab); | ||
|
||
public Iterable<Prefab> listPrefabs(); | ||
|
||
public void removePrefab(String name); | ||
|
||
public <T extends Component> T getComponent(String name, Class<T> componentClass); | ||
|
||
public <T extends Component> T setComponent(String name, T component); | ||
|
||
|
||
public <T extends Component> void removeComponent(String name, Class<T> componentClass); | ||
|
||
} |
Oops, something went wrong.