Search in sources :

Example 1 with AwaitedLocalCharacterSpawnEvent

use of org.terasology.engine.core.modes.loadProcesses.AwaitedLocalCharacterSpawnEvent 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);
    VisualCharacterComponent visualComponentOfOtherCharacter = new VisualCharacterComponent();
    Mockito.when(otherCharacterEntity.getComponent(VisualCharacterComponent.class)).thenReturn(visualComponentOfOtherCharacter);
    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, visualComponentOfOtherCharacter);
    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);
    VisualCharacterComponent visualComponentOfLaterJoiningCharacter = new VisualCharacterComponent();
    Mockito.when(laterJoiningCharacterEntity.getComponent(VisualCharacterComponent.class)).thenReturn(visualComponentOfLaterJoiningCharacter);
    // Joined player is not properly linked but it should not matter:
    Mockito.when(laterJoiningCharacterEntity.getOwner()).thenReturn(EntityRef.NULL);
    system.onActivatedVisualCharacter(OnActivatedComponent.newInstance(), laterJoiningCharacterEntity, visualComponentOfLaterJoiningCharacter);
    /*
         * 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.core.modes.loadProcesses.AwaitedLocalCharacterSpawnEvent) ArrayList(java.util.ArrayList) AwaitedLocalCharacterSpawnEvent(org.terasology.engine.core.modes.loadProcesses.AwaitedLocalCharacterSpawnEvent) CreateVisualCharacterEvent(org.terasology.engine.logic.characters.events.CreateVisualCharacterEvent) Event(org.terasology.engine.entitySystem.event.Event) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) CreateVisualCharacterEvent(org.terasology.engine.logic.characters.events.CreateVisualCharacterEvent) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 AwaitedLocalCharacterSpawnEvent (org.terasology.engine.core.modes.loadProcesses.AwaitedLocalCharacterSpawnEvent)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 Event (org.terasology.engine.entitySystem.event.Event)1 CreateVisualCharacterEvent (org.terasology.engine.logic.characters.events.CreateVisualCharacterEvent)1