Skip to content

Commit

Permalink
Merge pull request #65 from tales-pw/add-gameobject-clone-method
Browse files Browse the repository at this point in the history
Add GameObject#clone method
  • Loading branch information
xunto committed Feb 23, 2022
2 parents 12589d1 + 79c672f commit d169fd1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/pw/tales/cofdsystem/game_object/GameObject.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pw.tales.cofdsystem.game_object;

import thx.Uuid;
import pw.tales.cofdsystem.synchronization.serialization.game_object.GameObjectSerialization;
import pw.tales.cofdsystem.game_object.traits.TraitType;
import pw.tales.cofdsystem.game_object.traits.Trait;
Expand Down Expand Up @@ -108,4 +109,11 @@ class GameObject implements IRecord
var serializer = new GameObjectSerialization(system);
return serializer.fromData(data);
}

public function clone():GameObject
{
var data = this.toData();
data.dn = Uuid.create().toString();
return GameObject.fromData(this.system, data);
}
}
18 changes: 8 additions & 10 deletions test/pw/tales/cofdsystem/game_object/GameObjectTestCase.hx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package pw.tales.cofdsystem.game_object;

import pw.tales.cofdsystem.character.traits.attribute.Attributes;
import haxe.unit.TestCase;

class GameObjectTestCase extends TestCase
class GameObjectTestCase extends CofDSystemTestCase
{
public final system:CofDSystem = new CofDSystem();

public function testDeactivate():Void
{
var gameObject = new GameObject("game_object", system);
gameObject.getTraitManager().addTrait(Attributes.STRENGTH);
gameObject.deactivate();
this.c1.deactivate();
assertEquals(GameObjectState.INACTIVE, c1.getState());
}

assertEquals(GameObjectState.INACTIVE, gameObject.getState());
public function testClone():Void
{
var c1_clone = this.c1.clone();
assertTrue(this.c1.getDN() != c1_clone.getDN());
}
}

0 comments on commit d169fd1

Please sign in to comment.