use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class EntitySerializerTest method testPrefabMaintainedOverSerialization.
@Test
public void testPrefabMaintainedOverSerialization() throws Exception {
EntityRef entity = entityManager.create(prefab);
EntityData.Entity entityData = entitySerializer.serialize(entity);
long nextId = entityManager.getNextId();
entityManager.clear();
entityManager.setNextId(nextId);
EntityRef newEntity = entitySerializer.deserialize(entityData);
assertTrue(newEntity.hasComponent(EntityInfoComponent.class));
EntityInfoComponent comp = newEntity.getComponent(EntityInfoComponent.class);
assertEquals(prefab, comp.parentPrefab);
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class WorldSerializerTest method testNotPersistedIfFlagedOtherwise.
@Test
public void testNotPersistedIfFlagedOtherwise() throws Exception {
EngineEntityManager entityManager = context.get(EngineEntityManager.class);
EntityBuilder entityBuilder = entityManager.newBuilder();
PrefabSerializer prefabSerializer = new PrefabSerializer(entityManager.getComponentLibrary(), entityManager.getTypeSerializerLibrary());
WorldSerializer worldSerializer = new WorldSerializerImpl(entityManager, prefabSerializer);
entityBuilder.setPersistent(false);
// just used to express that an entity got created
@SuppressWarnings("unused") EntityRef entity = entityBuilder.build();
EntityData.GlobalStore worldData = worldSerializer.serializeWorld(false);
assertEquals(0, worldData.getEntityCount());
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class NetworkOwnershipTest method testClientSentInitialForOwnershipChain.
@Test
public void testClientSentInitialForOwnershipChain() {
NetworkComponent netCompA = new NetworkComponent();
netCompA.replicateMode = NetworkComponent.ReplicateMode.OWNER;
EntityRef entityA = entityManager.create(netCompA);
EntityBuilder builder = entityManager.newBuilder();
NetworkComponent netCompB = builder.addComponent(new NetworkComponent());
netCompB.replicateMode = NetworkComponent.ReplicateMode.OWNER;
builder.setOwner(entityA);
EntityRef entityB = builder.build();
networkSystem.registerNetworkEntity(entityA);
networkSystem.registerNetworkEntity(entityB);
connectClient();
verify(client, times(0)).setNetInitial(entityA.getComponent(NetworkComponent.class).getNetworkId());
verify(client, times(0)).setNetInitial(entityB.getComponent(NetworkComponent.class).getNetworkId());
entityA.setOwner(clientEntity);
networkSystem.updateOwnership(entityA);
verify(client, times(1)).setNetInitial(entityA.getComponent(NetworkComponent.class).getNetworkId());
verify(client, times(1)).setNetInitial(entityB.getComponent(NetworkComponent.class).getNetworkId());
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class ParticleUpdaterImplTest method testEmitterRegistration.
@Test
public void testEmitterRegistration() {
EntityRef emitterEntity = mock(EntityRef.class);
when(emitterEntity.getComponent(ParticleEmitterComponent.class)).thenReturn(new ParticleEmitterComponent());
particleUpdater.addEmitter(emitterEntity);
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class StorageManagerTest method createClientMock.
private Client createClientMock(String clientId, EntityRef charac) {
EntityRef clientEntity = createClientEntity(charac);
Client client = mock(Client.class);
when(client.getEntity()).thenReturn(clientEntity);
when(client.getId()).thenReturn(clientId);
return client;
}
Aggregations