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" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -3,13 +3,13 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Contentless {
|
||||
public static class Program {
|
||||
|
||||
private static readonly string[] ExcludedFolders = {"bin/", "obj/"};
|
||||
|
||||
public static void Main(string[] args) {
|
||||
if (args.Length != 1) {
|
||||
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}");
|
||||
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
|
||||
foreach (var line in content) {
|
||||
if (!line.StartsWith("/reference:"))
|
||||
|
@ -34,8 +51,8 @@ namespace Contentless {
|
|||
try {
|
||||
Assembly.LoadFrom(refPath);
|
||||
Console.WriteLine($"Using reference {refPath}");
|
||||
} catch (Exception) {
|
||||
Console.WriteLine($"Couldn't load reference {refPath}, file types that require this reference won't be added automatically");
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine($"Error loading reference {refPath}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,13 +62,14 @@ namespace Contentless {
|
|||
|
||||
var changed = false;
|
||||
foreach (var file in contentFile.Directory.EnumerateFiles("*", SearchOption.AllDirectories)) {
|
||||
// is the file the content file?
|
||||
if (file.Name == contentFile.Name)
|
||||
// is the file the content or config file?
|
||||
if (file.Name == contentFile.Name || file.Name == configFile.Name)
|
||||
continue;
|
||||
var relative = GetRelativePath(contentFile.DirectoryName, file.FullName).Replace("\\", "/");
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,3 +65,8 @@
|
|||
/processor:TiledMapTilesetProcessor
|
||||
/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