diff --git a/OpenRA.Mods.Common/MapGenerator/MapGeneratorSettings.cs b/OpenRA.Mods.Common/MapGenerator/MapGeneratorSettings.cs index 5b9fa0beb2..f0bb425ea9 100644 --- a/OpenRA.Mods.Common/MapGenerator/MapGeneratorSettings.cs +++ b/OpenRA.Mods.Common/MapGenerator/MapGeneratorSettings.cs @@ -208,6 +208,11 @@ namespace OpenRA.Mods.Common.MapGenerator public sealed class MapGeneratorSettings : IMapGeneratorSettings { + sealed class MapGenerationArgsWithOptions : MapGenerationArgs + { + public Dictionary Options = []; + } + readonly IMapGeneratorInfo generatorInfo; public MapGeneratorSettings(IMapGeneratorInfo generatorInfo, MiniYaml yaml) @@ -253,6 +258,26 @@ namespace OpenRA.Mods.Common.MapGenerator } } + public void Initialize(MapGenerationArgs args) + { + if (args is MapGenerationArgsWithOptions optionArgs) + { + foreach (var o in Options) + { + if (!optionArgs.Options.TryGetValue(o.Id, out var value)) + continue; + + switch (o) + { + case MapGeneratorBooleanOption bo: bo.Value = FieldLoader.GetValue(o.Id, value); break; + case MapGeneratorIntegerOption io: io.Value = FieldLoader.GetValue(o.Id, value); break; + case MapGeneratorMultiIntegerChoiceOption mio: mio.Value = FieldLoader.GetValue(o.Id, value); break; + case MapGeneratorMultiChoiceOption mo: mo.Value = value; break; + } + } + } + } + public MapGenerationArgs Compile(ITerrainInfo terrainInfo, Size size) { // Apply the choices in their canonical order. @@ -261,14 +286,27 @@ namespace OpenRA.Mods.Common.MapGenerator .OrderBy(option => option.Priority) .Select(o => o.GetSettings(terrainInfo, playerCount)); - return new MapGenerationArgs() + var options = new Dictionary(); + foreach (var o in Options) + { + switch (o) + { + case MapGeneratorBooleanOption bo: options[o.Id] = FieldSaver.FormatValue(bo.Value); break; + case MapGeneratorIntegerOption io: options[o.Id] = FieldSaver.FormatValue(io.Value); break; + case MapGeneratorMultiIntegerChoiceOption mio: options[o.Id] = FieldSaver.FormatValue(mio.Value); break; + case MapGeneratorMultiChoiceOption mo: options[o.Id] = mo.Value; break; + } + } + + return new MapGenerationArgsWithOptions() { Generator = generatorInfo.Type, Tileset = terrainInfo.Id, Size = size, Title = FluentProvider.GetMessage(generatorInfo.MapTitle), Author = FluentProvider.GetMessage(generatorInfo.Name), - Settings = new MiniYaml(null, MiniYaml.Merge(layers)) + Settings = new MiniYaml(null, MiniYaml.Merge(layers)), + Options = options }; } } diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index a81164e3aa..dc498e4e38 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -984,6 +984,8 @@ namespace OpenRA.Mods.Common.Traits void Randomize(MersenneTwister random); + void Initialize(MapGenerationArgs args); + MapGenerationArgs Compile(ITerrainInfo terrainInfo, Size size); }