Use the virtual filesystem to resolve MapFolder paths.
This commit is contained in:
@@ -16,6 +16,7 @@ using System.Linq;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
|
|
||||||
@@ -45,7 +46,8 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
// Expand the dictionary (dir path, dir type) to a dictionary of (map path, dir type)
|
// Expand the dictionary (dir path, dir type) to a dictionary of (map path, dir type)
|
||||||
var mapPaths = modData.Manifest.MapFolders.SelectMany(kv =>
|
var mapPaths = modData.Manifest.MapFolders.SelectMany(kv =>
|
||||||
FindMapsIn(kv.Key).ToDictionary(p => p, p => string.IsNullOrEmpty(kv.Value) ? MapClassification.Unknown : Enum<MapClassification>.Parse(kv.Value)));
|
FindMapsIn(modData.ModFiles, kv.Key).ToDictionary(p => p, p => string.IsNullOrEmpty(kv.Value)
|
||||||
|
? MapClassification.Unknown : Enum<MapClassification>.Parse(kv.Value)));
|
||||||
|
|
||||||
foreach (var path in mapPaths)
|
foreach (var path in mapPaths)
|
||||||
{
|
{
|
||||||
@@ -111,7 +113,7 @@ namespace OpenRA
|
|||||||
new Download(url, _ => { }, onInfoComplete);
|
new Download(url, _ => { }, onInfoComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<string> FindMapsIn(string dir)
|
public static IEnumerable<string> FindMapsIn(FileSystem.FileSystem context, string dir)
|
||||||
{
|
{
|
||||||
string[] noMaps = { };
|
string[] noMaps = { };
|
||||||
|
|
||||||
@@ -119,9 +121,15 @@ namespace OpenRA
|
|||||||
if (dir.StartsWith("~"))
|
if (dir.StartsWith("~"))
|
||||||
dir = dir.Substring(1);
|
dir = dir.Substring(1);
|
||||||
|
|
||||||
|
// HACK: We currently only support maps loaded from Folders
|
||||||
|
// This is a temporary workaround that resolves the filesystem paths to a system directory
|
||||||
|
IReadOnlyPackage package;
|
||||||
|
string filename;
|
||||||
|
if (context.TryGetPackageContaining(dir, out package, out filename))
|
||||||
|
dir = Path.Combine(package.Name, filename);
|
||||||
|
else if (Directory.Exists(Platform.ResolvePath(dir)))
|
||||||
dir = Platform.ResolvePath(dir);
|
dir = Platform.ResolvePath(dir);
|
||||||
|
else
|
||||||
if (!Directory.Exists(dir))
|
|
||||||
return noMaps;
|
return noMaps;
|
||||||
|
|
||||||
var dirsWithMaps = Directory.GetDirectories(dir)
|
var dirsWithMaps = Directory.GetDirectories(dir)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||||
@@ -29,6 +30,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public SaveMapLogic(Widget widget, Action<string> onSave, Action onExit, Map map, List<MiniYamlNode> playerDefinitions, List<MiniYamlNode> actorDefinitions)
|
public SaveMapLogic(Widget widget, Action<string> onSave, Action onExit, Map map, List<MiniYamlNode> playerDefinitions, List<MiniYamlNode> actorDefinitions)
|
||||||
{
|
{
|
||||||
|
var modData = Game.ModData;
|
||||||
var title = widget.Get<TextFieldWidget>("TITLE");
|
var title = widget.Get<TextFieldWidget>("TITLE");
|
||||||
title.Text = map.Title;
|
title.Text = map.Title;
|
||||||
|
|
||||||
@@ -59,14 +61,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
Func<string, string> makeMapDirectory = dir =>
|
Func<string, string> makeMapDirectory = dir =>
|
||||||
{
|
{
|
||||||
var f = Platform.UnresolvePath(dir);
|
if (dir.StartsWith("~"))
|
||||||
if (f.StartsWith("~"))
|
dir = dir.Substring(1);
|
||||||
f = f.Substring(1);
|
|
||||||
|
|
||||||
return f;
|
IReadOnlyPackage package;
|
||||||
|
string f;
|
||||||
|
if (modData.ModFiles.TryGetPackageContaining(dir, out package, out f))
|
||||||
|
dir = Path.Combine(package.Name, f);
|
||||||
|
|
||||||
|
return Platform.UnresolvePath(dir);
|
||||||
};
|
};
|
||||||
|
|
||||||
var mapDirectories = Game.ModData.Manifest.MapFolders
|
var mapDirectories = modData.Manifest.MapFolders
|
||||||
.ToDictionary(kv => makeMapDirectory(kv.Key), kv => Enum<MapClassification>.Parse(kv.Value));
|
.ToDictionary(kv => makeMapDirectory(kv.Key), kv => Enum<MapClassification>.Parse(kv.Value));
|
||||||
|
|
||||||
var directoryDropdown = widget.Get<DropDownButtonWidget>("DIRECTORY_DROPDOWN");
|
var directoryDropdown = widget.Get<DropDownButtonWidget>("DIRECTORY_DROPDOWN");
|
||||||
@@ -147,7 +153,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
if (playerDefinitions != null)
|
if (playerDefinitions != null)
|
||||||
map.PlayerDefinitions = playerDefinitions;
|
map.PlayerDefinitions = playerDefinitions;
|
||||||
|
|
||||||
map.RequiresMod = Game.ModData.Manifest.Mod.Id;
|
map.RequiresMod = modData.Manifest.Mod.Id;
|
||||||
|
|
||||||
// Create the map directory if required
|
// Create the map directory if required
|
||||||
Directory.CreateDirectory(Platform.ResolvePath(directoryDropdown.Text));
|
Directory.CreateDirectory(Platform.ResolvePath(directoryDropdown.Text));
|
||||||
@@ -156,13 +162,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
// Invalidate the old map metadata
|
// Invalidate the old map metadata
|
||||||
if (map.Uid != null && combinedPath == map.Path)
|
if (map.Uid != null && combinedPath == map.Path)
|
||||||
Game.ModData.MapCache[map.Uid].Invalidate();
|
modData.MapCache[map.Uid].Invalidate();
|
||||||
|
|
||||||
map.Save(combinedPath);
|
map.Save(combinedPath);
|
||||||
|
|
||||||
// Update the map cache so it can be loaded without restarting the game
|
// Update the map cache so it can be loaded without restarting the game
|
||||||
var classification = mapDirectories[directoryDropdown.Text];
|
var classification = mapDirectories[directoryDropdown.Text];
|
||||||
Game.ModData.MapCache[map.Uid].UpdateFromMap(map, classification);
|
modData.MapCache[map.Uid].UpdateFromMap(map, classification);
|
||||||
|
|
||||||
Console.WriteLine("Saved current map at {0}", combinedPath);
|
Console.WriteLine("Saved current map at {0}", combinedPath);
|
||||||
Ui.CloseWindow();
|
Ui.CloseWindow();
|
||||||
|
|||||||
Reference in New Issue
Block a user