-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disable buttons which are not ready yet, and add default generator
- Loading branch information
ar0ne
committed
Jun 27, 2018
1 parent
3be9575
commit 64fe6dd
Showing
7 changed files
with
134 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
engine/src/main/java/org/terasology/rendering/nui/layers/mainMenu/NewGameSetupHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2018 MovingBlocks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.terasology.rendering.nui.layers.mainMenu; | ||
|
||
import org.codehaus.plexus.util.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.terasology.config.Config; | ||
import org.terasology.engine.SimpleUri; | ||
import org.terasology.engine.TerasologyConstants; | ||
import org.terasology.engine.module.ModuleManager; | ||
import org.terasology.game.GameManifest; | ||
import org.terasology.module.DependencyResolver; | ||
import org.terasology.module.Module; | ||
import org.terasology.module.ResolutionResult; | ||
import org.terasology.rendering.nui.layers.mainMenu.savedGames.GameProvider; | ||
import org.terasology.utilities.random.FastRandom; | ||
import org.terasology.world.internal.WorldInfo; | ||
import org.terasology.world.time.WorldTime; | ||
|
||
|
||
/** | ||
* @TODO: rename?, add more methods for different screens and cases? | ||
*/ | ||
public class NewGameSetupHelper { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(NewGameSetupHelper.class); | ||
|
||
private NewGameSetupHelper() { | ||
} | ||
|
||
public static GameManifest buildNewGameSetup(final UniverseWrapper universeWrapper, final ModuleManager moduleManager, final Config config) { | ||
GameManifest gameManifest = new GameManifest(); | ||
if (StringUtils.isNotBlank(universeWrapper.getGameName())) { | ||
gameManifest.setTitle(universeWrapper.getGameName()); | ||
} else { | ||
gameManifest.setTitle(GameProvider.getNextGameName()); | ||
} | ||
|
||
String seed; | ||
if (StringUtils.isNotBlank(universeWrapper.getSeed())) { | ||
seed = universeWrapper.getSeed(); | ||
} else { | ||
seed = new FastRandom().nextString(32); | ||
} | ||
gameManifest.setSeed(seed); | ||
|
||
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 = 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. | ||
final float timeOffset = 0.50f; | ||
WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, seed, | ||
(long) (WorldTime.DAY_LENGTH * timeOffset), uri); | ||
|
||
|
||
gameManifest.addWorld(worldInfo); | ||
return gameManifest; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters