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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations