Search in sources :

Example 1 with NetworkSystem

use of org.terasology.engine.network.NetworkSystem in project Terasology by MovingBlocks.

the class EntitySerializerTest method setup.

@BeforeEach
public void setup() {
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = context.get(EngineEntityManager.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("test", "gettersetter"), GetterSetterComponent.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("test", "string"), StringComponent.class);
    entityManager.getComponentLibrary().register(new ResourceUrn("test", "integer"), IntegerComponent.class);
    entitySerializer = new EntitySerializer(entityManager);
    componentLibrary = entityManager.getComponentLibrary();
    PrefabData prefabData = new PrefabData();
    prefabData.addComponent(new StringComponent("Value"));
    prefab = Assets.generateAsset(new ResourceUrn("test:Test"), prefabData, Prefab.class);
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) StringComponent(org.terasology.unittest.stubs.StringComponent) NetworkSystem(org.terasology.engine.network.NetworkSystem) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) EntitySerializer(org.terasology.engine.persistence.serializers.EntitySerializer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with NetworkSystem

use of org.terasology.engine.network.NetworkSystem in project Terasology by MovingBlocks.

the class StorageManagerTest method setup.

@BeforeEach
public void setup(@TempDir Path tempHome) throws Exception {
    super.setup();
    PathManager.getInstance().useOverrideHomePath(tempHome);
    savePath = PathManager.getInstance().getSavePath("testSave");
    assert !Files.isRegularFile(tempHome.resolve("global.dat"));
    entityManager = context.get(EngineEntityManager.class);
    moduleEnvironment = mock(ModuleEnvironment.class);
    blockManager = context.get(BlockManager.class);
    extraDataManager = context.get(ExtraBlockDataManager.class);
    ModuleManager moduleManager = mock(ModuleManager.class);
    when(moduleManager.getEnvironment()).thenReturn(moduleEnvironment);
    RecordedEventStore recordedEventStore = new RecordedEventStore();
    recordAndReplayUtils = new RecordAndReplayUtils();
    CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
    DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
    recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, mock(TypeRegistry.class));
    recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    esm = new ReadWriteStorageManager(savePath, moduleEnvironment, entityManager, blockManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    context.put(StorageManager.class, esm);
    this.character = entityManager.create();
    Client client = createClientMock(PLAYER_ID, character);
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    when(networkSystem.getPlayers()).thenReturn(Arrays.asList(client));
    context.put(NetworkSystem.class, networkSystem);
    AssetManager assetManager = context.get(AssetManager.class);
    BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
    data.setBlockFamily(SymmetricFamily.class);
    assetManager.loadAsset(new ResourceUrn("test:testblock"), data, BlockFamilyDefinition.class);
    assetManager.loadAsset(new ResourceUrn("test:testblock2"), data, BlockFamilyDefinition.class);
    testBlock = context.get(BlockManager.class).getBlock("test:testblock");
    testBlock2 = context.get(BlockManager.class).getBlock("test:testblock2");
    context.put(ChunkProvider.class, mock(ChunkProvider.class));
    WorldProvider worldProvider = mock(WorldProvider.class);
    when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
    context.put(WorldProvider.class, worldProvider);
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) AssetManager(org.terasology.gestalt.assets.management.AssetManager) NetworkSystem(org.terasology.engine.network.NetworkSystem) RecordedEventStore(org.terasology.engine.recording.RecordedEventStore) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) ModuleManager(org.terasology.engine.core.module.ModuleManager) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) BlockManager(org.terasology.engine.world.block.BlockManager) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) WorldProvider(org.terasology.engine.world.WorldProvider) WorldInfo(org.terasology.engine.world.internal.WorldInfo) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) Client(org.terasology.engine.network.Client) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) CharacterStateEventPositionMap(org.terasology.engine.recording.CharacterStateEventPositionMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with NetworkSystem

use of org.terasology.engine.network.NetworkSystem 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 4 with NetworkSystem

use of org.terasology.engine.network.NetworkSystem in project Terasology by MovingBlocks.

the class ReadWriteStorageManager method createSaveTransaction.

private SaveTransaction createSaveTransaction() {
    SaveTransactionBuilder saveTransactionBuilder = new SaveTransactionBuilder(privateEntityManager, entitySetDeltaRecorder, isStoreChunksInZips(), getStoragePathProvider(), worldDirectoryWriteLock, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    ChunkProvider chunkProvider = CoreRegistry.get(ChunkProvider.class);
    NetworkSystem networkSystem = CoreRegistry.get(NetworkSystem.class);
    addChunksToSaveTransaction(saveTransactionBuilder, chunkProvider);
    addPlayersToSaveTransaction(saveTransactionBuilder, networkSystem);
    addGlobalStoreBuilderToSaveTransaction(saveTransactionBuilder);
    addGameManifestToSaveTransaction(saveTransactionBuilder);
    return saveTransactionBuilder.build();
}
Also used : NetworkSystem(org.terasology.engine.network.NetworkSystem) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider)

Example 5 with NetworkSystem

use of org.terasology.engine.network.NetworkSystem in project Terasology by MovingBlocks.

the class HeadlessEnvironment method setupNetwork.

@Override
protected void setupNetwork() {
    EngineTime mockTime = mock(EngineTime.class);
    context.put(Time.class, mockTime);
    NetworkSystem networkSystem = new NetworkSystemImpl(mockTime, getContext());
    context.put(NetworkSystem.class, networkSystem);
}
Also used : NetworkSystem(org.terasology.engine.network.NetworkSystem) EngineTime(org.terasology.engine.core.EngineTime) NetworkSystemImpl(org.terasology.engine.network.internal.NetworkSystemImpl)

Aggregations

NetworkSystem (org.terasology.engine.network.NetworkSystem)15 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ModuleManager (org.terasology.engine.core.module.ModuleManager)5 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)5 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)5 ContextImpl (org.terasology.engine.context.internal.ContextImpl)4 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)4 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)4 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)4 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)3 PrefabData (org.terasology.engine.entitySystem.prefab.PrefabData)3 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)3 PojoPrefabManager (org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager)3 Reflections (org.reflections.Reflections)2 PojoEntityManager (org.terasology.engine.entitySystem.entity.internal.PojoEntityManager)2 ComponentLibrary (org.terasology.engine.entitySystem.metadata.ComponentLibrary)2 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)2 NetworkSystemImpl (org.terasology.engine.network.internal.NetworkSystemImpl)2 TypeHandlerLibraryImpl (org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl)2 CharacterStateEventPositionMap (org.terasology.engine.recording.CharacterStateEventPositionMap)2