Search in sources :

Example 6 with Event

use of org.terasology.entitySystem.event.Event in project Terasology by MovingBlocks.

the class VisualCharacterSystemTest method testSendingOfCreateVisualCharacterEvent.

/**
 * This test verifies that:
 * <ul>
 *     <li>No visual character gets created (via event) for the own character (as it is first person)</li>
 *     <li>That the system can deal with LocalPlayer and characters not being properly linked when
 *     the character entities get loaded/created</li>
 *     <li>A visual character gets created (via event) for characters that were already present when the player
 *     joined</li>
 *     <li>A visual character gets created (via event) for characters that joins afterwards </li>
 * </ul>
 */
@Test
public void testSendingOfCreateVisualCharacterEvent() {
    EntityRef clientEntity = mockEntityWithUniqueId();
    EntityRef otherClientEntity = mockEntityWithUniqueId();
    EntityRef ownCharacterEntity = mockEntityWithUniqueId();
    List<Event> ownCharacterEntityEvents = new ArrayList<>();
    recordEntityEventsToList(ownCharacterEntity, ownCharacterEntityEvents);
    VisualCharacterComponent visualComponentOfOwnCharacter = new VisualCharacterComponent();
    Mockito.when(ownCharacterEntity.getComponent(VisualCharacterComponent.class)).thenReturn(visualComponentOfOwnCharacter);
    EntityRef otherCharacterEntity = mockEntityWithUniqueId();
    List<Event> otherCharacterEntityEvents = new ArrayList<>();
    recordEntityEventsToList(otherCharacterEntity, otherCharacterEntityEvents);
    clientEntityReturnedByLocalPlayer = EntityRef.NULL;
    /*
         * Simulate activation before entity is done
         * since the character is not properly linked yet nothing should happen
         */
    system.onActivatedVisualCharacter(OnActivatedComponent.newInstance(), otherCharacterEntity, new VisualCharacterComponent());
    system.onActivatedVisualCharacter(OnActivatedComponent.newInstance(), ownCharacterEntity, visualComponentOfOwnCharacter);
    simulateProperLinkingOfLocalPlayerAndCharacterEntities(clientEntity, otherClientEntity, ownCharacterEntity, otherCharacterEntity);
    system.onAwaitedLocalCharacterSpawnEvent(new AwaitedLocalCharacterSpawnEvent(), ownCharacterEntity);
    assertTypesInListEqual(ownCharacterEntityEvents, Collections.emptyList());
    assertTypesInListEqual(otherCharacterEntityEvents, Arrays.asList(CreateVisualCharacterEvent.class));
    EntityRef laterJoiningCharacterEntity = mockEntityWithUniqueId();
    List<Event> laterJoiningCharacterEntityEvents = new ArrayList<>();
    recordEntityEventsToList(laterJoiningCharacterEntity, laterJoiningCharacterEntityEvents);
    // Joined player is not properly linked but it should not matter:
    Mockito.when(laterJoiningCharacterEntity.getOwner()).thenReturn(EntityRef.NULL);
    system.onActivatedVisualCharacter(OnActivatedComponent.newInstance(), laterJoiningCharacterEntity, new VisualCharacterComponent());
    /*
         * There is no second AwaitedLocalCharacterSpawnEvent event,
         * the system must use the activation to send the event:
         */
    assertTypesInListEqual(laterJoiningCharacterEntityEvents, Arrays.asList(CreateVisualCharacterEvent.class));
}
Also used : AwaitedLocalCharacterSpawnEvent(org.terasology.engine.modes.loadProcesses.AwaitedLocalCharacterSpawnEvent) ArrayList(java.util.ArrayList) CreateVisualCharacterEvent(org.terasology.logic.characters.events.CreateVisualCharacterEvent) Event(org.terasology.entitySystem.event.Event) AwaitedLocalCharacterSpawnEvent(org.terasology.engine.modes.loadProcesses.AwaitedLocalCharacterSpawnEvent) EntityRef(org.terasology.entitySystem.entity.EntityRef) CreateVisualCharacterEvent(org.terasology.logic.characters.events.CreateVisualCharacterEvent) Test(org.junit.Test)

Aggregations

Event (org.terasology.entitySystem.event.Event)6 EntityRef (org.terasology.entitySystem.entity.EntityRef)5 Test (org.junit.Test)3 TIntList (gnu.trove.list.TIntList)2 TShortObjectHashMap (gnu.trove.map.hash.TShortObjectHashMap)2 Vector3i (org.terasology.math.geom.Vector3i)2 ChunkStore (org.terasology.persistence.ChunkStore)2 DeserializationException (org.terasology.persistence.typeHandling.DeserializationException)2 Chunk (org.terasology.world.chunks.Chunk)2 ReadyChunkInfo (org.terasology.world.chunks.internal.ReadyChunkInfo)2 ByteString (com.google.protobuf.ByteString)1 ArrayList (java.util.ArrayList)1 AwaitedLocalCharacterSpawnEvent (org.terasology.engine.modes.loadProcesses.AwaitedLocalCharacterSpawnEvent)1 ReplicatedFieldMetadata (org.terasology.entitySystem.metadata.ReplicatedFieldMetadata)1 PredictionSystem (org.terasology.logic.characters.PredictionSystem)1 CreateVisualCharacterEvent (org.terasology.logic.characters.events.CreateVisualCharacterEvent)1 SerializationException (org.terasology.persistence.typeHandling.SerializationException)1 Serializer (org.terasology.persistence.typeHandling.Serializer)1 ProtobufPersistedData (org.terasology.persistence.typeHandling.protobuf.ProtobufPersistedData)1 EntityData (org.terasology.protobuf.EntityData)1