Search in sources :

Example 1 with GameManifest

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

the class NameRecordingScreen method rewriteManifestTitle.

/**
 * Rewrites the title of the save game manifest to match the new directory title.
 *
 * @param destinationPath The path of the new recording files.
 * @param newTitle The new name for the recording manifest.
 * @throws IOException
 */
private void rewriteManifestTitle(Path destinationPath, String newTitle) throws IOException {
    // simply grabs the manifest, changes it, and saves again.
    GameManifest manifest = GameManifest.load(destinationPath.resolve(GameManifest.DEFAULT_FILE_NAME));
    manifest.setTitle(newTitle);
    GameManifest.save(destinationPath.resolve(GameManifest.DEFAULT_FILE_NAME), manifest);
}
Also used : GameManifest(org.terasology.engine.game.GameManifest)

Example 2 with GameManifest

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

the class GameProvider method getSavedGameOrRecording.

private static List<GameInfo> getSavedGameOrRecording(Path saveOrRecordingPath) {
    SortedMap<FileTime, Path> savedGamePaths = Maps.newTreeMap(Collections.reverseOrder());
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(saveOrRecordingPath)) {
        for (Path entry : stream) {
            if (Files.isRegularFile(entry.resolve(GameManifest.DEFAULT_FILE_NAME))) {
                savedGamePaths.put(Files.getLastModifiedTime(entry.resolve(GameManifest.DEFAULT_FILE_NAME)), entry);
            }
        }
    } catch (IOException e) {
        logger.error("Failed to read saved games path", e);
    }
    List<GameInfo> result = Lists.newArrayListWithCapacity(savedGamePaths.size());
    for (Map.Entry<FileTime, Path> world : savedGamePaths.entrySet()) {
        Path gameManifest = world.getValue().resolve(GameManifest.DEFAULT_FILE_NAME);
        if (!Files.isRegularFile(gameManifest)) {
            continue;
        }
        try {
            GameManifest info = GameManifest.load(gameManifest);
            try {
                if (!info.getTitle().isEmpty()) {
                    Date date = new Date(world.getKey().toMillis());
                    result.add(new GameInfo(info, date, world.getValue()));
                }
            } catch (NullPointerException npe) {
                logger.error("The save file was corrupted for: " + world.toString() + ". The manifest can be " + "found and restored at: " + gameManifest.toString(), npe);
            }
        } catch (IOException e) {
            logger.error("Failed reading world data object.", e);
        }
    }
    return result;
}
Also used : Path(java.nio.file.Path) GameManifest(org.terasology.engine.game.GameManifest) FileTime(java.nio.file.attribute.FileTime) IOException(java.io.IOException) Map(java.util.Map) SortedMap(java.util.SortedMap) Date(java.util.Date)

Example 3 with GameManifest

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

the class ReplayScreen method loadGame.

private void loadGame(GameInfo item) {
    try {
        GameManifest manifest = item.getManifest();
        recordAndReplayUtils.setGameTitle(manifest.getTitle());
        config.getWorldGeneration().setDefaultSeed(manifest.getSeed());
        config.getWorldGeneration().setWorldTitle(manifest.getTitle());
        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)

Example 4 with GameManifest

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

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

the class Terasology method call.

@Override
public Integer call() throws IOException {
    handleLaunchArguments();
    setupLogging();
    SplashScreen splashScreen;
    if (splashEnabled) {
        CountDownLatch splashInitLatch = new CountDownLatch(1);
        GLFWSplashScreen glfwSplash = new GLFWSplashScreen(splashInitLatch);
        Thread thread = new Thread(glfwSplash, "splashscreen-loop");
        thread.setDaemon(true);
        thread.start();
        try {
            // wait splash initialize... we will lose some post messages otherwise.
            // noinspection ResultOfMethodCallIgnored
            splashInitLatch.await(1, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
        // ignore
        }
        splashScreen = glfwSplash;
    } else {
        splashScreen = SplashScreenBuilder.createStub();
    }
    splashScreen.post("Java Runtime " + System.getProperty("java.version") + " loaded");
    try {
        TerasologyEngineBuilder builder = new TerasologyEngineBuilder();
        populateSubsystems(builder);
        TerasologyEngine engine = builder.build();
        engine.subscribe(newStatus -> {
            if (newStatus == StandardGameStatus.RUNNING) {
                splashScreen.close();
            } else {
                splashScreen.post(newStatus.getDescription());
            }
        });
        if (isHeadless) {
            engine.subscribeToStateChange(new HeadlessStateChangeListener(engine));
            engine.run(new StateHeadlessSetup());
        } else if (loadLastGame) {
            // initialize the managers first
            engine.initialize();
            GameScheduler.scheduleParallel("loadGame", () -> {
                GameManifest gameManifest = getLatestGameManifest();
                if (gameManifest != null) {
                    engine.changeState(new StateLoading(gameManifest, NetworkMode.NONE));
                }
            });
        } else {
            if (createLastGame) {
                engine.initialize();
                GameScheduler.scheduleParallel("createLastGame", () -> {
                    GameManifest gameManifest = getLatestGameManifest();
                    if (gameManifest != null) {
                        String title = gameManifest.getTitle();
                        if (!title.startsWith("New Created")) {
                            // if first time run
                            gameManifest.setTitle("New Created " + title + " 1");
                        } else {
                            // if not first time run
                            gameManifest.setTitle(getNewTitle(title));
                        }
                        engine.changeState(new StateLoading(gameManifest, NetworkMode.NONE));
                    }
                });
            }
            engine.run(new StateMainMenu());
        }
    } catch (Throwable e) {
        // also catch Errors such as UnsatisfiedLink, NoSuchMethodError, etc.
        splashScreen.close();
        reportException(e);
    }
    return 0;
}
Also used : TerasologyEngineBuilder(org.terasology.engine.core.TerasologyEngineBuilder) StateLoading(org.terasology.engine.core.modes.StateLoading) CountDownLatch(java.util.concurrent.CountDownLatch) StateHeadlessSetup(org.terasology.engine.core.subsystem.headless.mode.StateHeadlessSetup) TerasologyEngine(org.terasology.engine.core.TerasologyEngine) GameManifest(org.terasology.engine.game.GameManifest) HeadlessStateChangeListener(org.terasology.engine.core.subsystem.headless.mode.HeadlessStateChangeListener) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) SplashScreen(org.terasology.splash.SplashScreen)

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