Use Filepaths instead of IFolders where possible.

This commit is contained in:
Paul Chote
2010-12-29 19:14:48 +13:00
parent 829fe6530a
commit fc6438e311
6 changed files with 12 additions and 17 deletions

View File

@@ -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 ) );

View File

@@ -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" ) ) );

View File

@@ -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

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Widgets
public Func<MapStub> Map = () => null;
public Action<int> OnSpawnClick = spawn => {};
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
static Cache<MapStub,Bitmap> PreviewCache = new Cache<MapStub, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub )));
static Cache<MapStub,Bitmap> PreviewCache = new Cache<MapStub, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub.Path )));
public MapPreviewWidget() : base() { }
protected MapPreviewWidget(MapPreviewWidget other)

View File

@@ -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)

View File

@@ -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<LabelWidget>("LOBBY_TITLE");
title.Text = "OpenRA Multiplayer Lobby - " + orderManager.LobbyInfo.GlobalSettings.ServerName;