Skip to content

Commit

Permalink
Fixed entity pointers, added an entity pointer test component
Browse files Browse the repository at this point in the history
  • Loading branch information
Flafla2 committed Nov 27, 2013
1 parent dfa4734 commit ad03634
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void apply()
{
wizards.get(x).setComponentFields();
}
Entity after = editor.getMap().getEntityList().getEntityWithUUID(currentEntity);
Entity after = editor.getMap().getEntityList().getEntityWithUUID(currentEntity).clone();
editor.executeOperation(new OperationEditEntity(editor,before,after));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void execute() {
{
boolean setSelected = before.getUUID().equals(editor.getSelectedEntity());
after.updatePos();
editor.getMap().getEntityList().set(x, after);
editor.getMap().getEntityList().get(x).transpose(after);
if(setSelected)
editor.setSelectedEntity(after.getUUID());
return;
Expand All @@ -46,7 +46,7 @@ public void undo() {
{
boolean setSelected = after.getUUID().equals(editor.getSelectedEntity());
before.updatePos();
editor.getMap().getEntityList().set(x, before);
editor.getMap().getEntityList().get(x).transpose(before);
if(setSelected)
editor.setSelectedEntity(before.getUUID());
return;
Expand Down
16 changes: 16 additions & 0 deletions Remote2D/src/com/remote/remote2d/engine/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ public Entity clone()
return clone;
}

/**
* Takes all the attributes of the given entity and transposes it to this
* entity.
* @param e Entity to transpose over to this one.
*/
public void transpose(Entity e)
{
R2DTypeCollection compile = new R2DTypeCollection("Entity Clone");
e.saveR2DFile(compile);
loadR2DFile(compile);

components.clear();
for(Component c : e.components)
addComponent(c.clone());
}

@Override
public boolean equals(Object o)
{
Expand Down
13 changes: 12 additions & 1 deletion Remote2D/src/com/remote/remote2d/engine/entity/EntityList.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,14 @@ public void tick(int i, int j, int k)
}

/**
* Sets the entity at the given index to the given entity
* Sets the entity at the given index to the given entity.
* The higher the index, the later the Entity will be rendered,
* which means that an entity with a higher index will be "on top" of
* entities with a lower index.
*
* Also keep in mind that set() does NOT retain pointers to other entities.
* For this reason set() should almost ONLY be used by the engine. In almost
* all cases {@link Entity#transpose(Entity)} is recommended.
* @param i Index to set
* @param e Entity to set at the given index
*/
Expand All @@ -152,6 +159,10 @@ public int indexOf(Entity e)
}

/**
* Gets the entity at the given index. The higher the index, the later the
* Entity will be rendered, which means that an entity with a higher index will
* be "on top" of entities with a lower index.
*
* @param index Index to get from
* @return The Entity at the given index of the list.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.remote.remote2d.engine.Remote2DGame;
import com.remote.remote2d.engine.entity.InsertableComponentList;
import com.remote.remote2d.engine.io.R2DFileManager;
import com.remote.remote2d.extras.test.entity.ComponentEntityPointerTest;
import com.remote.remote2d.extras.test.entity.ComponentPlayer;
import com.remote.remote2d.extras.test.entity.ComponentTopDownPlayer;
import com.remote.remote2d.extras.test.gui.GuiMainMenu;
Expand All @@ -23,6 +24,7 @@ public void initGame() {
Remote2D.guiList.push(new GuiMainMenu());
InsertableComponentList.addInsertableComponent("Player", ComponentPlayer.class);
InsertableComponentList.addInsertableComponent("Top Down Player", ComponentTopDownPlayer.class);
InsertableComponentList.addInsertableComponent("Entity Pointer Test", ComponentEntityPointerTest.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.remote.remote2d.extras.test.entity;

import com.remote.remote2d.engine.art.Fonts;
import com.remote.remote2d.engine.entity.Entity;
import com.remote.remote2d.engine.entity.component.Component;
import com.remote.remote2d.engine.logic.Vector2;

public class ComponentEntityPointerTest extends Component {

public Entity testEntity;

@Override
public void tick(int i, int j, int k) {

}

@Override
public void renderBefore(boolean editor, float interpolation) {

}

@Override
public void onEntitySpawn() {

}

@Override
public void renderAfter(boolean editor, float interpolation) {
Vector2 pos = entity.getPosGlobal(interpolation);
if(entity != null)
Fonts.get("Arial").drawString(testEntity.name, pos.x, pos.y, 20, 0x000000);
}

@Override
public void init() {

}

@Override
public void apply() {

}

}

0 comments on commit ad03634

Please sign in to comment.