Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New create game flow backend | Final steps #3385

Merged
merged 2 commits into from Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -92,7 +92,7 @@ public class CreateGameScreen extends CoreScreenLayer {
private boolean loadingAsServer;

/**
* A UniverseWrapper object used here to determine if the game is single player or multi-player.
* A UniverseWrapper object used here to determine if the game is single-player or multi-player.
*/
private UniverseWrapper universeWrapper;

Expand Down
Expand Up @@ -178,7 +178,7 @@ public String get() {

SimpleUri uri = config.getWorldGeneration().getDefaultGenerator();
// This is multiplied by the number of seconds in a day (86400000) to determine the exact millisecond at which the game will start.
float timeOffset = 0.50f;
final float timeOffset = 0.50f;
WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, tempSeed,
(long) (WorldTime.DAY_LENGTH * timeOffset), uri);
gameManifest.addWorld(worldInfo);
Expand Down
Expand Up @@ -41,6 +41,8 @@

public class StartPlayingScreen extends CoreScreenLayer {

public static final ResourceUrn ASSET_URI = new ResourceUrn("engine:startPlayingScreen");

@In
private ModuleManager moduleManager;

Expand All @@ -53,7 +55,6 @@ public class StartPlayingScreen extends CoreScreenLayer {
@In
private TranslationSystem translationSystem;

public static final ResourceUrn ASSET_URI = new ResourceUrn("engine:startPlayingScreen");
private Texture texture;
private WorldSetupWrapper world;
private UniverseWrapper universeWrapper;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void initialise() {

SimpleUri uri = world.getWorldGeneratorInfo().getUri();
// This is multiplied by the number of seconds in a day (86400000) to determine the exact millisecond at which the game will start.
float timeOffset = 0.50f;
final float timeOffset = 0.50f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if @vampcat meant to make this a constant rather than just final. If so it would be all caps and so on as a class level variable :-)

WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, world.getWorldGenerator().getWorldSeed(),
(long) (WorldTime.DAY_LENGTH * timeOffset), uri);
gameManifest.addWorld(worldInfo);
Expand Down
Expand Up @@ -84,18 +84,22 @@
public class UniverseSetupScreen extends CoreScreenLayer {

public static final ResourceUrn ASSET_URI = new ResourceUrn("engine:universeSetupScreen");
private List<WorldSetupWrapper> worlds = Lists.newArrayList();
int worldNumber = 0;
private String selectedWorld = "";

@In
private WorldGeneratorManager worldGeneratorManager;

@In
private ModuleManager moduleManager;

@In
private Config config;

private List<WorldSetupWrapper> worlds = Lists.newArrayList();
private ModuleEnvironment environment;
private ModuleAwareAssetTypeManager assetTypeManager;
private Context context;
private int worldNumber;
private String selectedWorld = "";

@Override
public void initialise() {
Expand Down Expand Up @@ -186,14 +190,19 @@ public void set(String value) {
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Worlds List Empty!", "No world found to configure.");
}
} catch (UnresolvedWorldGeneratorException e) {
e.getMessage();
e.printStackTrace();
}
});

WidgetUtil.trySubscribe(this, "addGenerator", button -> {
addNewWorld(worldGenerator.getSelection());
List<WorldSetupWrapper> worldOptions = worlds;
worldsDropdown.setOptions(worldNames());
if (worldGenerator.getSelection().getUri().toString().equals("Core:heightMap")) {
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("HeightMap not supported", "HeightMap is not supported for advanced setup right now, a game template will be introduced soon.");

} else {
addNewWorld(worldGenerator.getSelection());
List<WorldSetupWrapper> worldOptions = worlds;
worldsDropdown.setOptions(worldNames());
}
//triggerForwardAnimation(worldSetupScreen);
});

Expand All @@ -204,7 +213,7 @@ public void set(String value) {
worldPreGenerationScreen.setEnvironment(context);
triggerForwardAnimation(worldPreGenerationScreen);
} catch (UnresolvedWorldGeneratorException e) {
e.getMessage();
e.printStackTrace();
}
} else {
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Worlds List Empty!", "Please select a world generator and add words to the dropdown!");
Expand Down Expand Up @@ -254,10 +263,10 @@ private void addNewWorld(WorldGeneratorInfo worldGeneratorInfo) {
}

/**
* This method switched the environment of the game to a temporary one needed for
* creating a game. It created a new {@link Context} and only puts the minimum classes
* This method switches the environment of the game to a temporary one needed for
* creating a game. It creates a new {@link Context} and only puts the minimum classes
* needed for successful game creation.
* @param wrapper passed from the {@link org.terasology.rendering.nui.layers.mainMenu.selectModulesScreen.AdvancedGameSetupScreen} and pushed into the new context.
* @param wrapper takes the {@link org.terasology.rendering.nui.layers.mainMenu.selectModulesScreen.AdvancedGameSetupScreen} and pushes it into the new context.
*/
public void setEnvironment(UniverseWrapper wrapper) {
context = new ContextImpl();
Expand Down Expand Up @@ -312,13 +321,12 @@ private void initAssets() {
(AssetFactory<BehaviorTree, BehaviorTreeData>) BehaviorTree::new, false, "behaviors");
assetTypeManager.registerCoreAssetType(UIElement.class,
(AssetFactory<UIElement, UIData>) UIElement::new, "ui");

}

/**
* Create a list of the names of the world, so that they can be displayed as simple String
* in the drop-down.
* @return A list of world names in String.
* @return A list of world names encoded as a String
*/
public List<String> worldNames() {
List<String> worldNamesList = Lists.newArrayList();
Expand All @@ -341,7 +349,7 @@ public WorldSetupWrapper findWorldByName() {
}
return null;
}

public List<WorldSetupWrapper> getWorldsList() {
return worlds;
}
Expand Down
Expand Up @@ -16,7 +16,7 @@
package org.terasology.rendering.nui.layers.mainMenu;

/**
* A class which store the universe level properties for a game like if
* A class which stores the universe level properties for a game like whether
* the game is single-player or multi-player, seed value and the game name.
*/
public class UniverseWrapper {
Expand Down
Expand Up @@ -49,17 +49,20 @@
import java.util.stream.Collectors;

/**
* This class let's the user preview different worlds added in the
* {@link UniverseSetupScreen}. Each world is still configurable and it's seed
* This class lets the user preview different worlds added in the
* {@link UniverseSetupScreen}. Each world is still configurable and its seed
* can be changed by the re-roll button. Note that each world has a unique seed.
*/
public class WorldPreGenerationScreen extends CoreScreenLayer {

public static final ResourceUrn ASSET_URI = new ResourceUrn("engine:worldPreGenerationScreen");

@In
private ModuleManager moduleManager;

@In
private Config config;

private ModuleEnvironment environment;
private WorldGenerator worldGenerator;
private Texture texture;
Expand All @@ -75,8 +78,7 @@ public class WorldPreGenerationScreen extends CoreScreenLayer {
/**
* A function called before the screen comes to the forefront to setup the environment
* and extract necessary objects from the new Context.
* @param subContext As there is a new environment created in the {@link UniverseSetupScreen}, it's passed to
* this screen instead of using the old Context.
* @param subContext The new environment created in {@link UniverseSetupScreen}
* @throws UnresolvedWorldGeneratorException The creation of a world generator can throw this Exception
*/
public void setEnvironment(Context subContext) throws UnresolvedWorldGeneratorException {
Expand Down Expand Up @@ -125,7 +127,6 @@ public void set(Float value) {
}
});


final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
worldsDropdown.bindSelection(new Binding<String>() {
@Override
Expand All @@ -149,7 +150,7 @@ public void set(String value) {
previewGen = new FacetLayerPreview(environment, worldGenerator);
updatePreview();
} catch (UnresolvedWorldGeneratorException e) {
e.getMessage();
e.printStackTrace();
}
}
});
Expand All @@ -176,7 +177,7 @@ public void set(String value) {
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Worlds List Empty!", "No world found to configure.");
}
} catch (UnresolvedWorldGeneratorException e) {
e.getMessage();
e.printStackTrace();
}
});

Expand All @@ -200,12 +201,12 @@ public void onOpened() {
previewGen = new FacetLayerPreview(environment, worldGenerator);
updatePreview();
} catch (UnresolvedWorldGeneratorException e) {
e.getMessage();
e.printStackTrace();
}
}

/**
* Generates a texture and set's to the image view, thus previewing the world.
* Generates a texture and sets it to the image view, thus previewing the world.
*/
private void genTexture() {
int imgWidth = 384;
Expand All @@ -221,7 +222,7 @@ private void genTexture() {
}

/**
* Updates the preview according to any changes to made the configurator.
* Updates the preview according to any changes made to the configurator.
* Also pops up a message and keeps track of percentage world preview prepared.
*/
private void updatePreview() {
Expand All @@ -247,9 +248,9 @@ private void updatePreview() {
}

/**
* This method takes the name of the selected world as String and return the corresponding
* WorldSetupWrapper object.
* @return {@link WorldSetupWrapper} object.
* This method takes the name of the world selected in the worldsDropdown
* as String and return the corresponding WorldSetupWrapper object.
* @return {@link WorldSetupWrapper} object of the selected world.
*/
private WorldSetupWrapper findWorldByName() {
for (WorldSetupWrapper world : worldList) {
Expand Down
Expand Up @@ -51,8 +51,10 @@
public class WorldSetupScreen extends CoreScreenLayer {

public static final ResourceUrn ASSET_URI = new ResourceUrn("engine:worldSetupScreen");

@In
private WorldGeneratorManager worldGeneratorManager;

@In
private Config config;

Expand Down Expand Up @@ -85,10 +87,9 @@ public void onOpened() {
}

/**
* This method sets the world whose properties are to changed. This function is called before the screen comes
* This method sets the world whose properties are to be changed. This function is called before the screen comes
* to the forefront.
* @param subContext As there is a new environment created in the {@link UniverseSetupScreen}, it's passed to
* this screen instead of using the old Context.
* @param subContext the new environment created in {@link UniverseSetupScreen}
* @param worldSelected the world whose configurations are to be changed.
* @throws UnresolvedWorldGeneratorException
*/
Expand Down
Expand Up @@ -59,7 +59,6 @@
import org.terasology.rendering.nui.widgets.UIList;
import org.terasology.rendering.nui.widgets.UIText;
import org.terasology.utilities.random.FastRandom;
import org.terasology.world.generator.UnresolvedWorldGeneratorException;
import org.terasology.world.generator.internal.WorldGeneratorManager;

import java.util.ArrayList;
Expand Down
Expand Up @@ -22,7 +22,7 @@

/**
* This class only has significance during the create game phase.
* Every world is a object of this class.
* Every world is an object of this class.
*/
public class WorldSetupWrapper {

Expand Down