Search in sources :

Example 1 with StateLoading

use of org.terasology.engine.core.modes.StateLoading in project Terasology by MovingBlocks.

the class CoreCommands method join.

/**
 * Join a game
 *
 * @param address   String containing address of game server
 * @param portParam Integer containing game server port
 */
@Command(shortDescription = "Join a game", requiredPermission = PermissionManager.NO_PERMISSION)
public void join(@CommandParam("address") final String address, @CommandParam(value = "port", required = false) Integer portParam) {
    final int port = portParam != null ? portParam : TerasologyConstants.DEFAULT_PORT;
    Callable<JoinStatus> operation = () -> networkSystem.join(address, port);
    final WaitPopup<JoinStatus> popup = nuiManager.pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
    popup.setMessage("Join Game", "Connecting to '" + address + ":" + port + "' - please wait ...");
    popup.onSuccess(result -> {
        if (result.getStatus() != JoinStatus.Status.FAILED) {
            gameEngine.changeState(new StateLoading(result));
        } else {
            MessagePopup screen = nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
            screen.setMessage("Failed to Join", "Could not connect to server - " + result.getErrorMessage());
        }
    });
    popup.startOperation(operation, true);
}
Also used : StateLoading(org.terasology.engine.core.modes.StateLoading) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) JoinStatus(org.terasology.engine.network.JoinStatus) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 2 with StateLoading

use of org.terasology.engine.core.modes.StateLoading in project Terasology by MovingBlocks.

the class JoinGameScreen method join.

private void join(final String address, final int port) {
    Callable<JoinStatus> operation = () -> {
        JoinStatus joinStatus = networkSystem.join(address, port);
        return joinStatus;
    };
    final WaitPopup<JoinStatus> popup = getManager().pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
    popup.setMessage(translationSystem.translate("${engine:menu#join-game-online}"), translationSystem.translate("${engine:menu#connecting-to}") + " '" + address + ":" + port + "' - " + translationSystem.translate("${engine:menu#please-wait}"));
    popup.onSuccess(result -> {
        if (result.getStatus() != JoinStatus.Status.FAILED) {
            engine.changeState(new StateLoading(result));
        } else {
            MessagePopup screen = getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
            screen.setMessage(translationSystem.translate("${engine:menu#failed-to-join}"), translationSystem.translate("${engine:menu#could-not-connect-to-server}") + " - " + result.getErrorMessage());
        }
    });
    popup.startOperation(operation, true);
}
Also used : StateLoading(org.terasology.engine.core.modes.StateLoading) JoinStatus(org.terasology.engine.network.JoinStatus)

Example 3 with StateLoading

use of org.terasology.engine.core.modes.StateLoading 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 StateLoading

use of org.terasology.engine.core.modes.StateLoading 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)

Example 5 with StateLoading

use of org.terasology.engine.core.modes.StateLoading in project Terasology by MovingBlocks.

the class StateHeadlessSetup method init.

@Override
public void init(GameEngine gameEngine) {
    context = gameEngine.createChildContext();
    initEntityAndComponentManagers(true);
    createLocalPlayer(context);
    GameManifest gameManifest;
    List<GameInfo> savedGames = GameProvider.getSavedGames();
    if (savedGames.size() > 0) {
        gameManifest = savedGames.get(0).getManifest();
    } else {
        gameManifest = createGameManifest();
    }
    Config config = context.get(Config.class);
    WorldInfo worldInfo = gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD);
    config.getUniverseConfig().addWorldManager(worldInfo);
    config.getUniverseConfig().setSpawnWorldTitle(worldInfo.getTitle());
    config.getUniverseConfig().setUniverseSeed(gameManifest.getSeed());
    gameEngine.changeState(new StateLoading(gameManifest, NetworkMode.LISTEN_SERVER));
}
Also used : GameInfo(org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameInfo) GameManifest(org.terasology.engine.game.GameManifest) StateLoading(org.terasology.engine.core.modes.StateLoading) WorldGenerationConfig(org.terasology.engine.config.WorldGenerationConfig) Config(org.terasology.engine.config.Config) WorldInfo(org.terasology.engine.world.internal.WorldInfo)

Aggregations

StateLoading (org.terasology.engine.core.modes.StateLoading)10 GameManifest (org.terasology.engine.game.GameManifest)8 GameEngine (org.terasology.engine.core.GameEngine)4 IOException (java.io.IOException)2 Config (org.terasology.engine.config.Config)2 SimpleUri (org.terasology.engine.core.SimpleUri)2 JoinStatus (org.terasology.engine.network.JoinStatus)2 WorldInfo (org.terasology.engine.world.internal.WorldInfo)2 Module (org.terasology.gestalt.module.Module)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 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1