From 32851e624cf71d9aed00bb75ed677213646c0720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 7 Oct 2013 00:10:55 +0200 Subject: [PATCH 1/5] specify map folders in mod.yaml closes #3544 --- OpenRA.Game/ModData.cs | 14 +++++++------- mods/cnc/mod.yaml | 2 ++ mods/d2k/mod.yaml | 2 ++ mods/d2k/sequences/map.yaml | 24 ------------------------ mods/ra/mod.yaml | 2 ++ mods/ts/mod.yaml | 2 ++ 6 files changed, 15 insertions(+), 31 deletions(-) delete mode 100644 mods/d2k/sequences/map.yaml diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 138d75978d..917e5de733 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -37,9 +37,10 @@ namespace OpenRA if (!Directory.Exists(dir)) return noMaps; - return Directory.GetDirectories(dir) - .Concat(Directory.GetFiles(dir, "*.zip")) - .Concat(Directory.GetFiles(dir, "*.oramap")); + var dirsWithMaps = Directory.GetDirectories(dir) + .Where(d => Directory.GetFiles(d, "map.yaml").Any() && Directory.GetFiles(d, "map.bin").Any()); + + return dirsWithMaps.Concat(Directory.GetFiles(dir, "*.oramap")); } public ModData(params string[] mods) @@ -52,7 +53,7 @@ namespace OpenRA LoadScreen.Display(); WidgetLoader = new WidgetLoader(this); - AvailableMaps = FindMaps(Manifest.Mods); + AvailableMaps = FindMaps(); // HACK: Mount only local folders so we have a half-working environment for the asset installer FileSystem.UnmountAll(); @@ -138,10 +139,9 @@ namespace OpenRA return map; } - Dictionary FindMaps(string[] mods) + Dictionary FindMaps() { - var paths = mods.SelectMany(p => FindMapsIn("mods{0}{1}{0}maps{0}".F(Path.DirectorySeparatorChar, p))) - .Concat(mods.SelectMany(p => FindMapsIn("{1}maps{0}{2}{0}".F(Path.DirectorySeparatorChar, Platform.SupportDir, p)))); + var paths = Manifest.Folders.SelectMany(f => FindMapsIn(f)); var ret = new Dictionary(); diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index acc99f5a70..721bfc229d 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -8,8 +8,10 @@ Folders: . ./mods/cnc ./mods/cnc/bits + ./mods/cnc/maps ./mods/cnc/uibits ~^/Content/cnc + ~^/maps/cnc Packages: overrides.mix diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index 15b269af13..4dfc9d9b6f 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -8,11 +8,13 @@ Folders: . ./mods/d2k ./mods/d2k/bits + ./mods/d2k/maps ./mods/d2k/uibits ./mods/ra/uibits ~^/Content/d2k ~^/Content/d2k/GAMESFX ~^/Content/d2k/Music + ~^/maps/d2k Packages: SOUND.RS diff --git a/mods/d2k/sequences/map.yaml b/mods/d2k/sequences/map.yaml deleted file mode 100644 index f2e820645a..0000000000 --- a/mods/d2k/sequences/map.yaml +++ /dev/null @@ -1,24 +0,0 @@ -crate: - idle: DATA.R8 - Start: 102 - ZOffset: -511 - Offset: -16,-16 - land: DATA.R8 - Start: 102 - ZOffset: -511 - Offset: -16,-16 - -spicebloom: - make: DATA.R8 - Start: 107 - Length: 3 - Offset: -16,-16 - active: DATA.R8 - Start: 109 - Length: 1 - ZOffset: -511 - Offset: -16,-16 - idle: DATA.R8 - Start: 109 - ZOffset: -511 - Offset: -16,-16 \ No newline at end of file diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 085986af9a..e85e5c2f53 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -9,8 +9,10 @@ Folders: ./mods/ra ./mods/ra/bits ./mods/ra/bits/desert + ./mods/ra/maps ./mods/ra/uibits ~^/Content/ra + ~^/maps/ra Packages: ~main.mix diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index e9f041a190..81bb6d7c5b 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -9,8 +9,10 @@ Folders: # Tiberian Sun ./mods/ts ./mods/ts/bits + ./mods/ts/maps ./mods/ts/uibits ~^/Content/ts + ~^/maps/ts # Red Alert ./mods/ra/uibits From 0b73491e3ff06d7d9633ce3264cacb07ba70138c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 12 Oct 2013 11:00:37 +0200 Subject: [PATCH 2/5] CamelCase for FileSystem folder --- .../{Filesystem => FileSystem}/D2kSoundResources.cs | 0 .../{Filesystem => FileSystem}/FileSystem.cs | 0 .../{Filesystem => FileSystem}/Folder.cs | 0 .../InstallShieldPackage.cs | 0 .../{Filesystem => FileSystem}/MixFile.cs | 0 .../{Filesystem => FileSystem}/ZipFile.cs | 0 OpenRA.FileFormats/OpenRA.FileFormats.csproj | 12 ++++++------ 7 files changed, 6 insertions(+), 6 deletions(-) rename OpenRA.FileFormats/{Filesystem => FileSystem}/D2kSoundResources.cs (100%) rename OpenRA.FileFormats/{Filesystem => FileSystem}/FileSystem.cs (100%) rename OpenRA.FileFormats/{Filesystem => FileSystem}/Folder.cs (100%) rename OpenRA.FileFormats/{Filesystem => FileSystem}/InstallShieldPackage.cs (100%) rename OpenRA.FileFormats/{Filesystem => FileSystem}/MixFile.cs (100%) rename OpenRA.FileFormats/{Filesystem => FileSystem}/ZipFile.cs (100%) diff --git a/OpenRA.FileFormats/Filesystem/D2kSoundResources.cs b/OpenRA.FileFormats/FileSystem/D2kSoundResources.cs similarity index 100% rename from OpenRA.FileFormats/Filesystem/D2kSoundResources.cs rename to OpenRA.FileFormats/FileSystem/D2kSoundResources.cs diff --git a/OpenRA.FileFormats/Filesystem/FileSystem.cs b/OpenRA.FileFormats/FileSystem/FileSystem.cs similarity index 100% rename from OpenRA.FileFormats/Filesystem/FileSystem.cs rename to OpenRA.FileFormats/FileSystem/FileSystem.cs diff --git a/OpenRA.FileFormats/Filesystem/Folder.cs b/OpenRA.FileFormats/FileSystem/Folder.cs similarity index 100% rename from OpenRA.FileFormats/Filesystem/Folder.cs rename to OpenRA.FileFormats/FileSystem/Folder.cs diff --git a/OpenRA.FileFormats/Filesystem/InstallShieldPackage.cs b/OpenRA.FileFormats/FileSystem/InstallShieldPackage.cs similarity index 100% rename from OpenRA.FileFormats/Filesystem/InstallShieldPackage.cs rename to OpenRA.FileFormats/FileSystem/InstallShieldPackage.cs diff --git a/OpenRA.FileFormats/Filesystem/MixFile.cs b/OpenRA.FileFormats/FileSystem/MixFile.cs similarity index 100% rename from OpenRA.FileFormats/Filesystem/MixFile.cs rename to OpenRA.FileFormats/FileSystem/MixFile.cs diff --git a/OpenRA.FileFormats/Filesystem/ZipFile.cs b/OpenRA.FileFormats/FileSystem/ZipFile.cs similarity index 100% rename from OpenRA.FileFormats/Filesystem/ZipFile.cs rename to OpenRA.FileFormats/FileSystem/ZipFile.cs diff --git a/OpenRA.FileFormats/OpenRA.FileFormats.csproj b/OpenRA.FileFormats/OpenRA.FileFormats.csproj index ecdf6dfe9b..f8f42f2b1c 100644 --- a/OpenRA.FileFormats/OpenRA.FileFormats.csproj +++ b/OpenRA.FileFormats/OpenRA.FileFormats.csproj @@ -90,11 +90,6 @@ - - - - - @@ -148,11 +143,16 @@ - + + + + + + From 166b727c0b45b5dd392420ddfb14f63bdeefd448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 12 Oct 2013 11:04:45 +0200 Subject: [PATCH 3/5] StyleCop cleanup --- OpenRA.FileFormats/FileSystem/FileSystem.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/OpenRA.FileFormats/FileSystem/FileSystem.cs b/OpenRA.FileFormats/FileSystem/FileSystem.cs index 886f308046..6046908e67 100644 --- a/OpenRA.FileFormats/FileSystem/FileSystem.cs +++ b/OpenRA.FileFormats/FileSystem/FileSystem.cs @@ -19,8 +19,8 @@ namespace OpenRA.FileFormats public static class FileSystem { public static List MountedFolders = new List(); - static Cache> classicHashIndex = new Cache>( _ => new List() ); - static Cache> crcHashIndex = new Cache>( _ => new List() ); + static Cache> classicHashIndex = new Cache>(_ => new List()); + static Cache> crcHashIndex = new Cache>(_ => new List()); public static List FolderPaths = new List(); @@ -89,11 +89,12 @@ namespace OpenRA.FileFormats public static void Mount(string name, string annotation) { var optional = name.StartsWith("~"); - if (optional) name = name.Substring(1); + if (optional) + name = name.Substring(1); // paths starting with ^ are relative to the support dir if (name.StartsWith("^")) - name = Platform.SupportDir+name.Substring(1); + name = Platform.SupportDir + name.Substring(1); FolderPaths.Add(name); Action a = () => FileSystem.MountInner(OpenPackage(name, annotation, order++)); @@ -115,7 +116,7 @@ namespace OpenRA.FileFormats public static bool Unmount(IFolder mount) { - return (MountedFolders.RemoveAll(f => f == mount) > 0); + return MountedFolders.RemoveAll(f => f == mount) > 0; } public static void Mount(IFolder mount) @@ -151,7 +152,7 @@ namespace OpenRA.FileFormats public static Stream OpenWithExts(string filename, params string[] exts) { - if (filename.IndexOfAny(new char[] { '/', '\\' } ) == -1) + if (filename.IndexOfAny(new char[] { '/', '\\' }) == -1) { foreach (var ext in exts) { From c87c4cfda28906dda1f6cb48f765b10a16d824b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 12 Oct 2013 11:05:09 +0200 Subject: [PATCH 4/5] translate ^ and ~ as FileSystem.Mount does --- OpenRA.Game/ModData.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 917e5de733..ed67ec49c2 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -34,6 +34,14 @@ namespace OpenRA { string[] noMaps = { }; + // ignore optional flag + if (dir.StartsWith("~")) + dir = dir.Substring(1); + + // paths starting with ^ are relative to the user directory + if (dir.StartsWith("^")) + dir = Platform.SupportDir + dir.Substring(1); + if (!Directory.Exists(dir)) return noMaps; From 74692bde664f812c6a30501c838cc4e7f0eccafe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 27 Oct 2013 09:22:10 +0100 Subject: [PATCH 5/5] load maps only from MapFolders defined separately in mod.yaml --- OpenRA.FileFormats/Manifest.cs | 3 ++- OpenRA.Game/ModData.cs | 2 +- mods/cnc/mod.yaml | 4 +++- mods/d2k/mod.yaml | 4 +++- mods/ra/mod.yaml | 4 +++- mods/ts/mod.yaml | 6 ++++-- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/OpenRA.FileFormats/Manifest.cs b/OpenRA.FileFormats/Manifest.cs index 63ec0b0c38..43515a02e1 100644 --- a/OpenRA.FileFormats/Manifest.cs +++ b/OpenRA.FileFormats/Manifest.cs @@ -19,7 +19,7 @@ namespace OpenRA.FileFormats public class Manifest { public readonly string[] - Mods, Folders, Rules, ServerTraits, + Mods, Folders, MapFolders, Rules, ServerTraits, Sequences, VoxelSequences, Cursors, Chrome, Assemblies, ChromeLayout, Weapons, Voices, Notifications, Music, Movies, Translations, TileSets, ChromeMetrics, PackageContents; @@ -39,6 +39,7 @@ namespace OpenRA.FileFormats // TODO: Use fieldloader Folders = YamlList(yaml, "Folders"); + MapFolders = YamlList(yaml, "MapFolders"); Packages = yaml["Packages"].NodesDict.ToDictionary(x => x.Key, x => x.Value.Value); Rules = YamlList(yaml, "Rules"); ServerTraits = YamlList(yaml, "ServerTraits"); diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index ed67ec49c2..b736ef2840 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -149,7 +149,7 @@ namespace OpenRA Dictionary FindMaps() { - var paths = Manifest.Folders.SelectMany(f => FindMapsIn(f)); + var paths = Manifest.MapFolders.SelectMany(f => FindMapsIn(f)); var ret = new Dictionary(); diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 721bfc229d..32ca45d723 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -8,9 +8,11 @@ Folders: . ./mods/cnc ./mods/cnc/bits - ./mods/cnc/maps ./mods/cnc/uibits ~^/Content/cnc + +MapFolders: + ./mods/cnc/maps ~^/maps/cnc Packages: diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index 4dfc9d9b6f..9f132f842a 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -8,12 +8,14 @@ Folders: . ./mods/d2k ./mods/d2k/bits - ./mods/d2k/maps ./mods/d2k/uibits ./mods/ra/uibits ~^/Content/d2k ~^/Content/d2k/GAMESFX ~^/Content/d2k/Music + +MapFolders: + ./mods/d2k/maps ~^/maps/d2k Packages: diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index e85e5c2f53..394eb836c9 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -9,9 +9,11 @@ Folders: ./mods/ra ./mods/ra/bits ./mods/ra/bits/desert - ./mods/ra/maps ./mods/ra/uibits ~^/Content/ra + +MapFolders: + ./mods/ra/maps ~^/maps/ra Packages: diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index 81bb6d7c5b..63adc87e73 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -9,13 +9,15 @@ Folders: # Tiberian Sun ./mods/ts ./mods/ts/bits - ./mods/ts/maps ./mods/ts/uibits ~^/Content/ts - ~^/maps/ts # Red Alert ./mods/ra/uibits +MapFolders: + ./mods/ts/maps + ~^/maps/ts + Packages: # Red Alert interior.mix