Search in sources :

Example 1 with WorldInfo

use of org.terasology.engine.world.internal.WorldInfo 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 2 with WorldInfo

use of org.terasology.engine.world.internal.WorldInfo in project Terasology by MovingBlocks.

the class JoinServer method step.

@Override
public boolean step() {
    if (applyModuleThread != null) {
        if (!applyModuleThread.isAlive()) {
            if (oldEnvironment != null) {
                oldEnvironment.close();
            }
            return true;
        }
        return false;
    } else if (joinStatus.getStatus() == JoinStatus.Status.COMPLETE) {
        Server server = networkSystem.getServer();
        ServerInfoMessage serverInfo = networkSystem.getServer().getInfo();
        // If no GameName, use Server IP Address
        if (serverInfo.getGameName().length() > 0) {
            gameManifest.setTitle(serverInfo.getGameName());
        } else {
            gameManifest.setTitle(server.getRemoteAddress());
        }
        for (WorldInfo worldInfo : serverInfo.getWorldInfoList()) {
            gameManifest.addWorld(worldInfo);
        }
        Map<String, Short> blockMap = Maps.newHashMap();
        for (Entry<Integer, String> entry : serverInfo.getBlockIds().entrySet()) {
            String name = entry.getValue();
            short id = entry.getKey().shortValue();
            Short oldId = blockMap.put(name, id);
            if (oldId != null && oldId != id) {
                logger.warn("Overwriting Id {} for {} with Id {}", oldId, name, id);
            }
        }
        gameManifest.setRegisteredBlockFamilies(serverInfo.getRegisterBlockFamilyList());
        gameManifest.setBlockIdMap(blockMap);
        gameManifest.setTime(networkSystem.getServer().getInfo().getTime());
        ModuleManager moduleManager = context.get(ModuleManager.class);
        Set<Module> moduleSet = Sets.newLinkedHashSet();
        for (NameVersion moduleInfo : networkSystem.getServer().getInfo().getModuleList()) {
            Module module = moduleManager.getRegistry().getModule(moduleInfo.getName(), moduleInfo.getVersion());
            if (module == null) {
                StateMainMenu mainMenu = new StateMainMenu("Missing required module: " + moduleInfo);
                context.get(GameEngine.class).changeState(mainMenu);
                return false;
            } else {
                logger.info("Activating module: {}:{}", moduleInfo.getName(), moduleInfo.getVersion());
                gameManifest.addModule(module.getId(), module.getVersion());
                moduleSet.add(module);
            }
        }
        oldEnvironment = moduleManager.getEnvironment();
        moduleManager.loadEnvironment(moduleSet, true);
        context.get(Game.class).load(gameManifest);
        EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
        applyModuleThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
        applyModuleThread.start();
        return false;
    } else if (joinStatus.getStatus() == JoinStatus.Status.FAILED) {
        StateMainMenu mainMenu = new StateMainMenu("Failed to connect to server: " + joinStatus.getErrorMessage());
        context.get(GameEngine.class).changeState(mainMenu);
        networkSystem.shutdown();
    }
    return false;
}
Also used : Set(java.util.Set) Server(org.terasology.engine.network.Server) NameVersion(org.terasology.gestalt.naming.NameVersion) GameEngine(org.terasology.engine.core.GameEngine) ModuleManager(org.terasology.engine.core.module.ModuleManager) Entry(java.util.Map.Entry) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) WorldInfo(org.terasology.engine.world.internal.WorldInfo) ServerInfoMessage(org.terasology.engine.network.ServerInfoMessage) Module(org.terasology.gestalt.module.Module) Map(java.util.Map) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 3 with WorldInfo

use of org.terasology.engine.world.internal.WorldInfo in project Terasology by MovingBlocks.

the class ServerInfoMessageImpl method getWorldInfoList.

@Override
public List<WorldInfo> getWorldInfoList() {
    List<WorldInfo> result = Lists.newArrayList();
    for (NetData.WorldInfo pbWorldInfo : info.getWorldInfoList()) {
        WorldInfo worldInfo = new WorldInfo();
        worldInfo.setTime(pbWorldInfo.getTime());
        worldInfo.setTitle(pbWorldInfo.getTitle());
        result.add(worldInfo);
    }
    return result;
}
Also used : NetData(org.terasology.protobuf.NetData) WorldInfo(org.terasology.engine.world.internal.WorldInfo)

Example 4 with WorldInfo

use of org.terasology.engine.world.internal.WorldInfo in project Terasology by MovingBlocks.

the class GameManifestProvider method createGameManifest.

/**
 * Generates game manifest with default settings (title, seed) if not specified.
 * Uses default world generator, and modules selection.
 * @TODO: rewrite/fix it when code will be more stable
 *
 * @param universeWrapper  contains the universe level properties
 * @param moduleManager    resolves modules
 * @param config           provides default module selection, world generator
 * @return                 game manifest with default settings
 */
public static GameManifest createGameManifest(final UniverseWrapper universeWrapper, final ModuleManager moduleManager, final Config config) {
    GameManifest gameManifest = new GameManifest();
    if (StringUtils.isNotBlank(universeWrapper.getGameName())) {
        gameManifest.setTitle(GameProvider.getNextGameName(universeWrapper.getGameName()));
    } else {
        gameManifest.setTitle(GameProvider.getNextGameName());
    }
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
    if (!result.isSuccess()) {
        logger.error("Can't resolve dependencies");
        return null;
    }
    for (Module module : result.getModules()) {
        gameManifest.addModule(module.getId(), module.getVersion());
    }
    SimpleUri uri;
    String seed;
    WorldSetupWrapper worldSetup = universeWrapper.getTargetWorld();
    if (worldSetup != null) {
        uri = worldSetup.getWorldGenerator().getUri();
        seed = worldSetup.getWorldGenerator().getWorldSeed();
    } else {
        uri = config.getWorldGeneration().getDefaultGenerator();
        seed = universeWrapper.getSeed();
    }
    gameManifest.setSeed(seed);
    String targetWorldName = "";
    Map<String, Component> worldConfig = Maps.newHashMap();
    if (worldSetup != null) {
        targetWorldName = worldSetup.getWorldName().toString();
        if (worldSetup.getWorldConfigurator() != null) {
            // horrible hack to get configs into manifest.
            // config driven by CreateWorldEntity.
            // world config set somewhere else as well no clear drive from config --> world
            gameManifest.setModuleConfigs(uri, worldSetup.getWorldConfigurator().getProperties());
        }
    }
    // This is multiplied by the number of seconds in a day (86400000) to determine the exact  millisecond at which the game will start.
    WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, targetWorldName, seed, (long) (WorldTime.DAY_LENGTH * WorldTime.SUNRISE_OFFSET), uri);
    gameManifest.addWorld(worldInfo);
    config.getUniverseConfig().addWorldManager(worldInfo);
    config.getUniverseConfig().setSpawnWorldTitle(worldInfo.getTitle());
    config.getUniverseConfig().setUniverseSeed(universeWrapper.getSeed());
    return gameManifest;
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) WorldInfo(org.terasology.engine.world.internal.WorldInfo) Module(org.terasology.gestalt.module.Module) Component(org.terasology.gestalt.entitysystem.component.Component) WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver)

Example 5 with WorldInfo

use of org.terasology.engine.world.internal.WorldInfo in project Terasology by MovingBlocks.

the class JoinGameScreen method getWorldText.

private String getWorldText(Future<ServerInfoMessage> info) {
    try {
        List<String> codedWorldInfo = new ArrayList<>();
        ServerInfoMessage serverInfoMessage = info.get();
        if (serverInfoMessage == null) {
            return FontColor.getColored(translationSystem.translate("${engine:menu#connection-failed}"), Color.RED);
        }
        for (WorldInfo wi : serverInfoMessage.getWorldInfoList()) {
            float timeInDays = wi.getTime() / (float) WorldTime.DAY_LENGTH;
            codedWorldInfo.add(String.format("%s (%.2f days)", wi.getTitle(), timeInDays));
        }
        return Joiner.on('\n').join(codedWorldInfo);
    } catch (ExecutionException | InterruptedException e) {
        return FontColor.getColored(translationSystem.translate("${engine:menu#connection-failed}"), Color.RED);
    }
}
Also used : ArrayList(java.util.ArrayList) WorldInfo(org.terasology.engine.world.internal.WorldInfo) ServerInfoMessage(org.terasology.engine.network.ServerInfoMessage) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

WorldInfo (org.terasology.engine.world.internal.WorldInfo)12 ModuleManager (org.terasology.engine.core.module.ModuleManager)5 GameManifest (org.terasology.engine.game.GameManifest)5 Module (org.terasology.gestalt.module.Module)4 SimpleUri (org.terasology.engine.core.SimpleUri)3 WorldProvider (org.terasology.engine.world.WorldProvider)3 BlockManager (org.terasology.engine.world.block.BlockManager)3 Config (org.terasology.engine.config.Config)2 WorldGenerationConfig (org.terasology.engine.config.WorldGenerationConfig)2 StateLoading (org.terasology.engine.core.modes.StateLoading)2 StateMainMenu (org.terasology.engine.core.modes.StateMainMenu)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 ServerInfoMessage (org.terasology.engine.network.ServerInfoMessage)2 DirectionAndOriginPosRecorderList (org.terasology.engine.recording.DirectionAndOriginPosRecorderList)2 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)2 RecordAndReplaySerializer (org.terasology.engine.recording.RecordAndReplaySerializer)2 RecordAndReplayUtils (org.terasology.engine.recording.RecordAndReplayUtils)2 WorldSetupWrapper (org.terasology.engine.rendering.world.WorldSetupWrapper)2 WorldGenerator (org.terasology.engine.world.generator.WorldGenerator)2 IOException (java.io.IOException)1