mirror of
https://github.com/Ellpeck/Contentless.git
synced 2024-11-22 07:23:30 +01:00
added overrides
This commit is contained in:
parent
c921747d0d
commit
6a623ceec6
7 changed files with 54 additions and 12 deletions
|
@ -9,5 +9,8 @@ namespace Contentless {
|
||||||
[JsonProperty(PropertyName = "logSkipped")]
|
[JsonProperty(PropertyName = "logSkipped")]
|
||||||
public bool LogSkipped = true;
|
public bool LogSkipped = true;
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "overrides")]
|
||||||
|
public string[][] Overrides = { };
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -40,7 +40,8 @@ namespace Contentless {
|
||||||
} else {
|
} else {
|
||||||
Console.WriteLine("Using default config");
|
Console.WriteLine("Using default config");
|
||||||
}
|
}
|
||||||
var excluded = Array.ConvertAll(config.ExcludedFiles, s => new Regex(s.Replace(".", "[.]").Replace("*", ".*").Replace("?", ".")));
|
var excluded = config.ExcludedFiles.Select(MakeFileRegex).ToArray();
|
||||||
|
var overrides = config.Overrides.Select(e => (MakeFileRegex(e[0]), e[1])).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) {
|
||||||
|
@ -81,7 +82,23 @@ namespace Contentless {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var importer = GetImporterFor(relative, importers);
|
ImporterInfo importer = null;
|
||||||
|
|
||||||
|
// override importers
|
||||||
|
var over = GetOverrideImporterFor(relative, overrides);
|
||||||
|
if (over != null) {
|
||||||
|
importer = Array.Find(importers, i => i.Type.Name == over);
|
||||||
|
if (importer == null) {
|
||||||
|
Console.WriteLine($"Override importer {over} not found for file {relative}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// normal importers
|
||||||
|
if (importer == null)
|
||||||
|
importer = GetImporterFor(relative, importers);
|
||||||
|
|
||||||
|
// no importer found :(
|
||||||
if (importer == null) {
|
if (importer == null) {
|
||||||
Console.WriteLine($"No importer found for file {relative}");
|
Console.WriteLine($"No importer found for file {relative}");
|
||||||
continue;
|
continue;
|
||||||
|
@ -112,6 +129,14 @@ namespace Contentless {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetOverrideImporterFor(string file, (Regex, string)[] overrides) {
|
||||||
|
foreach (var (regex, value) in overrides) {
|
||||||
|
if (regex.IsMatch(file))
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static ImporterInfo GetImporterFor(string file, ImporterInfo[] importers) {
|
private static ImporterInfo GetImporterFor(string file, ImporterInfo[] importers) {
|
||||||
var extension = Path.GetExtension(file);
|
var extension = Path.GetExtension(file);
|
||||||
foreach (var importer in importers) {
|
foreach (var importer in importers) {
|
||||||
|
@ -156,6 +181,10 @@ namespace Contentless {
|
||||||
return path.Replace(relativeTo, "");
|
return path.Replace(relativeTo, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Regex MakeFileRegex(string s) {
|
||||||
|
return new Regex(s.Replace(".", "[.]").Replace("*", ".*").Replace("?", "."));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
10
README.md
10
README.md
|
@ -13,7 +13,7 @@ Next, add Contentless to your build process by adding the following task to your
|
||||||
Contentless will now automatically add any content files from your `Content` directory and subdirectories to your `Content.mgcb` file if they haven't already been added either manually or by Contentless. No existing items' configurations will be overridden, so you can still use the Content Pipeline tool to modify any settings as well.
|
Contentless will now automatically add any content files from your `Content` directory and subdirectories to your `Content.mgcb` file if they haven't already been added either manually or by Contentless. No existing items' configurations will be overridden, so you can still use the Content Pipeline tool to modify any settings as well.
|
||||||
|
|
||||||
# Configuring
|
# Configuring
|
||||||
To add a configuration file to Contentless, simply create a file named `Contentless.json` in the same directory as your `Content.mgcb` file. You can use the config to change several options. For reference, here is a configuration file with the default values that are used if no config is supplied:
|
To add a configuration file to Contentless, simply create a file named `Contentless.json` in the same directory as your `Content.mgcb` file. You can use the config to change several options. For reference, here is a configuration file with the default values that are used if no config is supplied, along with some documentation:
|
||||||
```json5
|
```json5
|
||||||
{
|
{
|
||||||
// The list of files that should be excluded. Can use regex
|
// The list of files that should be excluded. Can use regex
|
||||||
|
@ -23,7 +23,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
|
// If any files that were skipped without errors should be logged
|
||||||
// (Files that already have entries or files that were ignored)
|
// (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
|
||||||
|
"overrides": [
|
||||||
|
// Entries are arrays containing the file regex and importer, e.g.
|
||||||
|
// [".json", "JsonImporter"]
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,11 @@
|
||||||
|
|
||||||
#---------------------------------- Content ---------------------------------#
|
#---------------------------------- Content ---------------------------------#
|
||||||
|
|
||||||
|
#begin Json/Test.json
|
||||||
|
/importer:JsonContentImporter
|
||||||
|
/processor:JsonContentProcessor
|
||||||
|
/build:Json/Test.json
|
||||||
|
|
||||||
#begin Locale/Interface.xml
|
#begin Locale/Interface.xml
|
||||||
/importer:XmlImporter
|
/importer:XmlImporter
|
||||||
/processor:PassThroughProcessor
|
/processor:PassThroughProcessor
|
||||||
|
@ -64,8 +69,4 @@
|
||||||
/importer:TiledMapTilesetImporter
|
/importer:TiledMapTilesetImporter
|
||||||
/processor:TiledMapTilesetProcessor
|
/processor:TiledMapTilesetProcessor
|
||||||
/build:Tiled/Tileset.tsx
|
/build:Tiled/Tileset.tsx
|
||||||
#begin Copy/Test.json
|
|
||||||
/importer:TexturePackerJsonImporter
|
|
||||||
/processor:TexturePackerProcessor
|
|
||||||
/build:Copy/Test.json
|
|
||||||
|
|
||||||
|
|
|
@ -4,5 +4,8 @@
|
||||||
"bin/",
|
"bin/",
|
||||||
"Ex*.png"
|
"Ex*.png"
|
||||||
],
|
],
|
||||||
"logSkipped": false
|
"logSkipped": false,
|
||||||
|
"overrides": [
|
||||||
|
[".json", "JsonContentImporter"]
|
||||||
|
]
|
||||||
}
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
3
Test/Content/Json/Test.json
Normal file
3
Test/Content/Json/Test.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"test": "test!"
|
||||||
|
}
|
Loading…
Reference in a new issue