Merge ModRuleset and MapRuleset into Ruleset

This commit is contained in:
Pavlos Touboulidis
2014-05-10 10:29:26 +03:00
parent 48d1dde8a7
commit 750fc4e02c
18 changed files with 54 additions and 80 deletions

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Editor
{
static class Program
{
public static MapRuleset Rules;
public static Ruleset Rules;
[STAThread]
static void Main(string[] args)

View File

@@ -36,30 +36,12 @@ namespace OpenRA
this.modData = modData;
}
public ModRuleset LoadModRules()
{
var m = modData.Manifest;
Dictionary<string, MusicInfo> music;
Dictionary<string, string> movies;
Dictionary<string, TileSet> tileSets;
using (new PerfTimer("Music"))
music = LoadYamlRules(musicCache, m.Music, new List<MiniYamlNode>(), (k, _) => new MusicInfo(k.Key, k.Value));
using (new PerfTimer("Movies"))
movies = LoadYamlRules(movieCache, m.Movies, new List<MiniYamlNode>(), (k, v) => k.Value.Value);
using (new PerfTimer("TileSets"))
tileSets = LoadTileSets(tileSetCache, m.TileSets);
return new ModRuleset(music, movies, tileSets);
}
public MapRuleset LoadDefaultRules()
public Ruleset LoadDefaultRules()
{
return LoadMapRules(new Map());
}
public MapRuleset LoadMapRules(Map map)
public Ruleset LoadMapRules(Map map)
{
var m = modData.Manifest;
@@ -67,6 +49,9 @@ namespace OpenRA
Dictionary<string, WeaponInfo> weapons;
Dictionary<string, SoundInfo> voices;
Dictionary<string, SoundInfo> notifications;
Dictionary<string, MusicInfo> music;
Dictionary<string, string> movies;
Dictionary<string, TileSet> tileSets;
OnProgress();
using (new PerfTimer("Actors"))
@@ -80,9 +65,18 @@ namespace OpenRA
OnProgress();
using (new PerfTimer("Notifications"))
notifications = LoadYamlRules(notificationCache, m.Notifications, map.NotificationDefinitions, (k, _) => new SoundInfo(k.Value));
OnProgress();
using (new PerfTimer("Music"))
music = LoadYamlRules(musicCache, m.Music, new List<MiniYamlNode>(), (k, _) => new MusicInfo(k.Key, k.Value));
OnProgress();
using (new PerfTimer("Movies"))
movies = LoadYamlRules(movieCache, m.Movies, new List<MiniYamlNode>(), (k, v) => k.Value.Value);
OnProgress();
using (new PerfTimer("TileSets"))
tileSets = LoadTileSets(tileSetCache, m.TileSets);
OnProgress();
return new MapRuleset(LoadModRules(), actors, weapons, voices, notifications);
return new Ruleset(actors, weapons, voices, notifications, music, movies, tileSets);
}
Dictionary<string, T> LoadYamlRules<T>(

View File

@@ -111,8 +111,8 @@ namespace OpenRA
[FieldLoader.Ignore] public Lazy<TileReference<byte, byte>[,]> MapResources;
[FieldLoader.Ignore] public string[,] CustomTerrain;
[FieldLoader.Ignore] Lazy<MapRuleset> rules;
public MapRuleset Rules { get { return rules != null ? rules.Value : null; } }
[FieldLoader.Ignore] Lazy<Ruleset> rules;
public Ruleset Rules { get { return rules != null ? rules.Value : null; } }
public SequenceProvider SequenceProvider { get; private set; }
public static Map FromTileset(TileSet tileset)
@@ -249,7 +249,7 @@ namespace OpenRA
SequenceProvider = new SequenceProvider(this);
}
public MapRuleset PreloadRules()
public Ruleset PreloadRules()
{
return rules.Value;
}
@@ -508,7 +508,7 @@ namespace OpenRA
});
}
public void FixOpenAreas(MapRuleset rules)
public void FixOpenAreas(Ruleset rules)
{
var r = new Random();
var tileset = rules.TileSets[Tileset];

View File

@@ -149,7 +149,7 @@ namespace OpenRA
// the next render cycle.
// (d) Any partially written bytes from the next minimap is in an
// unallocated area, and will be committed in the next cycle.
var bitmap = p.CustomPreview ?? Minimap.RenderMapPreview(modData.ModRules.TileSets[p.Map.Tileset], p.Map, true);
var bitmap = p.CustomPreview ?? Minimap.RenderMapPreview(modData.DefaultRules.TileSets[p.Map.Tileset], p.Map, true);
p.Minimap = sheetBuilder.Add(bitmap);
lock (syncRoot)

View File

@@ -15,24 +15,29 @@ using OpenRA.GameRules;
namespace OpenRA
{
public class ModRuleset
public class Ruleset
{
public readonly IReadOnlyDictionary<string, ActorInfo> Actors;
public readonly IReadOnlyDictionary<string, WeaponInfo> Weapons;
public readonly IReadOnlyDictionary<string, SoundInfo> Voices;
public readonly IReadOnlyDictionary<string, SoundInfo> Notifications;
public readonly IReadOnlyDictionary<string, MusicInfo> Music;
public readonly IReadOnlyDictionary<string, string> Movies;
public readonly IReadOnlyDictionary<string, TileSet> TileSets;
public ModRuleset(ModRuleset other)
{
this.Music = other.Music;
this.Movies = other.Movies;
this.TileSets = other.TileSets;
}
public ModRuleset(
public Ruleset(
IDictionary<string, ActorInfo> actors,
IDictionary<string, WeaponInfo> weapons,
IDictionary<string, SoundInfo> voices,
IDictionary<string, SoundInfo> notifications,
IDictionary<string, MusicInfo> music,
IDictionary<string, string> movies,
IDictionary<string, TileSet> tileSets)
{
this.Actors = new ReadOnlyDictionary<string, ActorInfo>(actors);
this.Weapons = new ReadOnlyDictionary<string, WeaponInfo>(weapons);
this.Voices = new ReadOnlyDictionary<string, SoundInfo>(voices);
this.Notifications = new ReadOnlyDictionary<string, SoundInfo>(notifications);
this.Music = new ReadOnlyDictionary<string, MusicInfo>(music);
this.Movies = new ReadOnlyDictionary<string, string>(movies);
this.TileSets = new ReadOnlyDictionary<string, TileSet>(tileSets);
@@ -40,26 +45,4 @@ namespace OpenRA
public IEnumerable<KeyValuePair<string, MusicInfo>> InstalledMusic { get { return Music.Where(m => m.Value.Exists); } }
}
public class MapRuleset : ModRuleset
{
public readonly IReadOnlyDictionary<string, ActorInfo> Actors;
public readonly IReadOnlyDictionary<string, WeaponInfo> Weapons;
public readonly IReadOnlyDictionary<string, SoundInfo> Voices;
public readonly IReadOnlyDictionary<string, SoundInfo> Notifications;
public MapRuleset(
ModRuleset modRuleset,
IDictionary<string, ActorInfo> actors,
IDictionary<string, WeaponInfo> weapons,
IDictionary<string, SoundInfo> voices,
IDictionary<string, SoundInfo> notifications)
: base(modRuleset)
{
this.Actors = new ReadOnlyDictionary<string, ActorInfo>(actors);
this.Weapons = new ReadOnlyDictionary<string, WeaponInfo>(weapons);
this.Voices = new ReadOnlyDictionary<string, SoundInfo>(voices);
this.Notifications = new ReadOnlyDictionary<string, SoundInfo>(notifications);
}
}
}

View File

@@ -29,10 +29,8 @@ namespace OpenRA
public readonly RulesetCache RulesetCache;
public CursorProvider CursorProvider { get; private set; }
Lazy<ModRuleset> modRules;
public ModRuleset ModRules { get { return modRules.Value; } }
Lazy<MapRuleset> defaultRules;
public MapRuleset DefaultRules { get { return defaultRules.Value; } }
Lazy<Ruleset> defaultRules;
public Ruleset DefaultRules { get { return defaultRules.Value; } }
public ModData(string mod)
{
@@ -51,7 +49,6 @@ namespace OpenRA
foreach (var dir in Manifest.Folders)
GlobalFileSystem.Mount(dir);
modRules = Exts.Lazy(() => RulesetCache.LoadModRules());
defaultRules = Exts.Lazy(() => RulesetCache.LoadDefaultRules());
}

View File

@@ -296,7 +296,7 @@ namespace OpenRA
}
// Returns true if played successfully
public static bool PlayPredefined(MapRuleset ruleset, Player p, Actor voicedUnit, string type, string definition, string variant, bool relative, WPos pos, float volumeModifier, bool attenuateVolume)
public static bool PlayPredefined(Ruleset ruleset, Player p, Actor voicedUnit, string type, string definition, string variant, bool relative, WPos pos, float volumeModifier, bool attenuateVolume)
{
if (ruleset == null)
throw new ArgumentNullException("ruleset");

View File

@@ -55,10 +55,10 @@ namespace OpenRA.Widgets
public Action OnDoubleClick = () => {};
public Action<KeyInput> OnKeyPress = _ => {};
readonly MapRuleset rules;
readonly Ruleset rules;
[ObjectCreator.UseCtor]
public ButtonWidget(MapRuleset rules)
public ButtonWidget(Ruleset rules)
{
this.rules = rules;

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Widgets
public bool HasPressedState = ChromeMetrics.Get<bool>("CheckboxPressedState");
[ObjectCreator.UseCtor]
public CheckboxWidget(MapRuleset rules)
public CheckboxWidget(Ruleset rules)
: base(rules)
{
GetCheckType = () => CheckType;

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Widgets
MaskWidget fullscreenMask;
[ObjectCreator.UseCtor]
public DropDownButtonWidget(MapRuleset rules)
public DropDownButtonWidget(Ruleset rules)
: base(rules) { }
protected DropDownButtonWidget(DropDownButtonWidget widget) : base(widget) { }

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Widgets
public string BaseName = "scrollitem";
[ObjectCreator.UseCtor]
public ScrollItemWidget(MapRuleset rules)
public ScrollItemWidget(Ruleset rules)
: base(rules)
{
IsVisible = () => false;

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
public class CncInstallMusicLogic
{
[ObjectCreator.UseCtor]
public CncInstallMusicLogic(Widget widget, MapRuleset rules, Action onExit)
public CncInstallMusicLogic(Widget widget, Ruleset rules, Action onExit)
{
var installButton = widget.GetOrNull<ButtonWidget>("INSTALL_BUTTON");
if (installButton != null)

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
public class ProductionTooltipLogic
{
[ObjectCreator.UseCtor]
public ProductionTooltipLogic(Widget widget, MapRuleset rules, TooltipContainerWidget tooltipContainer, ProductionPaletteWidget palette)
public ProductionTooltipLogic(Widget widget, Ruleset rules, TooltipContainerWidget tooltipContainer, ProductionPaletteWidget palette)
{
var pm = palette.World.LocalPlayer.PlayerActor.Trait<PowerManager>();
var pr = palette.World.LocalPlayer.PlayerActor.Trait<PlayerResources>();
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
};
}
static string ActorName(MapRuleset rules, string a)
static string ActorName(Ruleset rules, string a)
{
ActorInfo ai;
if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai) && ai.Traits.Contains<TooltipInfo>())

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Cnc.Widgets
public readonly string ProductionGroup;
[ObjectCreator.UseCtor]
public ProductionTypeButtonWidget(MapRuleset rules)
public ProductionTypeButtonWidget(Ruleset rules)
: base(rules) { }
protected ProductionTypeButtonWidget(ProductionTypeButtonWidget other)

View File

@@ -16,7 +16,7 @@ namespace OpenRA.Mods.RA.Buildings
{
public static class FootprintUtils
{
public static IEnumerable<CPos> Tiles(MapRuleset rules, string name, BuildingInfo buildingInfo, CPos topLeft)
public static IEnumerable<CPos> Tiles(Ruleset rules, string name, BuildingInfo buildingInfo, CPos topLeft)
{
var dim = (CVec)buildingInfo.Dimensions;

View File

@@ -337,7 +337,7 @@ namespace OpenRA.Mods.RA.Widgets
};
}
static string Description(MapRuleset rules, string a)
static string Description(Ruleset rules, string a)
{
ActorInfo ai;
rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai);

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
}
}
public static void ShowSlotDropDown(MapRuleset rules, DropDownButtonWidget dropdown, Session.Slot slot,
public static void ShowSlotDropDown(Ruleset rules, DropDownButtonWidget dropdown, Session.Slot slot,
Session.Client client, OrderManager orderManager)
{
var options = new Dictionary<string, IEnumerable<SlotDropDownOption>>() {{"Slot", new List<SlotDropDownOption>()
@@ -280,7 +280,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
name.GetText = () => c.Name;
}
public static void SetupEditableSlotWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapRuleset rules)
public static void SetupEditableSlotWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, Ruleset rules)
{
var slot = parent.Get<DropDownButtonWidget>("SLOT_OPTIONS");
slot.IsVisible = () => true;

View File

@@ -107,18 +107,18 @@ namespace OpenRA.Utility
int mapSize;
int actorCount = 0;
Map map = new Map();
MapRuleset rules;
Ruleset rules;
List<string> players = new List<string>();
Action<string> errorHandler;
LegacyMapImporter(string filename, MapRuleset rules, Action<string> errorHandler)
LegacyMapImporter(string filename, Ruleset rules, Action<string> errorHandler)
{
this.rules = rules;
this.errorHandler = errorHandler;
ConvertIniMap(filename);
}
public static Map Import(string filename, MapRuleset rules, Action<string> errorHandler)
public static Map Import(string filename, Ruleset rules, Action<string> errorHandler)
{
var converter = new LegacyMapImporter(filename, rules, errorHandler);
return converter.map;