made override structure a bit better

This commit is contained in:
Ellpeck 2019-10-30 23:59:47 +01:00
parent 69d50cbb1a
commit 94ed85bab7
5 changed files with 16 additions and 15 deletions

View file

@ -1,3 +1,4 @@
using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Contentless { namespace Contentless {
@ -10,7 +11,7 @@ namespace Contentless {
public bool LogSkipped = true; public bool LogSkipped = true;
[JsonProperty(PropertyName = "overrides")] [JsonProperty(PropertyName = "overrides")]
public string[][] Overrides = { }; public Dictionary<string, string> Overrides = new Dictionary<string, string>();
} }
} }

View file

@ -41,7 +41,7 @@ namespace Contentless {
Console.WriteLine("Using default config"); Console.WriteLine("Using default config");
} }
var excluded = config.ExcludedFiles.Select(MakeFileRegex).ToArray(); 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 // load any references to be able to include custom content types as well
foreach (var line in content) { 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) { foreach (var (regex, value) in overrides) {
if (regex.IsMatch(file)) if (regex.IsMatch(file))
return value; return value;
@ -144,7 +144,7 @@ namespace Contentless {
return null; return null;
} }
private static ImporterInfo GetImporterFor(string file, ImporterInfo[] importers) { private static ImporterInfo GetImporterFor(string file, IEnumerable<ImporterInfo> importers) {
var extension = Path.GetExtension(file); var extension = Path.GetExtension(file);
foreach (var importer in importers) { foreach (var importer in importers) {
if (importer.Importer.FileExtensions.Contains(extension)) if (importer.Importer.FileExtensions.Contains(extension))

View file

@ -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) // If any files that were skipped without errors should be logged (Files that already have entries or files that were ignored)
"logSkipped": true, "logSkipped": true,
// The list of files that should use a different importer than the one that Contentless automatically determined. Can use regex // The list of files that should use a different importer than the one that Contentless automatically determined. Can use regex
"overrides": [ "overrides": {
// Entries are arrays containing the file regex and importer, for example [".json", "JsonImporter"] // 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 // 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 # 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. 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.

View file

@ -64,12 +64,11 @@
/importer:TiledMapTilesetImporter /importer:TiledMapTilesetImporter
/processor:TiledMapTilesetProcessor /processor:TiledMapTilesetProcessor
/build:Tiled/Tileset.tsx /build:Tiled/Tileset.tsx
#begin Json/Copy.json
/copy:Json/Copy.json
#begin Json/Test.json #begin Json/Test.json
/importer:JsonContentImporter /importer:JsonContentImporter
/processor:JsonContentProcessor /processor:JsonContentProcessor
/build:Json/Test.json /build:Json/Test.json
#begin Json/Copy.json
/copy:Json/Copy.json

View file

@ -5,8 +5,8 @@
"Ex*.png" "Ex*.png"
], ],
"logSkipped": false, "logSkipped": false,
"overrides": [ "overrides": {
["Copy.*", "Copy"], "Copy.*": "Copy",
[".json", "JsonContentImporter"] ".json": "JsonContentImporter"
] }
} }