diff --git a/OpenRA.Mods.Common/Traits/World/ClearMapGenerator.cs b/OpenRA.Mods.Common/Traits/World/ClearMapGenerator.cs index a544951300..b806b708d5 100644 --- a/OpenRA.Mods.Common/Traits/World/ClearMapGenerator.cs +++ b/OpenRA.Mods.Common/Traits/World/ClearMapGenerator.cs @@ -19,9 +19,9 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - [TraitLocation(SystemActors.World | SystemActors.EditorWorld)] + [TraitLocation(SystemActors.EditorWorld)] [Desc("A map generator that clears a map.")] - public sealed class ClearMapGeneratorInfo : TraitInfo, IMapGeneratorInfo + public sealed class ClearMapGeneratorInfo : TraitInfo, IMapGeneratorInfo { [FieldLoader.Require] [Desc("Human-readable name this generator uses.")] @@ -44,8 +44,6 @@ namespace OpenRA.Mods.Common.Traits string IMapGeneratorInfo.Name => Name; - public override object Create(ActorInitializer init) { return new ClearMapGenerator(this); } - static MiniYaml SettingsLoader(MiniYaml my) { return my.NodeWithKey("Settings").Value; @@ -55,22 +53,10 @@ namespace OpenRA.Mods.Common.Traits { return MapGeneratorSettings.DumpFluent(my.NodeWithKey("Settings").Value); } - } - - public sealed class ClearMapGenerator : IMapGenerator - { - readonly ClearMapGeneratorInfo info; - - IMapGeneratorInfo IMapGenerator.Info => info; - - public ClearMapGenerator(ClearMapGeneratorInfo info) - { - this.info = info; - } public MapGeneratorSettings GetSettings(Map map) { - return MapGeneratorSettings.LoadSettings(info.Settings, map); + return MapGeneratorSettings.LoadSettings(Settings, map); } public void Generate(Map map, MiniYaml settings) @@ -112,4 +98,6 @@ namespace OpenRA.Mods.Common.Traits map.ActorDefinitions = ImmutableArray.Empty; } } + + public class ClearMapGenerator { /* we're only interested in the Info */ } } diff --git a/OpenRA.Mods.Common/Traits/World/RaMapGenerator.cs b/OpenRA.Mods.Common/Traits/World/RaMapGenerator.cs index eecfe8c013..7bcba1796e 100644 --- a/OpenRA.Mods.Common/Traits/World/RaMapGenerator.cs +++ b/OpenRA.Mods.Common/Traits/World/RaMapGenerator.cs @@ -22,8 +22,8 @@ using static OpenRA.Mods.Common.Traits.ResourceLayerInfo; namespace OpenRA.Mods.Common.Traits { - [TraitLocation(SystemActors.World | SystemActors.EditorWorld)] - public sealed class RaMapGeneratorInfo : TraitInfo, IMapGeneratorInfo + [TraitLocation(SystemActors.EditorWorld)] + public sealed class RaMapGeneratorInfo : TraitInfo, IMapGeneratorInfo { [FieldLoader.Require] public readonly string Type = null; @@ -43,8 +43,6 @@ namespace OpenRA.Mods.Common.Traits string IMapGeneratorInfo.Type => Type; string IMapGeneratorInfo.Name => Name; - public override object Create(ActorInitializer init) { return new RaMapGenerator(this); } - static MiniYaml SettingsLoader(MiniYaml my) { return my.NodeWithKey("Settings").Value; @@ -54,10 +52,7 @@ namespace OpenRA.Mods.Common.Traits { return MapGeneratorSettings.DumpFluent(my.NodeWithKey("Settings").Value); } - } - public sealed class RaMapGenerator : IMapGenerator - { const int FractionMax = 1000; const int EntityBonusMax = 1000000; @@ -486,18 +481,9 @@ namespace OpenRA.Mods.Common.Traits } } - readonly RaMapGeneratorInfo info; - - IMapGeneratorInfo IMapGenerator.Info => info; - - public RaMapGenerator(RaMapGeneratorInfo info) - { - this.info = info; - } - public MapGeneratorSettings GetSettings(Map map) { - return MapGeneratorSettings.LoadSettings(info.Settings, map); + return MapGeneratorSettings.LoadSettings(Settings, map); } public void Generate(Map map, MiniYaml settings) @@ -1815,4 +1801,6 @@ namespace OpenRA.Mods.Common.Traits return amplitude; } } + + public class RaMapGenerator { /* we're only interested in the Info */ } } diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 7275b661fb..4ed8fddc29 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -973,10 +973,7 @@ namespace OpenRA.Mods.Common.Traits { string Type { get; } string Name { get; } - } - public interface IMapGenerator - { /// /// Get the generator settings available for this map. /// Returns null if not compatible with the given map. @@ -993,7 +990,5 @@ namespace OpenRA.Mods.Common.Traits /// Thrown if the map could not be generated with the requested configuration. Map should be discarded. /// void Generate(Map map, MiniYaml settings); - - IMapGeneratorInfo Info { get; } } } diff --git a/OpenRA.Mods.Common/UtilityCommands/FuzzMapGeneratorCommand.cs b/OpenRA.Mods.Common/UtilityCommands/FuzzMapGeneratorCommand.cs index 21ce74f91a..a2c45f6d94 100644 --- a/OpenRA.Mods.Common/UtilityCommands/FuzzMapGeneratorCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/FuzzMapGeneratorCommand.cs @@ -16,7 +16,6 @@ using System.Globalization; using System.Linq; using System.Text; using OpenRA.Mods.Common.Traits; -using OpenRA.Traits; namespace OpenRA.Mods.Common.UtilityCommands { @@ -205,14 +204,12 @@ namespace OpenRA.Mods.Common.UtilityCommands .Select(variable => config.Choices[variable].Length) .ToImmutableArray(); - var generatorInfo = + var generator = modData.DefaultRules.Actors[SystemActors.EditorWorld].TraitInfos() .FirstOrDefault(info => info.Type == config.MapGeneratorType); - if (generatorInfo == null) + if (generator == null) throw new ArgumentException($"No map generator with type `{config.MapGeneratorType}`"); - var generator = (generatorInfo as TraitInfo).Create(null) as IMapGenerator; - long maxSerial = 1; long tests = 0; long failures = 0; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapGeneratorToolLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapGeneratorToolLogic.cs index 025aba87dd..a45edcae2e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapGeneratorToolLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapGeneratorToolLogic.cs @@ -40,10 +40,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly ModData modData; // nullable - IMapGenerator selectedGenerator; + IMapGeneratorInfo selectedGenerator; - readonly Dictionary generatorsToSettings; - readonly Dictionary> generatorsToSettingsChoices; + readonly Dictionary generatorsToSettings; + readonly Dictionary> generatorsToSettingsChoices; readonly ScrollPanelWidget settingsPanel; readonly Widget checkboxSettingTemplate; @@ -60,11 +60,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic this.modData = modData; selectedGenerator = null; - generatorsToSettings = new Dictionary(); - generatorsToSettingsChoices = new Dictionary>(); + generatorsToSettings = new Dictionary(); + generatorsToSettingsChoices = new Dictionary>(); - var mapGenerators = new List(); - foreach (var generator in world.WorldActor.TraitsImplementing()) + var mapGenerators = new List(); + foreach (var generator in world.Map.Rules.Actors[SystemActors.EditorWorld].TraitInfos()) { var settings = generator.GetSettings(world.Map); if (settings == null) @@ -91,18 +91,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic }; var generatorDropDown = widget.Get("GENERATOR"); - ChangeGenerator(mapGenerators.FirstOrDefault((IMapGenerator)null)); + ChangeGenerator(mapGenerators.FirstOrDefault()); if (selectedGenerator != null) { - generatorDropDown.GetText = () => FluentProvider.GetMessage(selectedGenerator.Info.Name); + generatorDropDown.GetText = () => FluentProvider.GetMessage(selectedGenerator.Name); generatorDropDown.OnMouseDown = _ => { - ScrollItemWidget SetupItem(IMapGenerator g, ScrollItemWidget template) + ScrollItemWidget SetupItem(IMapGeneratorInfo g, ScrollItemWidget template) { - bool IsSelected() => g.Info.Type == selectedGenerator.Info.Type; - void OnClick() => ChangeGenerator(mapGenerators.First(generator => generator.Info.Type == g.Info.Type)); + bool IsSelected() => g.Type == selectedGenerator.Type; + void OnClick() => ChangeGenerator(mapGenerators.First(generator => generator.Type == g.Type)); var item = ScrollItemWidget.Setup(template, IsSelected, OnClick); - item.Get("LABEL").GetText = () => FluentProvider.GetMessage(g.Info.Name); + item.Get("LABEL").GetText = () => FluentProvider.GetMessage(g.Name); return item; } @@ -147,7 +147,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } // newGenerator may be null. - void ChangeGenerator(IMapGenerator newGenerator) + void ChangeGenerator(IMapGeneratorInfo newGenerator) { selectedGenerator = newGenerator; @@ -307,7 +307,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Run main generator logic. May throw. var generateStopwatch = Stopwatch.StartNew(); - Log.Write("debug", $"Running '{selectedGenerator.Info.Type}' map generator with settings:\n{MiniYamlExts.WriteToString(settings.Nodes)}\n\n"); + Log.Write("debug", $"Running '{selectedGenerator.Type}' map generator with settings:\n{MiniYamlExts.WriteToString(settings.Nodes)}\n\n"); selectedGenerator.Generate(generatedMap, settings); Log.Write("debug", $"Generator finished, taking {generateStopwatch.ElapsedMilliseconds}ms"); @@ -354,7 +354,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic false); var description = FluentProvider.GetMessage(StrGenerated, - "name", FluentProvider.GetMessage(selectedGenerator.Info.Name)); + "name", FluentProvider.GetMessage(selectedGenerator.Name)); var action = new RandomMapEditorAction(editorBlit, description); editorActionManager.Add(action); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs index 06e336063c..239e542d27 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapToolsLogic.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Widgets; @@ -48,7 +47,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var markerToolPanel = widget.Get("MARKER_TOOL_PANEL"); toolPanels.Add(MapTool.MarkerTiles, markerToolPanel); - if (world.WorldActor.TraitsImplementing().Any()) + if (world.Map.Rules.Actors[SystemActors.EditorWorld].HasTraitInfo()) { var mapGeneratorToolPanel = widget.GetOrNull("MAP_GENERATOR_TOOL_PANEL"); if (mapGeneratorToolPanel != null)