Search in sources :

Example 1 with WorldSetupWrapper

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

use of org.terasology.engine.rendering.world.WorldSetupWrapper in project Terasology by MovingBlocks.

the class UniverseSetupScreen method addNewWorld.

/**
 * Called whenever the user decides to add a new world.
 * @param worldGeneratorInfo The {@link WorldGeneratorInfo} object for the new world.
 */
private void addNewWorld(WorldGeneratorInfo worldGeneratorInfo) {
    String selectedWorldName = worldGeneratorInfo.getDisplayName();
    while (worldNameMatchesAnother(selectedWorldName + "-" + worldNumber)) {
        ++worldNumber;
    }
    selectedWorld = worldGeneratorInfo.getDisplayName() + '-' + worldNumber;
    worlds.add(new WorldSetupWrapper(new Name(worldGeneratorInfo.getDisplayName() + '-' + worldNumber), worldGeneratorInfo));
    indexOfSelectedWorld = findIndex(worlds, selectedWorld);
    ++worldNumber;
}
Also used : WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper) Name(org.terasology.gestalt.naming.Name)

Example 3 with WorldSetupWrapper

use of org.terasology.engine.rendering.world.WorldSetupWrapper in project Terasology by MovingBlocks.

the class UniverseSetupScreen method findIndex.

/**
 * Looks for the index of a selected world from the given list.
 * @param worldsList the list to search
 * @param worldName the name of the world to find
 * @return the found index value or -1 if not found
 */
private int findIndex(List<WorldSetupWrapper> worldsList, String worldName) {
    for (int i = 0; i < worldsList.size(); i++) {
        WorldSetupWrapper currentWorldFromList = worldsList.get(i);
        Name customName = currentWorldFromList.getWorldName();
        if (customName.toString().equals(worldName)) {
            return i;
        }
    }
    return -1;
}
Also used : WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper) Name(org.terasology.gestalt.naming.Name)

Example 4 with WorldSetupWrapper

use of org.terasology.engine.rendering.world.WorldSetupWrapper in project Terasology by MovingBlocks.

the class StartPlayingScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
    WidgetUtil.trySubscribe(this, "play", button -> {
        universeWrapper.setTargetWorld(targetWorld);
        final GameManifest gameManifest = GameManifestProvider.createGameManifest(universeWrapper, moduleManager, config);
        if (gameManifest != null) {
            gameEngine.changeState(new StateLoading(gameManifest, (universeWrapper.getLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
        } else {
            getManager().createScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", "Can't create new game!");
        }
        SimpleUri uri;
        WorldInfo worldInfo;
        // gameManifest.addWorld(worldInfo);
        int i = 0;
        for (WorldSetupWrapper world : worldSetupWrappers) {
            if (world != targetWorld) {
                i++;
                uri = world.getWorldGeneratorInfo().getUri();
                worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD + i, world.getWorldName().toString(), world.getWorldGenerator().getWorldSeed(), (long) (WorldTime.DAY_LENGTH * WorldTime.NOON_OFFSET), uri);
                gameManifest.addWorld(worldInfo);
                config.getUniverseConfig().addWorldManager(worldInfo);
            }
        }
        gameEngine.changeState(new StateLoading(gameManifest, (universeWrapper.getLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
    });
    WidgetUtil.trySubscribe(this, "mainMenu", button -> {
        getManager().pushScreen("engine:mainMenuScreen");
    });
    WidgetUtil.trySubscribe(this, "renderingSettings", button -> {
        RenderingModuleSettingScreen renderingModuleSettingScreen = (RenderingModuleSettingScreen) getManager().getScreen(RenderingModuleSettingScreen.ASSET_URI);
        if (renderingModuleSettingScreen == null) {
            renderingModuleSettingScreen = getManager().createScreen(RenderingModuleSettingScreen.ASSET_URI, RenderingModuleSettingScreen.class);
            renderingModuleSettingScreen.setSubContext(this.subContext);
            renderingModuleSettingScreen.postInit();
        }
        triggerForwardAnimation(renderingModuleSettingScreen);
    });
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) StateLoading(org.terasology.engine.core.modes.StateLoading) RenderingModuleSettingScreen(org.terasology.engine.rendering.nui.layers.mainMenu.videoSettings.RenderingModuleSettingScreen) SimpleUri(org.terasology.engine.core.SimpleUri) WorldInfo(org.terasology.engine.world.internal.WorldInfo) WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper)

Aggregations

WorldSetupWrapper (org.terasology.engine.rendering.world.WorldSetupWrapper)4 SimpleUri (org.terasology.engine.core.SimpleUri)2 GameManifest (org.terasology.engine.game.GameManifest)2 WorldInfo (org.terasology.engine.world.internal.WorldInfo)2 Name (org.terasology.gestalt.naming.Name)2 StateLoading (org.terasology.engine.core.modes.StateLoading)1 RenderingModuleSettingScreen (org.terasology.engine.rendering.nui.layers.mainMenu.videoSettings.RenderingModuleSettingScreen)1 Component (org.terasology.gestalt.entitysystem.component.Component)1 Module (org.terasology.gestalt.module.Module)1 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)1 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)1