mirror of
https://github.com/Ellpeck/Contentless.git
synced 2024-11-22 07:23:30 +01:00
added a config
This commit is contained in:
parent
ad65e0cb06
commit
f64baaeb6a
5 changed files with 41 additions and 7 deletions
|
@ -9,4 +9,8 @@
|
||||||
<ProjectReference Include="..\MonoGame\MonoGame.Framework.Content.Pipeline\MonoGame.Framework.Content.Pipeline.Windows.csproj" />
|
<ProjectReference Include="..\MonoGame\MonoGame.Framework.Content.Pipeline\MonoGame.Framework.Content.Pipeline.Windows.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -3,13 +3,13 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Microsoft.Xna.Framework.Content.Pipeline;
|
using Microsoft.Xna.Framework.Content.Pipeline;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Contentless {
|
namespace Contentless {
|
||||||
public static class Program {
|
public static class Program {
|
||||||
|
|
||||||
private static readonly string[] ExcludedFolders = {"bin/", "obj/"};
|
|
||||||
|
|
||||||
public static void Main(string[] args) {
|
public static void Main(string[] args) {
|
||||||
if (args.Length != 1) {
|
if (args.Length != 1) {
|
||||||
Console.WriteLine("Please specify the location of the content file you want to use");
|
Console.WriteLine("Please specify the location of the content file you want to use");
|
||||||
|
@ -25,6 +25,23 @@ namespace Contentless {
|
||||||
Console.WriteLine($"Using content file {contentFile}");
|
Console.WriteLine($"Using content file {contentFile}");
|
||||||
var content = ReadContent(contentFile);
|
var content = ReadContent(contentFile);
|
||||||
|
|
||||||
|
// load config
|
||||||
|
var config = new Config();
|
||||||
|
var configFile = new FileInfo(Path.Combine(contentFile.DirectoryName, "Contentless.json"));
|
||||||
|
if (configFile.Exists) {
|
||||||
|
using (var stream = configFile.OpenText()) {
|
||||||
|
try {
|
||||||
|
config = JsonConvert.DeserializeObject<Config>(stream.ReadToEnd());
|
||||||
|
Console.WriteLine($"Using config from {configFile}");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Console.WriteLine($"Error loading config from {configFile}: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Console.WriteLine("Using default config");
|
||||||
|
}
|
||||||
|
var excluded = Array.ConvertAll(config.ExcludedFiles, s => new Regex(s.Replace(".", "[.]").Replace("*", ".*").Replace("?", ".")));
|
||||||
|
|
||||||
// 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) {
|
||||||
if (!line.StartsWith("/reference:"))
|
if (!line.StartsWith("/reference:"))
|
||||||
|
@ -34,8 +51,8 @@ namespace Contentless {
|
||||||
try {
|
try {
|
||||||
Assembly.LoadFrom(refPath);
|
Assembly.LoadFrom(refPath);
|
||||||
Console.WriteLine($"Using reference {refPath}");
|
Console.WriteLine($"Using reference {refPath}");
|
||||||
} catch (Exception) {
|
} catch (Exception e) {
|
||||||
Console.WriteLine($"Couldn't load reference {refPath}, file types that require this reference won't be added automatically");
|
Console.WriteLine($"Error loading reference {refPath}: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,13 +62,14 @@ namespace Contentless {
|
||||||
|
|
||||||
var changed = false;
|
var changed = false;
|
||||||
foreach (var file in contentFile.Directory.EnumerateFiles("*", SearchOption.AllDirectories)) {
|
foreach (var file in contentFile.Directory.EnumerateFiles("*", SearchOption.AllDirectories)) {
|
||||||
// is the file the content file?
|
// is the file the content or config file?
|
||||||
if (file.Name == contentFile.Name)
|
if (file.Name == contentFile.Name || file.Name == configFile.Name)
|
||||||
continue;
|
continue;
|
||||||
var relative = GetRelativePath(contentFile.DirectoryName, file.FullName).Replace("\\", "/");
|
var relative = GetRelativePath(contentFile.DirectoryName, file.FullName).Replace("\\", "/");
|
||||||
|
|
||||||
// is the file in an excluded directory?
|
// is the file in an excluded directory?
|
||||||
if (ExcludedFolders.Any(e => relative.Contains(e))) {
|
if (excluded.Any(e => e.IsMatch(relative))) {
|
||||||
|
Console.WriteLine($"Skipping excluded file {relative}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,3 +65,8 @@
|
||||||
/processor:TiledMapTilesetProcessor
|
/processor:TiledMapTilesetProcessor
|
||||||
/build:Tiled/Tileset.tsx
|
/build:Tiled/Tileset.tsx
|
||||||
|
|
||||||
|
#begin Contentless.json
|
||||||
|
/importer:TexturePackerJsonImporter
|
||||||
|
/processor:TexturePackerProcessor
|
||||||
|
/build:Contentless.json
|
||||||
|
|
||||||
|
|
7
Test/Content/Contentless.json
Normal file
7
Test/Content/Contentless.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"exclude": [
|
||||||
|
"obj/",
|
||||||
|
"bin/",
|
||||||
|
"Ex*.png"
|
||||||
|
]
|
||||||
|
}
|
BIN
Test/Content/Textures/Exclude.png
Normal file
BIN
Test/Content/Textures/Exclude.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.4 KiB |
Loading…
Reference in a new issue