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