From 94ed85bab783d192810d3b78ff55898d9cc07f20 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 30 Oct 2019 23:59:47 +0100 Subject: [PATCH] made override structure a bit better --- Contentless/Config.cs | 3 ++- Contentless/Program.cs | 6 +++--- README.md | 9 +++++---- Test/Content/Content.mgcb | 5 ++--- Test/Content/Contentless.json | 8 ++++---- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Contentless/Config.cs b/Contentless/Config.cs index 9a416ee..1acd7ed 100644 --- a/Contentless/Config.cs +++ b/Contentless/Config.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using Newtonsoft.Json; namespace Contentless { @@ -10,7 +11,7 @@ namespace Contentless { public bool LogSkipped = true; [JsonProperty(PropertyName = "overrides")] - public string[][] Overrides = { }; + public Dictionary Overrides = new Dictionary(); } } \ No newline at end of file diff --git a/Contentless/Program.cs b/Contentless/Program.cs index 66478c3..47d76be 100644 --- a/Contentless/Program.cs +++ b/Contentless/Program.cs @@ -41,7 +41,7 @@ namespace Contentless { Console.WriteLine("Using default config"); } var excluded = config.ExcludedFiles.Select(MakeFileRegex).ToArray(); - var overrides = config.Overrides.Select(e => (MakeFileRegex(e[0]), e[1])).ToArray(); + var overrides = config.Overrides.Select((e, i) => (MakeFileRegex(e.Key), e.Value)).ToArray(); // load any references to be able to include custom content types as well foreach (var line in content) { @@ -136,7 +136,7 @@ namespace Contentless { } } - private static string GetOverrideImporterFor(string file, (Regex, string)[] overrides) { + private static string GetOverrideImporterFor(string file, IEnumerable<(Regex, string)> overrides) { foreach (var (regex, value) in overrides) { if (regex.IsMatch(file)) return value; @@ -144,7 +144,7 @@ namespace Contentless { return null; } - private static ImporterInfo GetImporterFor(string file, ImporterInfo[] importers) { + private static ImporterInfo GetImporterFor(string file, IEnumerable importers) { var extension = Path.GetExtension(file); foreach (var importer in importers) { if (importer.Importer.FileExtensions.Contains(extension)) diff --git a/README.md b/README.md index fcdb767..0a3b5b3 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,13 @@ To add a configuration file to Contentless, simply create a file named `Contentl // If any files that were skipped without errors should be logged (Files that already have entries or files that were ignored) "logSkipped": true, // The list of files that should use a different importer than the one that Contentless automatically determined. Can use regex - "overrides": [ - // Entries are arrays containing the file regex and importer, for example [".json", "JsonImporter"] - // If you specify "Copy" as the importer, the file's Build Mode will be set to Copy rather than Build - ] + "overrides": { + // Entries are file regexes mapped to importer names, for example: ".json": "JsonImporter" + // If you specify "Copy" as the importer, the file's Build Mode will be set to Copy rather than Build, for example: ".txt": "Copy" + } } ``` +For an example of a config in use, see the [test config](https://github.com/Ellpeck/Contentless/blob/master/Test/Content/Contentless.json). # What it does When running Contentless and supplying the location of a MonoGame Content Pipeline project (`Content.mgcb`), it scans all of the files in the project's directory as well as its subdirectories. For each file, it checks if the `Content.mgcb` file already contains any references to that file. If no references are found, then a new reference to the file is added. diff --git a/Test/Content/Content.mgcb b/Test/Content/Content.mgcb index 3912407..84e8263 100644 --- a/Test/Content/Content.mgcb +++ b/Test/Content/Content.mgcb @@ -64,12 +64,11 @@ /importer:TiledMapTilesetImporter /processor:TiledMapTilesetProcessor /build:Tiled/Tileset.tsx +#begin Json/Copy.json +/copy:Json/Copy.json #begin Json/Test.json /importer:JsonContentImporter /processor:JsonContentProcessor /build:Json/Test.json -#begin Json/Copy.json -/copy:Json/Copy.json - diff --git a/Test/Content/Contentless.json b/Test/Content/Contentless.json index e8fa76a..b47fdf8 100644 --- a/Test/Content/Contentless.json +++ b/Test/Content/Contentless.json @@ -5,8 +5,8 @@ "Ex*.png" ], "logSkipped": false, - "overrides": [ - ["Copy.*", "Copy"], - [".json", "JsonContentImporter"] - ] + "overrides": { + "Copy.*": "Copy", + ".json": "JsonContentImporter" + } } \ No newline at end of file