Search in sources :

Example 1 with AttackButton

use of org.terasology.engine.input.binds.interaction.AttackButton in project Terasology by MovingBlocks.

the class EventSystemReplayImplTest method setup.

@BeforeEach
public void setup() {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    Reflections reflections = new Reflections(getClass().getClassLoader());
    TypeHandlerLibrary serializationLibrary = new TypeHandlerLibraryImpl(reflections);
    EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, serializationLibrary);
    PojoEntityManager entityManager = new PojoEntityManager();
    entityManager.setComponentLibrary(entitySystemLibrary.getComponentLibrary());
    entityManager.setPrefabManager(new PojoPrefabManager(context));
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    recordAndReplayCurrentStatus = new RecordAndReplayCurrentStatus();
    RecordedEventStore eventStore = new RecordedEventStore();
    RecordAndReplayUtils recordAndReplayUtils = new RecordAndReplayUtils();
    CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
    DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
    ModuleManager moduleManager = mock(ModuleManager.class);
    when(moduleManager.getEnvironment()).thenReturn(mock(ModuleEnvironment.class));
    RecordAndReplaySerializer recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, eventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, mock(TypeRegistry.class));
    recordAndReplayCurrentStatus.setStatus(RecordAndReplayStatus.REPLAYING);
    entity = entityManager.create();
    Long id = entity.getId();
    eventStore.add(new RecordedEvent(id, new AttackButton(), 1, 1));
    eventStore.add(new RecordedEvent(id, new AttackButton(), 2, 2));
    eventStore.add(new RecordedEvent(id, new AttackButton(), 3, 3));
    List<Class<?>> selectedClassesToReplay = new ArrayList<>();
    selectedClassesToReplay.add(InputEvent.class);
    eventSystem = new EventSystemReplayImpl(entitySystemLibrary.getEventLibrary(), networkSystem, entityManager, eventStore, recordAndReplaySerializer, recordAndReplayUtils, selectedClassesToReplay, recordAndReplayCurrentStatus);
    entityManager.setEventSystem(eventSystem);
    handler = new TestEventHandler();
    eventSystem.registerEventHandler(handler);
}
Also used : PojoPrefabManager(org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager) ArrayList(java.util.ArrayList) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) TypeRegistry(org.terasology.reflection.TypeRegistry) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) EntitySystemLibrary(org.terasology.engine.entitySystem.metadata.EntitySystemLibrary) Reflections(org.reflections.Reflections) NetworkSystem(org.terasology.engine.network.NetworkSystem) TypeHandlerLibraryImpl(org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) PojoEntityManager(org.terasology.engine.entitySystem.entity.internal.PojoEntityManager) AttackButton(org.terasology.engine.input.binds.interaction.AttackButton) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with AttackButton

use of org.terasology.engine.input.binds.interaction.AttackButton in project Terasology by MovingBlocks.

the class EventSystemReplayImplTest method testSendingEventAfterReplay.

@Test
public void testSendingEventAfterReplay() {
    assertEquals(0, handler.receivedAttackButtonList.size());
    long startTime = System.currentTimeMillis();
    while ((System.currentTimeMillis() - startTime) < 100) {
        eventSystem.process();
    }
    eventSystem.send(entity, new AttackButton());
    assertEquals(4, handler.receivedAttackButtonList.size());
}
Also used : AttackButton(org.terasology.engine.input.binds.interaction.AttackButton) Test(org.junit.jupiter.api.Test)

Example 3 with AttackButton

use of org.terasology.engine.input.binds.interaction.AttackButton in project Terasology by MovingBlocks.

the class EventSystemReplayImplTest method testBlockingEventDuringReplay.

@Test
public void testBlockingEventDuringReplay() {
    assertEquals(0, handler.receivedAttackButtonList.size());
    eventSystem.send(entity, new AttackButton());
    long startTime = System.currentTimeMillis();
    while ((System.currentTimeMillis() - startTime) < 100) {
        eventSystem.process();
    }
    assertEquals(3, handler.receivedAttackButtonList.size());
}
Also used : AttackButton(org.terasology.engine.input.binds.interaction.AttackButton) Test(org.junit.jupiter.api.Test)

Aggregations

AttackButton (org.terasology.engine.input.binds.interaction.AttackButton)3 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Reflections (org.reflections.Reflections)1 ContextImpl (org.terasology.engine.context.internal.ContextImpl)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 PojoEntityManager (org.terasology.engine.entitySystem.entity.internal.PojoEntityManager)1 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)1 PojoPrefabManager (org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager)1 NetworkSystem (org.terasology.engine.network.NetworkSystem)1 TypeHandlerLibraryImpl (org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl)1 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)1 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)1 TypeRegistry (org.terasology.reflection.TypeRegistry)1