Skip to content

Commit

Permalink
Merge pull request #10697 from pchote/map-cleanup-part-2
Browse files Browse the repository at this point in the history
Remove Map references from MapPreview.
  • Loading branch information
obrakmann committed Feb 7, 2016
2 parents ce0e092 + 8b5592e commit 1df728a
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 158 deletions.
2 changes: 1 addition & 1 deletion OpenRA.Game/Game.cs
Expand Up @@ -445,7 +445,7 @@ public static void LoadShellMap()
static string ChooseShellmap()
{
var shellmaps = ModData.MapCache
.Where(m => m.Status == MapStatus.Available && m.Map.Visibility.HasFlag(MapVisibility.Shellmap))
.Where(m => m.Status == MapStatus.Available && m.Visibility.HasFlag(MapVisibility.Shellmap))
.Select(m => m.Uid);

if (!shellmaps.Any())
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Game/Map/MapCache.cs
Expand Up @@ -174,7 +174,8 @@ void LoadAsyncInternal()
if (bitmap == null)
{
createdPreview = true;
bitmap = Minimap.RenderMapPreview(modData.DefaultRules.TileSets[p.Map.Tileset], p.Map, modData.DefaultRules, true);
var map = new Map(p.Path);
bitmap = Minimap.RenderMapPreview(modData.DefaultRules.TileSets[map.Tileset], map, modData.DefaultRules, true);
}

Game.RunAfterTick(() =>
Expand Down
31 changes: 9 additions & 22 deletions OpenRA.Game/Map/MapPreview.cs
Expand Up @@ -57,6 +57,8 @@ public class MapPreview
MapCache cache;

public readonly string Uid;
public string Path { get; private set; }

public string Title { get; private set; }
public string Type { get; private set; }
public string Author { get; private set; }
Expand All @@ -65,13 +67,11 @@ public class MapPreview
public MapGridType GridType { get; private set; }
public Rectangle Bounds { get; private set; }
public Bitmap CustomPreview { get; private set; }
public Map Map { get; private set; }
public MapStatus Status { get; private set; }
public MapClassification Class { get; private set; }
public MapVisibility Visibility { get; private set; }
public bool SuitableForInitialMap { get; private set; }

public MapRuleStatus RuleStatus { get; private set; }

Download download;
public long DownloadBytes { get; private set; }
public int DownloadPercentage { get; private set; }
Expand Down Expand Up @@ -111,11 +111,12 @@ public MapPreview(string uid, MapGridType gridType, MapCache cache)
GridType = gridType;
Status = MapStatus.Unavailable;
Class = MapClassification.Unknown;
Visibility = MapVisibility.Lobby;
}

public void UpdateFromMap(Map m, MapClassification classification)
{
Map = m;
Path = m.Path;
Title = m.Title;
Type = m.Type;
Type = m.Type;
Expand All @@ -126,6 +127,7 @@ public void UpdateFromMap(Map m, MapClassification classification)
CustomPreview = m.CustomPreview;
Status = MapStatus.Available;
Class = classification;
Visibility = m.Visibility;

var players = new MapPlayers(m.PlayerDefinitions).Players;
PlayerCount = players.Count(x => x.Value.Playable);
Expand All @@ -135,7 +137,7 @@ public void UpdateFromMap(Map m, MapClassification classification)

bool EvaluateUserFriendliness(Dictionary<string, PlayerReference> players)
{
if (Status != MapStatus.Available || !Map.Visibility.HasFlag(MapVisibility.Lobby))
if (Status != MapStatus.Available || !Visibility.HasFlag(MapVisibility.Lobby))
return false;

// Other map types may have confusing settings or gameplay
Expand Down Expand Up @@ -168,7 +170,6 @@ public void UpdateRemoteSearch(MapStatus status, MiniYaml yaml)
if (!r.downloading)
{
Status = MapStatus.Unavailable;
RuleStatus = MapRuleStatus.Invalid;
return;
}
Expand Down Expand Up @@ -228,7 +229,7 @@ public void Install()
return;
}
mapPath = Path.Combine(baseMapPath, res.Headers["Content-Disposition"].Replace("attachment; filename = ", ""));
mapPath = System.IO.Path.Combine(baseMapPath, res.Headers["Content-Disposition"].Replace("attachment; filename = ", ""));
}
Action<DownloadProgressChangedEventArgs> onDownloadProgress = i => { DownloadBytes = i.BytesReceived; DownloadPercentage = i.ProgressPercentage; };
Expand All @@ -246,11 +247,7 @@ public void Install()
}
Log.Write("debug", "Downloaded map to '{0}'", mapPath);
Game.RunAfterTick(() =>
{
UpdateFromMap(new Map(mapPath), MapClassification.User);
CacheRules();
});
Game.RunAfterTick(() => UpdateFromMap(new Map(mapPath), MapClassification.User));
};
download = new Download(mapUrl, mapPath, onDownloadProgress, onDownloadComplete);
Expand All @@ -272,19 +269,9 @@ public void CancelInstall()
download = null;
}

public void CacheRules()
{
if (RuleStatus != MapRuleStatus.Unknown)
return;

Map.PreloadRules();
RuleStatus = Map.InvalidCustomRules ? MapRuleStatus.Invalid : MapRuleStatus.Cached;
}

public void Invalidate()
{
Status = MapStatus.Unavailable;
RuleStatus = MapRuleStatus.Unknown;
}
}
}
2 changes: 1 addition & 1 deletion OpenRA.Game/ModData.cs
Expand Up @@ -166,7 +166,7 @@ public Map PrepareMap(string uid)
throw new InvalidDataException("Invalid map uid: {0}".F(uid));

// Operate on a copy of the map to avoid gameplay state leaking into the cache
var map = new Map(MapCache[uid].Map.Path);
var map = new Map(MapCache[uid].Path);

LoadTranslations(map);

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Widgets/WidgetUtils.cs
Expand Up @@ -255,7 +255,7 @@ public static string ChooseInitialMap(string initialUid)
if (string.IsNullOrEmpty(initialUid) || Game.ModData.MapCache[initialUid].Status != MapStatus.Available)
{
var selected = Game.ModData.MapCache.Where(x => x.SuitableForInitialMap).RandomOrDefault(Game.CosmeticRandom) ??
Game.ModData.MapCache.First(m => m.Status == MapStatus.Available && m.Map.Visibility.HasFlag(MapVisibility.Lobby));
Game.ModData.MapCache.First(m => m.Status == MapStatus.Available && m.Visibility.HasFlag(MapVisibility.Lobby));
return selected.Uid;
}

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs
Expand Up @@ -926,7 +926,7 @@ static Session.Slot MakeSlotFromPlayerReference(PlayerReference pr)

static void LoadMap(S server)
{
server.Map = server.ModData.MapCache[server.LobbyInfo.GlobalSettings.Map].Map;
server.Map = new Map(server.ModData.MapCache[server.LobbyInfo.GlobalSettings.Map].Path);

server.MapPlayers = new MapPlayers(server.Map.PlayerDefinitions);
server.LobbyInfo.Slots = server.MapPlayers.Players
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs
Expand Up @@ -78,7 +78,7 @@ public void Run(ModData modData, string[] args)
Game.ModData.MapCache.LoadMaps();
maps.AddRange(Game.ModData.MapCache
.Where(m => m.Status == MapStatus.Available)
.Select(m => m.Map));
.Select(m => new Map(m.Path)));
}
else
maps.Add(new Map(args[1]));
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/UtilityCommands/UpgradeModCommand.cs
Expand Up @@ -101,7 +101,7 @@ public void Run(ModData modData, string[] args)
Console.WriteLine("Processing Maps:");
var maps = Game.ModData.MapCache
.Where(m => m.Status == MapStatus.Available)
.Select(m => m.Map);
.Select(m => new Map(m.Path));

foreach (var map in maps)
{
Expand Down

0 comments on commit 1df728a

Please sign in to comment.