Merge pull request #10786 from pchote/mappreview-packages

Remove internal use of map paths.
This commit is contained in:
Oliver Brakmann
2016-02-23 22:52:54 +01:00
21 changed files with 172 additions and 174 deletions

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var maxTerrainHeight = world.Map.Grid.MaximumTerrainHeight;
var tileset = modRules.TileSets[tilesetDropDown.Text];
var map = new Map(tileset, width + 2, height + maxTerrainHeight + 2);
var map = new Map(Game.ModData, tileset, width + 2, height + maxTerrainHeight + 2);
var tl = new PPos(1, 1);
var br = new PPos(width, height + maxTerrainHeight);

View File

@@ -76,6 +76,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var mapDirectories = modData.Manifest.MapFolders
.ToDictionary(kv => makeMapDirectory(kv.Key), kv => Enum<MapClassification>.Parse(kv.Value));
var mapPath = map.Package != null ? map.Package.Name : null;
var directoryDropdown = widget.Get<DropDownButtonWidget>("DIRECTORY_DROPDOWN");
{
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
@@ -87,7 +88,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return item;
};
var mapDirectory = map.Path != null ? Platform.UnresolvePath(Path.GetDirectoryName(map.Path)) : null;
// TODO: This won't work for maps inside oramod packages
var mapDirectory = mapPath != null ? Platform.UnresolvePath(Path.GetDirectoryName(mapPath)) : null;
var initialDirectory = mapDirectories.Keys.FirstOrDefault(f => f == mapDirectory);
// Prioritize MapClassification.User directories over system directories
@@ -101,14 +103,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var mapIsUnpacked = false;
if (map.Path != null)
// TODO: This won't work for maps inside oramod packages
if (mapPath != null)
{
var attr = File.GetAttributes(map.Path);
var attr = File.GetAttributes(mapPath);
mapIsUnpacked = attr.HasFlag(FileAttributes.Directory);
}
var filename = widget.Get<TextFieldWidget>("FILENAME");
filename.Text = mapIsUnpacked ? Path.GetFileName(map.Path) : Path.GetFileNameWithoutExtension(map.Path);
filename.Text = mapIsUnpacked ? Path.GetFileName(mapPath) : Path.GetFileNameWithoutExtension(mapPath);
var fileType = mapIsUnpacked ? MapFileType.Unpacked : MapFileType.OraMap;
var fileTypes = new Dictionary<MapFileType, MapFileTypeInfo>()
@@ -159,17 +162,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// Create the map directory if required
Directory.CreateDirectory(Platform.ResolvePath(directoryDropdown.Text));
// TODO: This won't work for maps inside oramod packages
var combinedPath = Platform.ResolvePath(Path.Combine(directoryDropdown.Text, filename.Text + fileTypes[fileType].Extension));
// Invalidate the old map metadata
if (map.Uid != null && combinedPath == map.Path)
if (map.Uid != null && combinedPath == mapPath)
modData.MapCache[map.Uid].Invalidate();
map.Save(combinedPath);
var package = modData.ModFiles.CreatePackage(combinedPath);
map.Save(package);
// Update the map cache so it can be loaded without restarting the game
var classification = mapDirectories[directoryDropdown.Text];
modData.MapCache[map.Uid].UpdateFromMap(map.Container, classification, null, map.Grid.Type);
modData.MapCache[map.Uid].UpdateFromMap(map.Package, classification, null, map.Grid.Type);
Console.WriteLine("Saved current map at {0}", combinedPath);
Ui.CloseWindow();

View File

@@ -738,14 +738,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (MapPreview.Uid == uid)
return;
MapPreview = Game.ModData.MapCache[uid];
var modData = Game.ModData;
MapPreview = modData.MapCache[uid];
Map = null;
if (MapPreview.Status == MapStatus.Available)
{
// Maps need to be validated and pre-loaded before they can be accessed
new Thread(_ =>
{
var currentMap = Map = new Map(MapPreview.Path);
var currentMap = Map = new Map(modData, MapPreview.Package);
currentMap.PreloadRules();
Game.RunAfterTick(() =>
{

View File

@@ -285,7 +285,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
string DeleteMap(string map)
{
var path = Game.ModData.MapCache[map].Path;
var path = Game.ModData.MapCache[map].Package.Name;
try
{
if (File.Exists(path))

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly ScrollPanelWidget missionList;
readonly ScrollItemWidget headerTemplate;
readonly ScrollItemWidget template;
readonly Cache<MapPreview, Map> mapCache = new Cache<MapPreview, Map>(p => new Map(p.Path));
readonly Cache<MapPreview, Map> mapCache;
MapPreview selectedMapPreview;
Map selectedMap;
@@ -56,6 +56,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public MissionBrowserLogic(Widget widget, World world, Action onStart, Action onExit)
{
modData = Game.ModData;
mapCache = new Cache<MapPreview, Map>(p => new Map(modData, p.Package));
this.onStart = onStart;
missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST");
@@ -109,8 +110,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var missionMapPaths = kv.Value.Nodes.Select(n => Path.GetFullPath(n.Key)).ToList();
var previews = modData.MapCache
.Where(p => p.Status == MapStatus.Available && missionMapPaths.Contains(Path.GetFullPath(p.Path)))
.OrderBy(p => missionMapPaths.IndexOf(Path.GetFullPath(p.Path)));
.Where(p => p.Status == MapStatus.Available && missionMapPaths.Contains(p.Package.Name))
.OrderBy(p => missionMapPaths.IndexOf(p.Package.Name));
CreateMissionGroup(kv.Key, previews);
allPreviews.AddRange(previews);