Skip to content

Commit

Permalink
Change generator UI for the new map generator version (#3187)
Browse files Browse the repository at this point in the history
* Prepare client for the new map generator options

* Fix tests

* Adjust GenerateMapController tests

* Minor UI fixes

* Rename generators to styles

* Don't allow mutually exclusive options

* Improve header padding
  • Loading branch information
BlackYps committed Jun 15, 2024
1 parent 3deeb92 commit d26aaa4
Show file tree
Hide file tree
Showing 13 changed files with 675 additions and 990 deletions.
25 changes: 22 additions & 3 deletions src/main/java/com/faforever/client/game/CreateGameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,34 @@ public void onRandomMapButtonClicked() {
public void onGenerateMapButtonClicked() {
GenerateMapController generateMapController = uiService.loadFxml("theme/play/generate_map.fxml");
mapGeneratorService.getNewestGenerator()
.then(Mono.defer(() -> Mono.when(mapGeneratorService.getGeneratorStyles()
.then(Mono.defer(() -> Mono.when(mapGeneratorService.getGeneratorSymmetries()
.publishOn(
fxApplicationThreadExecutor.asScheduler())
.doOnNext(generateMapController::setSymmetries),
mapGeneratorService.getGeneratorStyles()
.publishOn(
fxApplicationThreadExecutor.asScheduler())
.doOnNext(generateMapController::setStyles),
mapGeneratorService.getGeneratorBiomes()
mapGeneratorService.getGeneratorTerrainStyles()
.publishOn(
fxApplicationThreadExecutor.asScheduler())
.doOnNext(
generateMapController::setTerrainStyles),
mapGeneratorService.getGeneratorTextureStyles()
.publishOn(
fxApplicationThreadExecutor.asScheduler())
.doOnNext(
generateMapController::setTextureStyles),
mapGeneratorService.getGeneratorResourceStyles()
.publishOn(
fxApplicationThreadExecutor.asScheduler())
.doOnNext(
generateMapController::setResourceStyles),
mapGeneratorService.getGeneratorPropStyles()
.publishOn(
fxApplicationThreadExecutor.asScheduler())
.doOnNext(
generateMapController::setBiomes))))
generateMapController::setPropStyles))))
.publishOn(fxApplicationThreadExecutor.asScheduler())
.subscribe(null, throwable -> {
log.error("Opening map generation ui failed", throwable);
Expand Down
221 changes: 137 additions & 84 deletions src/main/java/com/faforever/client/game/GenerateMapController.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ protected String call() throws Exception {

GeneratorCommand.GeneratorCommandBuilder generatorCommandBuilder = GeneratorCommand.builder()
.version(version)
.seed(seed)
.generatorExecutableFile(generatorExecutableFile)
.javaExecutable(operatingSystem.getJavaExecutablePath())
.mapName(mapName);
Expand All @@ -67,15 +66,14 @@ protected String call() throws Exception {
generatorCommandBuilder.spawnCount(generatorOptions.spawnCount())
.numTeams(generatorOptions.numTeams())
.mapSize(generatorOptions.mapSize())
.seed(generatorOptions.seed())
.generationType(generatorOptions.generationType())
.landDensity(generatorOptions.landDensity())
.plateauDensity(generatorOptions.plateauDensity())
.mountainDensity(generatorOptions.mountainDensity())
.rampDensity(generatorOptions.rampDensity())
.mexDensity(generatorOptions.mexDensity())
.reclaimDensity(generatorOptions.reclaimDensity())
.symmetry(generatorOptions.symmetry())
.style(generatorOptions.style())
.biome(generatorOptions.biome())
.terrainStyle(generatorOptions.terrainStyle())
.textureStyle(generatorOptions.textureStyle())
.resourceStyle(generatorOptions.resourceStyle())
.propStyle(generatorOptions.propStyle())
.commandLineArgs(generatorOptions.commandLineArgs());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ public record GeneratorCommand(
Integer numTeams,
Integer mapSize,
String seed,
Float landDensity,
Float plateauDensity,
Float mountainDensity,
Float rampDensity,
Float mexDensity,
Float reclaimDensity,
GenerationType generationType,
String symmetry,
String style,
String biome,
String terrainStyle,
String textureStyle,
String resourceStyle,
String propStyle,
String commandLineArgs
) {

Expand Down Expand Up @@ -66,37 +64,33 @@ public List<String> getCommand() {
return command;
}

if (style != null && !style.equals(MapGeneratorService.GENERATOR_RANDOM_STYLE)) {
command.addAll(Arrays.asList("--style", style));
return command;
}

if (landDensity != null) {
command.addAll(Arrays.asList("--land-density", landDensity.toString()));
if (seed != null) {
command.addAll(Arrays.asList("--seed", seed));
}

if (mountainDensity != null) {
command.addAll(Arrays.asList("--mountain-density", mountainDensity.toString()));
if (symmetry != null && !symmetry.equals(MapGeneratorService.GENERATOR_RANDOM_OPTION)) {
command.addAll(Arrays.asList("--terrain-symmetry", symmetry));
}

if (plateauDensity != null) {
command.addAll(Arrays.asList("--plateau-density", plateauDensity.toString()));
if (style != null && !style.equals(MapGeneratorService.GENERATOR_RANDOM_OPTION)) {
command.addAll(Arrays.asList("--style", style));
return command;
}

if (rampDensity != null) {
command.addAll(Arrays.asList("--ramp-density", rampDensity.toString()));
if (terrainStyle != null && !terrainStyle.equals(MapGeneratorService.GENERATOR_RANDOM_OPTION)) {
command.addAll(Arrays.asList("--terrain-style", terrainStyle));
}

if (mexDensity != null) {
command.addAll(Arrays.asList("--mex-density", mexDensity.toString()));
if (textureStyle != null && !textureStyle.equals(MapGeneratorService.GENERATOR_RANDOM_OPTION)) {
command.addAll(Arrays.asList("--texture-style", textureStyle));
}

if (reclaimDensity != null) {
command.addAll(Arrays.asList("--reclaim-density", reclaimDensity.toString()));
if (resourceStyle != null && !resourceStyle.equals(MapGeneratorService.GENERATOR_RANDOM_OPTION)) {
command.addAll(Arrays.asList("--resource-style", resourceStyle));
}

if (biome != null && !biome.equals(MapGeneratorService.GENERATOR_RANDOM_BIOME)) {
command.addAll(Arrays.asList("--biome", biome));
if (propStyle != null && !propStyle.equals(MapGeneratorService.GENERATOR_RANDOM_OPTION)) {
command.addAll(Arrays.asList("--prop-style", propStyle));
}

return command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ public record GeneratorOptions(
Integer spawnCount,
Integer numTeams,
Integer mapSize,
Float landDensity,
Float plateauDensity,
Float mountainDensity,
Float rampDensity,
Float mexDensity,
Float reclaimDensity,
String seed,
GenerationType generationType,
String symmetry,
String style,
String biome,
String terrainStyle,
String textureStyle,
String resourceStyle,
String propStyle,
String commandLineArgs
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public class MapGeneratorService implements DisposableBean {
@VisibleForTesting
public static final String GENERATOR_EXECUTABLE_SUB_DIRECTORY = "map_generator";
public static final int GENERATION_TIMEOUT_SECONDS = 60 * 3;
public static final String GENERATOR_RANDOM_STYLE = "RANDOM";
public static final String GENERATOR_RANDOM_BIOME = "RANDOM";
public static final String GENERATOR_RANDOM_OPTION = "RANDOM";
private static final Pattern VERSION_PATTERN = Pattern.compile("\\d\\d?\\d?\\.\\d\\d?\\d?\\.\\d\\d?\\d?");
protected static final Pattern GENERATED_MAP_PATTERN = Pattern.compile("neroxis_map_generator_(" + VERSION_PATTERN + ")_(.*)");

Expand Down Expand Up @@ -178,6 +177,16 @@ public Mono<Void> getNewestGenerator() {
.flatMap(this::downloadGeneratorIfNecessary);
}

public Mono<List<String>> getGeneratorSymmetries() {
Assert.checkNullIllegalState(defaultGeneratorVersion, "Generator version not set");
GeneratorOptionsTask generatorOptionsTask = generatorOptionsTaskFactory.getObject();
Path generatorExecutablePath = getGeneratorExecutablePath(defaultGeneratorVersion);
generatorOptionsTask.setVersion(defaultGeneratorVersion);
generatorOptionsTask.setQuery("--symmetries");
generatorOptionsTask.setGeneratorExecutableFile(generatorExecutablePath);
return taskService.submitTask(generatorOptionsTask).getMono();
}

public Mono<List<String>> getGeneratorStyles() {
Assert.checkNullIllegalState(defaultGeneratorVersion, "Generator version not set");
GeneratorOptionsTask generatorOptionsTask = generatorOptionsTaskFactory.getObject();
Expand All @@ -188,12 +197,42 @@ public Mono<List<String>> getGeneratorStyles() {
return taskService.submitTask(generatorOptionsTask).getMono();
}

public Mono<List<String>> getGeneratorBiomes() {
public Mono<List<String>> getGeneratorTerrainStyles() {
Assert.checkNullIllegalState(defaultGeneratorVersion, "Generator version not set");
GeneratorOptionsTask generatorOptionsTask = generatorOptionsTaskFactory.getObject();
Path generatorExecutablePath = getGeneratorExecutablePath(defaultGeneratorVersion);
generatorOptionsTask.setVersion(defaultGeneratorVersion);
generatorOptionsTask.setQuery("--terrain-styles");
generatorOptionsTask.setGeneratorExecutableFile(generatorExecutablePath);
return taskService.submitTask(generatorOptionsTask).getMono();
}

public Mono<List<String>> getGeneratorTextureStyles() {
Assert.checkNullIllegalState(defaultGeneratorVersion, "Generator version not set");
GeneratorOptionsTask generatorOptionsTask = generatorOptionsTaskFactory.getObject();
Path generatorExecutablePath = getGeneratorExecutablePath(defaultGeneratorVersion);
generatorOptionsTask.setVersion(defaultGeneratorVersion);
generatorOptionsTask.setQuery("--texture-styles");
generatorOptionsTask.setGeneratorExecutableFile(generatorExecutablePath);
return taskService.submitTask(generatorOptionsTask).getMono();
}

public Mono<List<String>> getGeneratorResourceStyles() {
Assert.checkNullIllegalState(defaultGeneratorVersion, "Generator version not set");
GeneratorOptionsTask generatorOptionsTask = generatorOptionsTaskFactory.getObject();
Path generatorExecutablePath = getGeneratorExecutablePath(defaultGeneratorVersion);
generatorOptionsTask.setVersion(defaultGeneratorVersion);
generatorOptionsTask.setQuery("--resource-styles");
generatorOptionsTask.setGeneratorExecutableFile(generatorExecutablePath);
return taskService.submitTask(generatorOptionsTask).getMono();
}

public Mono<List<String>> getGeneratorPropStyles() {
Assert.checkNullIllegalState(defaultGeneratorVersion, "Generator version not set");
GeneratorOptionsTask generatorOptionsTask = generatorOptionsTaskFactory.getObject();
Path generatorExecutablePath = getGeneratorExecutablePath(defaultGeneratorVersion);
generatorOptionsTask.setVersion(defaultGeneratorVersion);
generatorOptionsTask.setQuery("--biomes");
generatorOptionsTask.setQuery("--prop-styles");
generatorOptionsTask.setGeneratorExecutableFile(generatorExecutablePath);
return taskService.submitTask(generatorOptionsTask).getMono();
}
Expand Down
Loading

0 comments on commit d26aaa4

Please sign in to comment.