Remove map saving shim method.
This commit is contained in:
@@ -33,8 +33,9 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
Cache<string, List<IReadOnlyPackage>> fileIndex = new Cache<string, List<IReadOnlyPackage>>(_ => new List<IReadOnlyPackage>());
|
Cache<string, List<IReadOnlyPackage>> fileIndex = new Cache<string, List<IReadOnlyPackage>>(_ => new List<IReadOnlyPackage>());
|
||||||
|
|
||||||
public IReadWritePackage CreatePackage(string filename, Dictionary<string, byte[]> content)
|
public IReadWritePackage CreatePackage(string filename)
|
||||||
{
|
{
|
||||||
|
var content = new Dictionary<string, byte[]>();
|
||||||
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new ZipFile(this, filename, content);
|
return new ZipFile(this, filename, content);
|
||||||
if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
|||||||
@@ -120,7 +120,6 @@ namespace OpenRA
|
|||||||
public readonly SubCell LastSubCell;
|
public readonly SubCell LastSubCell;
|
||||||
|
|
||||||
public IReadOnlyPackage Package { get; private set; }
|
public IReadOnlyPackage Package { get; private set; }
|
||||||
public string Path { get { return Package.Name; } }
|
|
||||||
|
|
||||||
// Yaml map data
|
// Yaml map data
|
||||||
public string Uid { get; private set; }
|
public string Uid { get; private set; }
|
||||||
@@ -494,11 +493,6 @@ namespace OpenRA
|
|||||||
return rules.Value;
|
return rules.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save(string toPath)
|
|
||||||
{
|
|
||||||
Save(modData.ModFiles.CreatePackage(toPath, new Dictionary<string, byte[]>()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Save(IReadWritePackage toContainer)
|
public void Save(IReadWritePackage toContainer)
|
||||||
{
|
{
|
||||||
MapFormat = 8;
|
MapFormat = 8;
|
||||||
|
|||||||
@@ -93,9 +93,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
|
|
||||||
Map.FixOpenAreas(Rules);
|
Map.FixOpenAreas(Rules);
|
||||||
|
|
||||||
var fileName = Path.GetFileNameWithoutExtension(args[1]);
|
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||||
var dest = fileName + ".oramap";
|
var package = modData.ModFiles.CreatePackage(dest);
|
||||||
Map.Save(dest);
|
Map.Save(package);
|
||||||
Console.WriteLine(dest + " saved.");
|
Console.WriteLine(dest + " saved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.UtilityCommands
|
namespace OpenRA.Mods.Common.UtilityCommands
|
||||||
{
|
{
|
||||||
@@ -67,7 +68,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
foreach (var kv in forRemoval)
|
foreach (var kv in forRemoval)
|
||||||
map.ActorDefinitions.Remove(kv);
|
map.ActorDefinitions.Remove(kv);
|
||||||
|
|
||||||
map.Save(map.Path);
|
map.Save((IReadWritePackage)map.Package);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using OpenRA.FileSystem;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.UtilityCommands
|
namespace OpenRA.Mods.Common.UtilityCommands
|
||||||
{
|
{
|
||||||
class UpgradeMapCommand : IUtilityCommand
|
class UpgradeMapCommand : IUtilityCommand
|
||||||
@@ -33,7 +35,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
||||||
map.Save(args[1]);
|
map.Save((IReadWritePackage)map.Package);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.UtilityCommands
|
namespace OpenRA.Mods.Common.UtilityCommands
|
||||||
{
|
{
|
||||||
@@ -113,7 +114,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
||||||
map.Save(map.Path);
|
map.Save((IReadWritePackage)map.Package);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var mapDirectories = 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 mapPath = map.Package.Name;
|
||||||
var directoryDropdown = widget.Get<DropDownButtonWidget>("DIRECTORY_DROPDOWN");
|
var directoryDropdown = widget.Get<DropDownButtonWidget>("DIRECTORY_DROPDOWN");
|
||||||
{
|
{
|
||||||
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||||
@@ -86,7 +87,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return item;
|
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);
|
var initialDirectory = mapDirectories.Keys.FirstOrDefault(f => f == mapDirectory);
|
||||||
|
|
||||||
// Prioritize MapClassification.User directories over system directories
|
// Prioritize MapClassification.User directories over system directories
|
||||||
@@ -100,14 +102,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
var mapIsUnpacked = false;
|
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);
|
mapIsUnpacked = attr.HasFlag(FileAttributes.Directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
var filename = widget.Get<TextFieldWidget>("FILENAME");
|
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 fileType = mapIsUnpacked ? MapFileType.Unpacked : MapFileType.OraMap;
|
||||||
|
|
||||||
var fileTypes = new Dictionary<MapFileType, MapFileTypeInfo>()
|
var fileTypes = new Dictionary<MapFileType, MapFileTypeInfo>()
|
||||||
@@ -158,13 +161,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
// Create the map directory if required
|
// Create the map directory if required
|
||||||
Directory.CreateDirectory(Platform.ResolvePath(directoryDropdown.Text));
|
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));
|
var combinedPath = Platform.ResolvePath(Path.Combine(directoryDropdown.Text, filename.Text + fileTypes[fileType].Extension));
|
||||||
|
|
||||||
// Invalidate the old map metadata
|
// Invalidate the old map metadata
|
||||||
if (map.Uid != null && combinedPath == map.Path)
|
if (map.Uid != null && combinedPath == mapPath)
|
||||||
modData.MapCache[map.Uid].Invalidate();
|
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
|
// Update the map cache so it can be loaded without restarting the game
|
||||||
var classification = mapDirectories[directoryDropdown.Text];
|
var classification = mapDirectories[directoryDropdown.Text];
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ namespace OpenRA.Mods.D2k.UtilityCommands
|
|||||||
if (map == null)
|
if (map == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var fileName = Path.GetFileNameWithoutExtension(args[1]);
|
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||||
var dest = fileName + ".oramap";
|
var package = modData.ModFiles.CreatePackage(dest);
|
||||||
map.Save(dest);
|
map.Save(package);
|
||||||
Console.WriteLine(dest + " saved.");
|
Console.WriteLine(dest + " saved.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,9 +171,9 @@ namespace OpenRA.Mods.TS.UtilityCommands
|
|||||||
var mapPlayers = new MapPlayers(map.Rules, spawnCount);
|
var mapPlayers = new MapPlayers(map.Rules, spawnCount);
|
||||||
map.PlayerDefinitions = mapPlayers.ToMiniYaml();
|
map.PlayerDefinitions = mapPlayers.ToMiniYaml();
|
||||||
|
|
||||||
var fileName = Path.GetFileNameWithoutExtension(filename);
|
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||||
var dest = fileName + ".oramap";
|
var package = modData.ModFiles.CreatePackage(dest);
|
||||||
map.Save(dest);
|
map.Save(package);
|
||||||
Console.WriteLine(dest + " saved.");
|
Console.WriteLine(dest + " saved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user