Skip to content

Commit

Permalink
Fix map generator biome styles and non round map sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Jun 15, 2024
1 parent f316fd5 commit 5c8ff69
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ private void setPreviewFolder(Path previewFolder) throws IOException {
this.previewFolder = previewFolder;
}

@Command(name = "biomes", aliases = {
"--biomes"}, description = "DEPRECATED", versionProvider = VersionProvider.class, usageHelpAutoWidth = true)
private void printBiomes() {}

@Command(name = "styles", aliases = {
"--styles"}, description = "Prints the map styles available", versionProvider = VersionProvider.class, usageHelpAutoWidth = true)
private void printStyles() {
Expand Down Expand Up @@ -371,15 +375,15 @@ private void setStyleAndParameters(GeneratorParameters.GeneratorParametersBuilde
return new WeightedOption<>(styleGenerator, mapStyle.getWeight());
}).toArray(WeightedOption[]::new);
Map<Class<? extends StyleGenerator>, MapStyle> styleMap = Arrays.stream(MapStyle.values())
.collect(Collectors.toMap(
MapStyle::getGeneratorClass,
Function.identity()));
.collect(Collectors.toMap(
MapStyle::getGeneratorClass,
Function.identity()));
WeightedOptionsWithFallback<StyleGenerator> styleGeneratorOptions = WeightedOptionsWithFallback.of(
new BasicStyleGenerator(), generatorOptions);
styleGenerator = styleGeneratorOptions.select(random,
styleGenerator -> styleGenerator.getParameterConstraints()
.matches(
generatorParameters));
styleGenerator -> styleGenerator.getParameterConstraints()
.matches(
generatorParameters));
styleOptions.setMapStyle(styleMap.get(styleGenerator.getClass()));
}
} else {
Expand All @@ -393,7 +397,9 @@ private void setCustomStyle() {
ResourceStyle resourceStyle = ResourceStyle.values()[random.nextInt(ResourceStyle.values().length)];
PropStyle propStyle = PropStyle.values()[random.nextInt(PropStyle.values().length)];

CustomStyleOptions customStyleOptions = generationOptions.getCasualOptions().getStyleOptions().getCustomStyleOptions();
CustomStyleOptions customStyleOptions = generationOptions.getCasualOptions()
.getStyleOptions()
.getCustomStyleOptions();
if (customStyleOptions.getTextureStyle() == null) {
customStyleOptions.setTextureStyle(textureStyle);
}
Expand Down Expand Up @@ -426,8 +432,7 @@ private void encodeMapName() {
String seedString = GeneratedMapNameEncoder.encode(seedBuffer.array());
byte[] optionArray;
StyleOptions styleOptions = generationOptions.getCasualOptions().getStyleOptions();
if (styleOptions.getCustomStyleOptions() != null)
{
if (styleOptions.getCustomStyleOptions() != null) {
optionArray = new byte[]{(byte) generatorParameters.spawnCount(),
(byte) (generatorParameters.mapSize() / 64),
(byte) generatorParameters.numTeams(),
Expand All @@ -447,8 +452,8 @@ private void encodeMapName() {
(byte) generatorParameters.numTeams(),
(byte) generatorParameters.terrainSymmetry().ordinal(),
(byte) styleOptions
.getMapStyle()
.ordinal()};
.getMapStyle()
.ordinal()};
} else {
optionArray = new byte[]{(byte) generatorParameters.spawnCount(),
(byte) (generatorParameters.mapSize() / 64),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.faforever.neroxis.util.Pipeline;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
Expand Down Expand Up @@ -42,7 +41,7 @@

@Execution(ExecutionMode.SAME_THREAD)
public class MapGeneratorTest {
public static final int NUM_DETERMINISM_REPEATS = 10;
public static final int NUM_DETERMINISM_REPEATS = 5;
String mapName = "neroxis_map_generator_snapshot_aaaaaaaaaacne_aicaedyaaeaqe";
long seed = 1234;
byte spawnCount = 2;
Expand Down Expand Up @@ -74,7 +73,10 @@ public void TestParseMapName() {
assertEquals(instance.getBasicOptions().getSeed(), seed);
assertEquals(instance.getOutputFolderMixin().getOutputPath(), Path.of("."));
GeneratorParameters generatorParameters = instance.getGeneratorParameters();
CustomStyleOptions customStyleOptions = instance.getGenerationOptions().getCasualOptions().getStyleOptions().getCustomStyleOptions();
CustomStyleOptions customStyleOptions = instance.getGenerationOptions()
.getCasualOptions()
.getStyleOptions()
.getCustomStyleOptions();

assertEquals(instance.getStyleGenerator().getClass(), CustomStyleGenerator.class);
assertEquals(customStyleOptions.getTerrainStyle(), terrainStyle);
Expand All @@ -88,7 +90,6 @@ public void TestParseMapName() {

@ParameterizedTest
@ArgumentsSource(ValidMapSizeArgumentProvider.class)
@Disabled("OOM")
public void TestMapExportedToProperSize(int mapSize) {
new CommandLine(instance).execute("--map-size", String.valueOf(mapSize));

Expand Down Expand Up @@ -403,7 +404,7 @@ public void TestEqualityTextureGeneratorSpecified(TextureStyle textureStyle) {
instance = new MapGenerator();

new CommandLine(instance).execute("--texture-style", textureStyle.toString(), "--map-size",
"256");
"256");
SCMap map1 = instance.getMap();
String mapName = instance.getMapName();
long generationTime1 = instance.getGenerationTime();
Expand Down Expand Up @@ -576,7 +577,7 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
private static class ValidMapSizeArgumentProvider implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return IntStream.iterate(128, size -> size < 2048, size -> size + 64).mapToObj(Arguments::of);
return IntStream.iterate(128, size -> size < 512, size -> size + 64).mapToObj(Arguments::of);
}
}

Expand Down
4 changes: 0 additions & 4 deletions shared/src/main/java/com/faforever/neroxis/map/Army.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ public class Army {
private final String id;
private final List<Group> groups = new ArrayList<>();

public List<Group> getGroups() {
return List.copyOf(groups);
}

public Group getGroup(String id) {
return groups.stream().filter(group -> group.getId().equals(id)).findFirst().orElse(null);
}
Expand Down
4 changes: 0 additions & 4 deletions shared/src/main/java/com/faforever/neroxis/map/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ public class Group {
private final String id;
private final List<Unit> units = new ArrayList<>();

public List<Unit> getUnits() {
return List.copyOf(units);
}

public Unit getUnit(String id) {
return units.stream().filter(unit -> unit.getId().equals(id)).findFirst().orElse(null);
}
Expand Down

0 comments on commit 5c8ff69

Please sign in to comment.