Search in sources :

Example 11 with GameManifest

use of org.terasology.engine.game.GameManifest in project Terasology by MovingBlocks.

the class SelectGameScreen method loadGame.

private void loadGame(GameInfo item) {
    if (isLoadingAsServer()) {
        Path blacklistPath = PathManager.getInstance().getHomePath().resolve("blacklist.json");
        Path whitelistPath = PathManager.getInstance().getHomePath().resolve("whitelist.json");
        if (!Files.exists(blacklistPath)) {
            try {
                Files.createFile(blacklistPath);
            } catch (IOException e) {
                logger.error("IO Exception on blacklist generation", e);
            }
        }
        if (!Files.exists(whitelistPath)) {
            try {
                Files.createFile(whitelistPath);
            } catch (IOException e) {
                logger.error("IO Exception on whitelist generation", e);
            }
        }
    }
    try {
        final GameManifest manifest = item.getManifest();
        config.getWorldGeneration().setDefaultSeed(manifest.getSeed());
        config.getWorldGeneration().setWorldTitle(manifest.getTitle());
        Optional.ofNullable(CoreRegistry.get(GameEngine.class)).orElseThrow(() -> new IllegalStateException("Failed to get game engine from CoreRegistry")).changeState(new StateLoading(manifest, (isLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
    } catch (Exception e) {
        logger.error("Failed to load saved game", e);
        getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error Loading Game", e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) GameManifest(org.terasology.engine.game.GameManifest) StateLoading(org.terasology.engine.core.modes.StateLoading) GameEngine(org.terasology.engine.core.GameEngine) IOException(java.io.IOException) IOException(java.io.IOException)

Example 12 with GameManifest

use of org.terasology.engine.game.GameManifest 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)

Example 13 with GameManifest

use of org.terasology.engine.game.GameManifest in project Terasology by MovingBlocks.

the class NameRecordingScreen method loadGame.

/**
 * Last step of the recording setup process.
 * Copies the save files from the selected game, transplants them into the 'recordings' folder, and renames the map files
 * to match the provided recording name. Then launches the game loading state.
 *
 * @param newTitle The title of the new recording.
 */
private void loadGame(String newTitle) {
    try {
        final GameManifest manifest = gameInfo.getManifest();
        copySaveDirectoryToRecordingLibrary(manifest.getTitle(), newTitle);
        recordAndReplayUtils.setGameTitle(newTitle);
        config.getWorldGeneration().setDefaultSeed(manifest.getSeed());
        config.getWorldGeneration().setWorldTitle(newTitle);
        CoreRegistry.get(GameEngine.class).changeState(new StateLoading(manifest, NetworkMode.NONE));
    } catch (Exception e) {
        logger.error("Failed to load saved game", e);
        getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error Loading Game", e.getMessage());
    }
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) StateLoading(org.terasology.engine.core.modes.StateLoading) GameEngine(org.terasology.engine.core.GameEngine) IOException(java.io.IOException)

Aggregations

GameManifest (org.terasology.engine.game.GameManifest)13 StateLoading (org.terasology.engine.core.modes.StateLoading)8 WorldInfo (org.terasology.engine.world.internal.WorldInfo)5 Module (org.terasology.gestalt.module.Module)5 GameEngine (org.terasology.engine.core.GameEngine)4 SimpleUri (org.terasology.engine.core.SimpleUri)4 IOException (java.io.IOException)3 Config (org.terasology.engine.config.Config)3 ModuleManager (org.terasology.engine.core.module.ModuleManager)3 Path (java.nio.file.Path)2 Map (java.util.Map)2 WorldGenerationConfig (org.terasology.engine.config.WorldGenerationConfig)2 Name (org.terasology.gestalt.naming.Name)2 Canvas (org.terasology.nui.Canvas)2 UILabel (org.terasology.nui.widgets.UILabel)2 UIText (org.terasology.nui.widgets.UIText)2 TargetLengthBasedClassNameAbbreviator (ch.qos.logback.classic.pattern.TargetLengthBasedClassNameAbbreviator)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1