From fc6438e3112196675a685ebfc6850c65e8bc1046 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 29 Dec 2010 19:14:48 +1300 Subject: [PATCH] Use Filepaths instead of IFolders where possible. --- OpenRA.FileFormats/Map/MapStub.cs | 9 ++++----- OpenRA.Game/Map.cs | 6 ++---- OpenRA.Game/ModData.cs | 8 +++----- OpenRA.Game/Widgets/MapPreviewWidget.cs | 2 +- OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs | 2 +- OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs | 2 +- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/OpenRA.FileFormats/Map/MapStub.cs b/OpenRA.FileFormats/Map/MapStub.cs index ea757b2135..5622cd37db 100644 --- a/OpenRA.FileFormats/Map/MapStub.cs +++ b/OpenRA.FileFormats/Map/MapStub.cs @@ -18,7 +18,8 @@ namespace OpenRA.FileFormats { public class MapStub { - public IFolder Container { get; protected set; } + protected IFolder Container; + public string Path; // Yaml map data public string Uid { get; protected set; } @@ -43,11 +44,9 @@ namespace OpenRA.FileFormats public MapStub() {} // Hack for the editor - not used for anything important public MapStub(string path) - : this(FileSystem.OpenPackage(path, int.MaxValue)) {} - - public MapStub(IFolder container) { - Container = container; + Path = path; + Container = FileSystem.OpenPackage(path, int.MaxValue); var yaml = MiniYaml.FromStream(Container.GetContent("map.yaml")); FieldLoader.Load( this, new MiniYaml( null, yaml ) ); diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index b5cfb2e12e..547810e5c3 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -85,10 +85,8 @@ namespace OpenRA public string Owner = null; } - public Map(string path) : this(FileSystem.OpenPackage(path, int.MaxValue)) {} - public Map(MapStub stub) : this(stub.Container) {} - public Map(IFolder package) - : base(package) + public Map(string path) + : base(path) { var yaml = new MiniYaml( null, MiniYaml.FromStream( Container.GetContent( "map.yaml" ) ) ); diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 4ba598690f..88a0d01e74 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -77,7 +77,7 @@ namespace OpenRA if (!AvailableMaps.ContainsKey(uid)) throw new InvalidDataException("Invalid map uid: {0}".F(uid)); - var map = new Map(AvailableMaps[uid]); + var map = new Map(AvailableMaps[uid].Path); // unload the previous map mount if we have one if (previousMapMount != null) FileSystem.Unmount(previousMapMount); @@ -85,11 +85,9 @@ namespace OpenRA // Adds the map its container to the FileSystem // allowing the map to use custom assets // Container should have the lowest priority of all (ie int max) - FileSystem.Mount(map.Container); - // Store a reference so we can unload it next time - previousMapMount = map.Container; - + previousMapMount = FileSystem.OpenPackage(map.Path, int.MaxValue); + FileSystem.Mount(previousMapMount); Rules.LoadRules(Manifest, map); if (map.Tileset != cachedTileset diff --git a/OpenRA.Game/Widgets/MapPreviewWidget.cs b/OpenRA.Game/Widgets/MapPreviewWidget.cs index b3b24342ac..b80fd6ff84 100644 --- a/OpenRA.Game/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Game/Widgets/MapPreviewWidget.cs @@ -24,7 +24,7 @@ namespace OpenRA.Widgets public Func Map = () => null; public Action OnSpawnClick = spawn => {}; public Func> SpawnColors = () => new Dictionary(); - static Cache PreviewCache = new Cache(stub => Minimap.RenderMapPreview( new Map( stub ))); + static Cache PreviewCache = new Cache(stub => Minimap.RenderMapPreview( new Map( stub.Path ))); public MapPreviewWidget() : base() { } protected MapPreviewWidget(MapPreviewWidget other) diff --git a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs index 593b66e107..61116e2df0 100644 --- a/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.RA/ServerTraits/LobbyCommands.cs @@ -274,7 +274,7 @@ namespace OpenRA.Mods.RA.Server public static void LoadMap(S server) { - server.Map = new Map(server.ModData.AvailableMaps[server.lobbyInfo.GlobalSettings.Map]); + server.Map = new Map(server.ModData.AvailableMaps[server.lobbyInfo.GlobalSettings.Map].Path); server.lobbyInfo.Slots = server.Map.Players .Select(p => MakeSlotFromPlayerReference(p.Value)) .Where(s => s != null) diff --git a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs index 5bd0c797b7..a0d4e6023a 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs @@ -165,7 +165,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates { if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return; MapUid = orderManager.LobbyInfo.GlobalSettings.Map; - Map = new Map(Game.modData.AvailableMaps[MapUid]); + Map = new Map(Game.modData.AvailableMaps[MapUid].Path); var title = Widget.RootWidget.GetWidget("LOBBY_TITLE"); title.Text = "OpenRA Multiplayer Lobby - " + orderManager.LobbyInfo.GlobalSettings.ServerName;