Changed IFolder implementations' priorities to be based on listing order in mod.yaml

This commit is contained in:
Matthew Bowra-Dean
2010-10-28 22:21:54 +13:00
parent 15d6facdb9
commit 4490a90332
8 changed files with 22 additions and 14 deletions

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Editor
Game.modData = new ModData(currentMod); Game.modData = new ModData(currentMod);
// load the map // load the map
var map = new Map(new Folder(mapname)); var map = new Map(new Folder(mapname, 0));
// upgrade maps that have no player definitions. editor doesnt care, // upgrade maps that have no player definitions. editor doesnt care,
// but this breaks the game pretty badly. // but this breaks the game pretty badly.

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Editor
if (MapList.SelectedItems.Count == 1) if (MapList.SelectedItems.Count == 1)
{ {
txtNew.Text = MapList.SelectedItems[0].Text; txtNew.Text = MapList.SelectedItems[0].Text;
var map = new Map(new Folder(Path.Combine(MapFolderPath, MapList.SelectedItems[0].Text))); var map = new Map(new Folder(Path.Combine(MapFolderPath, MapList.SelectedItems[0].Text), 0));
txtTitle.Text = map.Title; txtTitle.Text = map.Title;
txtAuthor.Text = map.Author; txtAuthor.Text = map.Author;
txtTheater.Text = map.Theater; txtTheater.Text = map.Theater;

View File

@@ -21,9 +21,11 @@ namespace OpenRA.FileFormats
readonly uint[] hashes; readonly uint[] hashes;
readonly Stream s; readonly Stream s;
readonly ZipPackage pkg; readonly ZipPackage pkg;
int priority;
public CompressedPackage(string filename) public CompressedPackage(string filename, int priority)
{ {
this.priority = priority;
s = FileSystem.Open(filename); s = FileSystem.Open(filename);
pkg = (ZipPackage)ZipPackage.Open(s, FileMode.Open); pkg = (ZipPackage)ZipPackage.Open(s, FileMode.Open);
hashes = pkg.GetParts() hashes = pkg.GetParts()
@@ -45,7 +47,7 @@ namespace OpenRA.FileFormats
public int Priority public int Priority
{ {
get { return 1; } get { return 500 + priority; }
} }
} }
} }

View File

@@ -34,14 +34,16 @@ namespace OpenRA.FileFormats
} }
} }
static int order = 0;
static IFolder OpenPackage(string filename) static IFolder OpenPackage(string filename)
{ {
if (filename.EndsWith(".mix")) if (filename.EndsWith(".mix"))
return new Package(filename); return new Package(filename, order++);
else if (filename.EndsWith(".zip")) else if (filename.EndsWith(".zip"))
return new CompressedPackage(filename); return new CompressedPackage(filename, order++);
else else
return new Folder(filename); return new Folder(filename, order++);
} }
public static void Mount(string name) public static void Mount(string name)
@@ -76,7 +78,7 @@ namespace OpenRA.FileFormats
{ {
var folder = index[PackageEntry.HashFilename(filename)] var folder = index[PackageEntry.HashFilename(filename)]
.Where(x => x.Exists(filename)) .Where(x => x.Exists(filename))
.OrderByDescending(x => x.Priority) .OrderBy(x => x.Priority)
.FirstOrDefault(); .FirstOrDefault();
if (folder != null) if (folder != null)

View File

@@ -17,7 +17,9 @@ namespace OpenRA.FileFormats
{ {
readonly string path; readonly string path;
public Folder(string path) { this.path = path; } int priority;
public Folder(string path, int priority) { this.path = path; this.priority = priority; }
public Stream GetContent(string filename) public Stream GetContent(string filename)
{ {
@@ -39,7 +41,7 @@ namespace OpenRA.FileFormats
public int Priority public int Priority
{ {
get { return 100; } get { return priority; }
} }
} }
} }

View File

@@ -29,9 +29,11 @@ namespace OpenRA.FileFormats
readonly bool isRmix, isEncrypted; readonly bool isRmix, isEncrypted;
readonly long dataStart; readonly long dataStart;
readonly Stream s; readonly Stream s;
int priority;
public Package(string filename) public Package(string filename, int priority)
{ {
this.priority = priority;
s = FileSystem.Open(filename); s = FileSystem.Open(filename);
BinaryReader reader = new BinaryReader(s); BinaryReader reader = new BinaryReader(s);
@@ -154,7 +156,7 @@ namespace OpenRA.FileFormats
public int Priority public int Priority
{ {
get { return 0; } get { return 1000 + priority; }
} }
} }

View File

@@ -184,7 +184,7 @@ namespace OpenRA
public void Save(string filepath) public void Save(string filepath)
{ {
// Todo: save to a zip file in the support dir by default // Todo: save to a zip file in the support dir by default
Package = new Folder(filepath); Package = new Folder(filepath, 0);
MapFormat = 3; MapFormat = 3;
var root = new List<MiniYamlNode>(); var root = new List<MiniYamlNode>();

View File

@@ -50,7 +50,7 @@ namespace OpenRA
.Where(p => Directory.Exists(p)) .Where(p => Directory.Exists(p))
.SelectMany(p => Directory.GetDirectories(p)).ToList(); .SelectMany(p => Directory.GetDirectories(p)).ToList();
return paths.Select(p => new MapStub(new Folder(p))).ToDictionary(m => m.Uid); return paths.Select(p => new MapStub(new Folder(p, 0))).ToDictionary(m => m.Uid);
} }
string cachedTheatre = null; string cachedTheatre = null;