From 69d50cbb1a3b6750b80cc018d1958fe703325a4f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 28 Oct 2019 23:54:06 +0100 Subject: [PATCH] added the ability to copy files instead of building them --- Contentless/Program.cs | 15 ++++++++++++++- README.md | 10 ++++------ Test/Content/Content.mgcb | 13 ++++++++----- Test/Content/Contentless.json | 1 + Test/Content/Json/Copy.json | 3 +++ 5 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 Test/Content/Json/Copy.json diff --git a/Contentless/Program.cs b/Contentless/Program.cs index f922544..66478c3 100644 --- a/Contentless/Program.cs +++ b/Contentless/Program.cs @@ -87,6 +87,13 @@ namespace Contentless { // override importers var over = GetOverrideImporterFor(relative, overrides); if (over != null) { + // copy special case + if (over == "Copy") { + CopyFile(content, relative); + changed = true; + continue; + } + importer = Array.Find(importers, i => i.Type.Name == over); if (importer == null) { Console.WriteLine($"Override importer {over} not found for file {relative}"); @@ -171,10 +178,16 @@ namespace Contentless { content.Add($"/processor:{importer.Importer.DefaultProcessor}"); content.Add($"/build:{relative}"); content.Add(""); - Console.WriteLine($"Adding file {relative} with importer {importer.Type.Name} and processor {importer.Importer.DefaultProcessor}"); } + private static void CopyFile(List content, string relative) { + content.Add($"#begin {relative}"); + content.Add($"/copy:{relative}"); + content.Add(""); + Console.WriteLine($"Adding file {relative} with the Copy build action"); + } + private static string GetRelativePath(string relativeTo, string path) { if (!relativeTo.EndsWith(Path.DirectorySeparatorChar.ToString())) relativeTo += Path.DirectorySeparatorChar; diff --git a/README.md b/README.md index 8100285..fcdb767 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,12 @@ To add a configuration file to Contentless, simply create a file named `Contentl "obj/", "bin/" ], - // 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, - // 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": [ - // Entries are arrays containing the file regex and importer, e.g. - // [".json", "JsonImporter"] + // 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 ] } ``` diff --git a/Test/Content/Content.mgcb b/Test/Content/Content.mgcb index da83b36..3912407 100644 --- a/Test/Content/Content.mgcb +++ b/Test/Content/Content.mgcb @@ -14,11 +14,6 @@ #---------------------------------- Content ---------------------------------# -#begin Json/Test.json -/importer:JsonContentImporter -/processor:JsonContentProcessor -/build:Json/Test.json - #begin Locale/Interface.xml /importer:XmlImporter /processor:PassThroughProcessor @@ -70,3 +65,11 @@ /processor:TiledMapTilesetProcessor /build:Tiled/Tileset.tsx +#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 8977084..e8fa76a 100644 --- a/Test/Content/Contentless.json +++ b/Test/Content/Contentless.json @@ -6,6 +6,7 @@ ], "logSkipped": false, "overrides": [ + ["Copy.*", "Copy"], [".json", "JsonContentImporter"] ] } \ No newline at end of file diff --git a/Test/Content/Json/Copy.json b/Test/Content/Json/Copy.json new file mode 100644 index 0000000..32a5e55 --- /dev/null +++ b/Test/Content/Json/Copy.json @@ -0,0 +1,3 @@ +{ + "test": "copy!" +} \ No newline at end of file