Skip to content

Commit

Permalink
refactor: merge universe setup into world pregen screen (#5122)
Browse files Browse the repository at this point in the history
Merging UniverseSetupScreen and WorldPreGenerationScreen incl.
* merging .ui representations
* merging .java classes
* merge widget bindings and screen logic
* merge WorldSetupWrapper into UniverseWrapper
* using UniverseWrapper instead of local copies of target world and seed for persisting state
* binding UI widgets to persisted state
* use universe seed and properly randomize seed on re-roll
* remove worlds element in lower right screen section
* update preview on changing seed field content and when opening screen
* memorize modified (manually or via re-roll) seed field content (currently reset always to initial seed)

Co-authored-by: Tobias Nett <[email protected]>
  • Loading branch information
jdrueckert and skaldarnar authored Nov 13, 2023
1 parent 1b286a6 commit c237660
Show file tree
Hide file tree
Showing 15 changed files with 476 additions and 874 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public GameManifest createGameManifest() {

gameManifest.setTitle(worldGenConfig.getWorldTitle());
gameManifest.setSeed(worldGenConfig.getDefaultSeed());
WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, worldGenConfig.getWorldTitle(), gameManifest.getSeed(),
WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, gameManifest.getSeed(),
(long) (WorldTime.DAY_LENGTH * WorldTime.NOON_OFFSET), worldGeneratorUri);
gameManifest.addWorld(worldInfo);
return gameManifest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.engine.rendering.nui.layers.mainMenu;

import com.google.common.collect.Maps;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -13,16 +12,14 @@
import org.terasology.engine.game.GameManifest;
import org.terasology.engine.registry.In;
import org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameProvider;
import org.terasology.engine.rendering.world.WorldSetupWrapper;
import org.terasology.engine.world.generator.WorldConfigurator;
import org.terasology.engine.world.generator.WorldGenerator;
import org.terasology.engine.world.internal.WorldInfo;
import org.terasology.engine.world.time.WorldTime;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.gestalt.module.Module;
import org.terasology.gestalt.module.dependencyresolution.DependencyResolver;
import org.terasology.gestalt.module.dependencyresolution.ResolutionResult;

import java.util.Map;

/**
* Generates new games manifest according to input data.
*/
Expand Down Expand Up @@ -67,30 +64,25 @@ public static GameManifest createGameManifest(final UniverseWrapper universeWrap

SimpleUri uri;
String seed;
WorldSetupWrapper worldSetup = universeWrapper.getTargetWorld();
if (worldSetup != null) {
uri = worldSetup.getWorldGenerator().getUri();
seed = worldSetup.getWorldGenerator().getWorldSeed();
WorldGenerator worldGenerator = universeWrapper.getWorldGenerator();
if (worldGenerator != null) {
uri = worldGenerator.getUri();
seed = worldGenerator.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());
}
WorldConfigurator worldConfigurator = universeWrapper.getWorldConfigurator();
if (worldConfigurator != 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, worldConfigurator.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,
WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, seed,
(long) (WorldTime.DAY_LENGTH * WorldTime.SUNRISE_OFFSET), uri);

gameManifest.addWorld(worldInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public String get() {
AdvancedGameSetupScreen advancedSetupGameScreen = getManager().createScreen(AdvancedGameSetupScreen.ASSET_URI, AdvancedGameSetupScreen.class);
WidgetUtil.trySubscribe(this, "advancedSetup", button -> {
universeWrapper.setGameName(gameName.getText());
advancedSetupGameScreen.setUniverseWrapper(universeWrapper);
advancedSetupGameScreen.setEnvironment(universeWrapper);
triggerForwardAnimation(advancedSetupGameScreen);
});

Expand Down Expand Up @@ -281,12 +281,10 @@ public void setUniverseWrapper(UniverseWrapper wrapper) {

@Override
public boolean onKeyEvent(NUIKeyEvent event) {
if (event.isDown() && event.getKey() == Keyboard.Key.ESCAPE) {
if (GameProvider.isSavesFolderEmpty()) {
// skip selectGameScreen and get back directly to main screen
getManager().pushScreen("engine:mainMenuScreen");
return true;
}
if (event.isDown() && event.getKey() == Keyboard.Key.ESCAPE && GameProvider.isSavesFolderEmpty()) {
// skip selectGameScreen and get back directly to main screen
getManager().pushScreen("engine:mainMenuScreen");
return true;
}
return super.onKeyEvent(event);
}
Expand Down
Loading

0 comments on commit c237660

Please sign in to comment.