mirror of
https://github.com/Ellpeck/Contentless.git
synced 2024-11-21 23:13:29 +01:00
reformat overrides and allow the option of adding processor parameters
This commit is contained in:
parent
2b16973913
commit
a2bf711912
7 changed files with 83 additions and 70 deletions
|
@ -5,14 +5,27 @@ using Newtonsoft.Json.Linq;
|
|||
namespace Contentless {
|
||||
public class Config {
|
||||
|
||||
[JsonProperty(PropertyName = "exclude")]
|
||||
[JsonProperty("exclude")]
|
||||
public string[] ExcludedFiles = {"bin/", "obj/"};
|
||||
|
||||
[JsonProperty(PropertyName = "logSkipped")]
|
||||
[JsonProperty("logSkipped")]
|
||||
public bool LogSkipped = true;
|
||||
|
||||
[JsonProperty(PropertyName = "overrides")]
|
||||
public Dictionary<string, JToken> Overrides = new Dictionary<string, JToken>();
|
||||
[JsonProperty("overrides")]
|
||||
public Dictionary<string, Override> Overrides = new Dictionary<string, Override>();
|
||||
|
||||
}
|
||||
|
||||
public class Override {
|
||||
|
||||
[JsonProperty("importer")]
|
||||
public string Importer;
|
||||
[JsonProperty("processor")]
|
||||
public string Processor;
|
||||
[JsonProperty("processorParams")]
|
||||
public Dictionary<string, string> ProcessorParams = new Dictionary<string, string>();
|
||||
[JsonProperty("copy")]
|
||||
public bool Copy;
|
||||
|
||||
}
|
||||
}
|
|
@ -12,9 +12,5 @@ namespace Contentless {
|
|||
this.Type = type;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return this.Type.Name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -4,13 +4,11 @@ namespace Contentless {
|
|||
public class OverrideInfo {
|
||||
|
||||
public readonly Regex Regex;
|
||||
public readonly string Importer;
|
||||
public readonly string Processor;
|
||||
public readonly Override Override;
|
||||
|
||||
public OverrideInfo(Regex regex, string importer, string processor) {
|
||||
public OverrideInfo(Regex regex, Override over) {
|
||||
this.Regex = regex;
|
||||
this.Importer = importer;
|
||||
this.Processor = processor;
|
||||
this.Override = over;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -86,29 +86,32 @@ namespace Contentless {
|
|||
|
||||
ImporterInfo importer = null;
|
||||
string processor = null;
|
||||
Dictionary<string, string> processorParams = null;
|
||||
|
||||
// override importers
|
||||
var over = GetOverrideFor(relative, overrides);
|
||||
if (over != null) {
|
||||
processorParams = over.Override.ProcessorParams;
|
||||
|
||||
// copy special case
|
||||
if (over.Importer == "Copy" || over.Processor == "Copy") {
|
||||
if (over.Override.Copy) {
|
||||
CopyFile(content, relative);
|
||||
changed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(over.Importer) && over.Importer != "Auto") {
|
||||
importer = importers.Find(i => i.Type.Name == over.Importer);
|
||||
if (!string.IsNullOrEmpty(over.Override.Importer)) {
|
||||
importer = importers.Find(i => i.Type.Name == over.Override.Importer);
|
||||
if (importer == null) {
|
||||
Console.WriteLine($"Override importer {over.Importer} not found for file {relative}");
|
||||
Console.WriteLine($"Override importer {over.Override.Importer} not found for file {relative}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(over.Processor) && over.Processor != "Auto") {
|
||||
processor = processors.Find(p => p == over.Processor);
|
||||
if (!string.IsNullOrEmpty(over.Override.Processor)) {
|
||||
processor = processors.Find(p => p == over.Override.Processor);
|
||||
if (processor == null) {
|
||||
Console.WriteLine($"Override processor {over.Processor} not found for file {relative}");
|
||||
Console.WriteLine($"Override processor {over.Override.Processor} not found for file {relative}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +129,7 @@ namespace Contentless {
|
|||
continue;
|
||||
}
|
||||
|
||||
AddFile(content, relative, importer, processor);
|
||||
AddFile(content, relative, importer.Type.Name, processor, processorParams);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
@ -154,29 +157,16 @@ namespace Contentless {
|
|||
if (processor != null)
|
||||
processors.Add(type.Name);
|
||||
}
|
||||
} catch (Exception) {
|
||||
} catch {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
return (importers, processors);
|
||||
}
|
||||
|
||||
private static IEnumerable<OverrideInfo> GetOverrides(Dictionary<string, JToken> config) {
|
||||
foreach (var entry in config) {
|
||||
var regex = MakeFileRegex(entry.Key);
|
||||
if (entry.Value.Type == JTokenType.Array) {
|
||||
var arr = (JArray) entry.Value;
|
||||
if (arr.Count != 2) {
|
||||
Console.WriteLine("The override config " + entry.Key + " is invalid: The array needs to contain exactly two entries");
|
||||
} else {
|
||||
yield return new OverrideInfo(regex, arr[0].ToString(), arr[1].ToString());
|
||||
}
|
||||
} else if (entry.Value.Type == JTokenType.String) {
|
||||
yield return new OverrideInfo(regex, entry.Value.ToString(), null);
|
||||
} else {
|
||||
Console.WriteLine("The override config " + entry.Key + " is invalid: Should be an array or a string");
|
||||
}
|
||||
}
|
||||
private static IEnumerable<OverrideInfo> GetOverrides(Dictionary<string, Override> config) {
|
||||
foreach (var entry in config)
|
||||
yield return new OverrideInfo(MakeFileRegex(entry.Key), entry.Value);
|
||||
}
|
||||
|
||||
private static OverrideInfo GetOverrideFor(string file, IEnumerable<OverrideInfo> overrides) {
|
||||
|
@ -215,10 +205,14 @@ namespace Contentless {
|
|||
return content;
|
||||
}
|
||||
|
||||
private static void AddFile(List<string> content, string relative, ImporterInfo importer, string processor) {
|
||||
private static void AddFile(List<string> content, string relative, string importer, string processor, Dictionary<string, string> processorParams) {
|
||||
content.Add($"#begin {relative}");
|
||||
content.Add($"/importer:{importer}");
|
||||
content.Add($"/processor:{processor}");
|
||||
if (processorParams != null) {
|
||||
foreach (var kv in processorParams)
|
||||
content.Add($"/processorParam:{kv.Key}={kv.Value}");
|
||||
}
|
||||
content.Add($"/build:{relative}");
|
||||
content.Add("");
|
||||
Console.WriteLine($"Adding file {relative} with importer {importer} and processor {processor}");
|
||||
|
|
28
README.md
28
README.md
|
@ -30,18 +30,32 @@ 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)
|
||||
// Default: true
|
||||
"logSkipped": true,
|
||||
// The list of files that should use a different importer than the one that Contentless automatically determined. Can use regex
|
||||
// Specifying a string as the value represents an override importer, specifying an array with two entries represents the override importer and override processor
|
||||
// The list of files that should use a different importer or processor than the one that Contentless automatically determined. Can use regex.
|
||||
// Default: {}
|
||||
"overrides": {
|
||||
// Example: Make all files matching the regex ".json" use the importer "JsonImporter"
|
||||
".json": "JsonImporter",
|
||||
// Example: Specifying "Copy" as the importer sets the file's Build Mode to "Copy" instead of "Build"
|
||||
".txt": "Copy",
|
||||
".json": {
|
||||
"importer": "JsonImporter"
|
||||
},
|
||||
// Example: Specifying both an importer and a processor
|
||||
".ogg": ["OggImporter", "SongProcessor"],
|
||||
".ogg": {
|
||||
"importer": "OggImporter",
|
||||
"processor": "SongProcessor"
|
||||
},
|
||||
// Example: Only specifying a processor
|
||||
".wav": ["Auto", "SoundEffectProcessor"]
|
||||
".wav": {
|
||||
"processor": "SoundEffectProcessor"
|
||||
},
|
||||
// Example: Setting a file to the Copy build action
|
||||
".txt": {
|
||||
"copy": true
|
||||
},
|
||||
// Example: Adding processor parameters for files
|
||||
"TestFile.png": {
|
||||
"processorParams": {
|
||||
"TextureFormat": "Compressed"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -17,11 +17,6 @@
|
|||
#begin Json/Copy.json
|
||||
/copy:Json/Copy.json
|
||||
|
||||
#begin Json/Test.json
|
||||
/importer:JsonContentImporter
|
||||
/processor:FontTextureProcessor
|
||||
/build:Json/Test.json
|
||||
|
||||
#begin Locale/Interface.xml
|
||||
/importer:XmlImporter
|
||||
/processor:FontTextureProcessor
|
||||
|
@ -30,30 +25,18 @@
|
|||
#begin Textures/Icons.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:Textures/Icons.png
|
||||
|
||||
#begin Textures/Inside.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:Textures/Inside.png
|
||||
|
||||
#begin Tiled/Map.tmx
|
||||
/importer:TiledMapImporter
|
||||
/processor:TiledMapProcessor
|
||||
/build:Tiled/Map.tmx
|
||||
|
||||
#begin Tiled/Tiles.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:Tiled/Tiles.png
|
||||
|
||||
#begin Tiled/Tileset.tsx
|
||||
/importer:TiledMapTilesetImporter
|
||||
/processor:TiledMapTilesetProcessor
|
||||
/build:Tiled/Tileset.tsx
|
||||
|
||||
#begin Textures/Exclude.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/build:Textures/Exclude.png
|
||||
|
||||
|
|
|
@ -6,9 +6,24 @@
|
|||
],
|
||||
"logSkipped": false,
|
||||
"overrides": {
|
||||
"Copy.*": "Copy",
|
||||
".json": ["JsonContentImporter", "FontTextureProcessor"],
|
||||
".ogg": ["OggImporter", "SongProcessor"],
|
||||
".xml": ["", "FontTextureProcessor"]
|
||||
"Copy.*": {
|
||||
"copy": true
|
||||
},
|
||||
".json": {
|
||||
"importer": "JsonContentImporter",
|
||||
"processor": "FontTextureProcessor"
|
||||
},
|
||||
".ogg": {
|
||||
"importer": "OggImporter",
|
||||
"processor": "SongProcessor"
|
||||
},
|
||||
".xml": {
|
||||
"processor": "FontTextureProcessor"
|
||||
},
|
||||
".png": {
|
||||
"processorParams": {
|
||||
"TextureFormat": "Compressed"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue