use of org.terasology.engine.core.modes.StateMainMenu in project Terasology by MovingBlocks.
the class JoinServer method step.
@Override
public boolean step() {
if (applyModuleThread != null) {
if (!applyModuleThread.isAlive()) {
if (oldEnvironment != null) {
oldEnvironment.close();
}
return true;
}
return false;
} else if (joinStatus.getStatus() == JoinStatus.Status.COMPLETE) {
Server server = networkSystem.getServer();
ServerInfoMessage serverInfo = networkSystem.getServer().getInfo();
// If no GameName, use Server IP Address
if (serverInfo.getGameName().length() > 0) {
gameManifest.setTitle(serverInfo.getGameName());
} else {
gameManifest.setTitle(server.getRemoteAddress());
}
for (WorldInfo worldInfo : serverInfo.getWorldInfoList()) {
gameManifest.addWorld(worldInfo);
}
Map<String, Short> blockMap = Maps.newHashMap();
for (Entry<Integer, String> entry : serverInfo.getBlockIds().entrySet()) {
String name = entry.getValue();
short id = entry.getKey().shortValue();
Short oldId = blockMap.put(name, id);
if (oldId != null && oldId != id) {
logger.warn("Overwriting Id {} for {} with Id {}", oldId, name, id);
}
}
gameManifest.setRegisteredBlockFamilies(serverInfo.getRegisterBlockFamilyList());
gameManifest.setBlockIdMap(blockMap);
gameManifest.setTime(networkSystem.getServer().getInfo().getTime());
ModuleManager moduleManager = context.get(ModuleManager.class);
Set<Module> moduleSet = Sets.newLinkedHashSet();
for (NameVersion moduleInfo : networkSystem.getServer().getInfo().getModuleList()) {
Module module = moduleManager.getRegistry().getModule(moduleInfo.getName(), moduleInfo.getVersion());
if (module == null) {
StateMainMenu mainMenu = new StateMainMenu("Missing required module: " + moduleInfo);
context.get(GameEngine.class).changeState(mainMenu);
return false;
} else {
logger.info("Activating module: {}:{}", moduleInfo.getName(), moduleInfo.getVersion());
gameManifest.addModule(module.getId(), module.getVersion());
moduleSet.add(module);
}
}
oldEnvironment = moduleManager.getEnvironment();
moduleManager.loadEnvironment(moduleSet, true);
context.get(Game.class).load(gameManifest);
EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
applyModuleThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
applyModuleThread.start();
return false;
} else if (joinStatus.getStatus() == JoinStatus.Status.FAILED) {
StateMainMenu mainMenu = new StateMainMenu("Failed to connect to server: " + joinStatus.getErrorMessage());
context.get(GameEngine.class).changeState(mainMenu);
networkSystem.shutdown();
}
return false;
}
use of org.terasology.engine.core.modes.StateMainMenu in project Terasology by MovingBlocks.
the class RegisterMods method step.
@Override
public boolean step() {
if (applyModulesThread != null) {
if (!applyModulesThread.isAlive()) {
if (oldEnvironment != null) {
oldEnvironment.close();
}
return true;
}
return false;
} else {
ModuleManager moduleManager = context.get(ModuleManager.class);
List<Name> moduleIds = gameManifest.getModules().stream().map(NameVersion::getName).collect(Collectors.toCollection(ArrayList::new));
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(moduleIds);
if (result.isSuccess()) {
oldEnvironment = moduleManager.getEnvironment();
ModuleEnvironment env = moduleManager.loadEnvironment(result.getModules(), true);
for (Module moduleInfo : env.getModulesOrderedByDependencies()) {
logger.info("Activating module: {}:{}", moduleInfo.getId(), moduleInfo.getVersion());
}
EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
applyModulesThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
applyModulesThread.start();
return false;
} else {
logger.warn("Missing at least one required module (or dependency) from the following list: {}", moduleIds);
context.get(GameEngine.class).changeState(new StateMainMenu("Missing required module or dependency"));
return true;
}
}
}
use of org.terasology.engine.core.modes.StateMainMenu in project Terasology by MovingBlocks.
the class WorldRendererImpl method initRenderingModules.
private void initRenderingModules() {
renderingModuleRegistry = context.get(RenderingModuleRegistry.class);
// registry not populated by new ModuleRendering instances in UI, populate now
if (renderingModuleRegistry.getOrderedRenderingModules().isEmpty()) {
List<ModuleRendering> renderingModules = renderingModuleRegistry.updateRenderingModulesOrder(context.get(ModuleManager.class).getEnvironment(), context);
if (renderingModules.isEmpty()) {
GameEngine gameEngine = context.get(GameEngine.class);
gameEngine.changeState(new StateMainMenu("No rendering module loaded, unable to render. Try enabling " + "CoreRendering."));
}
} else {
// registry populated by new ModuleRendering instances in UI
// Switch module's context from gamecreation subcontext to gamerunning context
renderingModuleRegistry.updateModulesContext(context);
}
for (ModuleRendering moduleRenderingInstance : renderingModuleRegistry.getOrderedRenderingModules()) {
if (moduleRenderingInstance.isEnabled()) {
logger.info(String.format("\nInitialising rendering class %s from %s module.\n", moduleRenderingInstance.getClass().getSimpleName(), moduleRenderingInstance.getProvidingModule()));
moduleRenderingInstance.initialise();
}
}
requestTaskListRefresh();
}
use of org.terasology.engine.core.modes.StateMainMenu 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;
}
use of org.terasology.engine.core.modes.StateMainMenu in project Terasology by MovingBlocks.
the class DeathScreen method initialise.
@Override
public void initialise() {
deathDetails = find("deathDetails", UILabel.class);
WidgetUtil.trySubscribe(this, "respawn", widget -> {
localPlayer.getClientEntity().send(new RespawnRequestEvent());
getManager().closeScreen(DeathScreen.this);
});
WidgetUtil.trySubscribe(this, "settings", widget -> getManager().pushScreen("settingsMenuScreen"));
WidgetUtil.trySubscribe(this, "mainMenu", widget -> {
localPlayer.getClientEntity().send(new RespawnRequestEvent());
gameEngine.changeState(new StateMainMenu());
});
WidgetUtil.trySubscribe(this, "exitGame", widget -> CoreRegistry.get(GameEngine.class).shutdown());
}
Aggregations