Changed 9p and tatlas' to use a separately loaded texture.

This commit is contained in:
2019-03-20 19:28:16 -05:00
parent 4add103f94
commit e3535f5662
30 changed files with 184 additions and 169 deletions

View File

@@ -5,22 +5,12 @@ using System.IO;
namespace RecrownedAthenaeum.Pipeline.NinePatch
{
[ContentImporter(".9p", DisplayName = "Nine Patch Importer", DefaultProcessor = "NinePatchProcessor")]
internal class NinePatchImporter : ContentImporter<NinePatchImporter.Package>
[ContentImporter(".9p", DisplayName = "Nine Patch Importer - RecrownedAthenaeum", DefaultProcessor = "NinePatchProcessor")]
internal class NinePatchImporter : ContentImporter<NinePatchData>
{
public override Package Import(string filename, ContentImporterContext context)
public override NinePatchData Import(string filename, ContentImporterContext context)
{
Package package;
package.ninePatchData = JsonConvert.DeserializeObject<NinePatchData>(File.ReadAllText(filename));
package.textureBytes = File.ReadAllBytes(package.ninePatchData.textureName);
return package;
}
internal struct Package
{
internal byte[] textureBytes;
internal NinePatchData ninePatchData;
return JsonConvert.DeserializeObject<NinePatchData>(File.ReadAllText(filename));
}
}
}

View File

@@ -1,25 +1,19 @@
using Microsoft.Xna.Framework.Content.Pipeline;
using Newtonsoft.Json;
using RecrownedAthenaeum.Data;
using System.IO;
using System.Text;
namespace RecrownedAthenaeum.Pipeline.NinePatch
{
[ContentImporter(DisplayName = "Nine Patch - RecrownedAthenaeum")]
class NinePatchProcessor : ContentProcessor<NinePatchImporter.Package, NinePatchProcessor.Package>
class NinePatchProcessor : ContentProcessor<NinePatchData, NinePatchData>
{
public override Package Process(NinePatchImporter.Package input, ContentProcessorContext context)
public override NinePatchData Process(NinePatchData input, ContentProcessorContext context)
{
Package package;
package.ninePatchDataBytes = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(input.ninePatchData));
package.textureBytes = input.textureBytes;
return package;
}
internal struct Package
{
internal byte[] ninePatchDataBytes;
internal byte[] textureBytes;
if (Path.GetFileNameWithoutExtension(context.SourceIdentity.SourceFilename) == Path.GetFileNameWithoutExtension(input.textureName)) throw new InvalidContentException("Ninepatch data and texture for the data can't have the same name.");
context.AddDependency(input.textureName);
return input;
}
}
}

View File

@@ -2,23 +2,25 @@
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Newtonsoft.Json;
using RecrownedAthenaeum.Data;
using System.IO;
namespace RecrownedAthenaeum.Pipeline.NinePatch
{
[ContentTypeWriter]
class NinePatchWriter : ContentTypeWriter<NinePatchProcessor.Package>
class NinePatchWriter : ContentTypeWriter<NinePatchData>
{
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return "RecrownedAthenaeum.ContentReaders.NinePatchDataReader, RecrownedAthenaeum";
}
protected override void Write(ContentWriter output, NinePatchProcessor.Package value)
protected override void Write(ContentWriter output, NinePatchData value)
{
output.Write(value.textureBytes.Length);
output.Write(value.textureBytes);
output.Write(value.ninePatchDataBytes.Length);
output.Write(value.ninePatchDataBytes);
output.Write(Path.GetFileNameWithoutExtension(value.textureName));
output.Write(value.left);
output.Write(value.right);
output.Write(value.bottom);
output.Write(value.top);
}
}
}