diff --git a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchImporter.cs b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchImporter.cs new file mode 100644 index 0000000..cb6392f --- /dev/null +++ b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchImporter.cs @@ -0,0 +1,26 @@ +using Microsoft.Xna.Framework.Content.Pipeline; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RecrownedAthenaeum.Pipeline.NinePatch +{ + [ContentImporter(".9p", DisplayName = "Nine Patch Importer")] + internal class NinePatchImporter : ContentImporter + { + public override NinePatchData Import(string filename, ContentImporterContext context) + { + NinePatchData data; + using (StreamReader stream = new StreamReader(filename)) + { + data = JsonConvert.DeserializeObject(stream.ReadToEnd()); + } + context.AddDependency(data.textureName); + return data; + } + } +} diff --git a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchProcessor.cs b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchProcessor.cs new file mode 100644 index 0000000..b7688c7 --- /dev/null +++ b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchProcessor.cs @@ -0,0 +1,22 @@ +using Microsoft.Xna.Framework.Content.Pipeline; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RecrownedAthenaeum.Pipeline.NinePatch +{ + [ContentImporter(DisplayName = "Nine Patch Importer")] + class NinePatchProcessor : ContentProcessor + { + public override byte[] Process(NinePatchData input, ContentProcessorContext context) + { + string serialized = JsonConvert.SerializeObject(input); + return Encoding.UTF8.GetBytes(serialized); + } + } +} diff --git a/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchWriter.cs b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchWriter.cs new file mode 100644 index 0000000..e6fc05d --- /dev/null +++ b/RecrownedAthenaeum.Pipeline/NinePatch/NinePatchWriter.cs @@ -0,0 +1,25 @@ +using Microsoft.Xna.Framework.Content.Pipeline; +using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RecrownedAthenaeum.Pipeline.NinePatch +{ + [ContentTypeWriter] + class NinePatchWriter : ContentTypeWriter + { + public override string GetRuntimeReader(TargetPlatform targetPlatform) + { + return "RecrownedAthenaeum.Pipeline, NinePatchDataReader"; + } + + protected override void Write(ContentWriter output, byte[] value) + { + output.Write(value.Length); + output.Write(value); + } + } +} diff --git a/RecrownedAthenaeum.Pipeline/RecrownedAthenaeum.Pipeline.csproj b/RecrownedAthenaeum.Pipeline/RecrownedAthenaeum.Pipeline.csproj index b81b0bc..2691450 100644 --- a/RecrownedAthenaeum.Pipeline/RecrownedAthenaeum.Pipeline.csproj +++ b/RecrownedAthenaeum.Pipeline/RecrownedAthenaeum.Pipeline.csproj @@ -50,7 +50,10 @@ + + + diff --git a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs index 05f1577..17f0d13 100644 --- a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs +++ b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasImporter.cs @@ -1,13 +1,6 @@ using Microsoft.Xna.Framework.Content.Pipeline; -using Microsoft.Xna.Framework.Graphics; using Newtonsoft.Json; -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Serialization; namespace RecrownedAthenaeum.Pipeline.TextureAtlas { diff --git a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs index 2f03dd6..94b0f2d 100644 --- a/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs +++ b/RecrownedAthenaeum.Pipeline/TextureAtlas/TextureAtlasProcessor.cs @@ -18,17 +18,7 @@ namespace RecrownedAthenaeum.Pipeline.TextureAtlas public override byte[] Process(TextureAtlasData input, ContentProcessorContext context) { string serialized = JsonConvert.SerializeObject(input); - byte[] bytes = Encoding.UTF8.GetBytes(serialized); - - using (MemoryStream outStream = new MemoryStream()) - { - using (GZipStream gZipStream = new GZipStream(outStream, CompressionLevel.Optimal)) - { - gZipStream.Write(bytes, 0, bytes.Length); - byte[] compressed = outStream.ToArray(); - return compressed; - } - } + return Encoding.UTF8.GetBytes(serialized); } } } diff --git a/RecrownedAthenaeum/Pipeline/NinePatchDataReader.cs b/RecrownedAthenaeum/Pipeline/NinePatchDataReader.cs new file mode 100644 index 0000000..506de21 --- /dev/null +++ b/RecrownedAthenaeum/Pipeline/NinePatchDataReader.cs @@ -0,0 +1,22 @@ +using Microsoft.Xna.Framework.Content; +using Newtonsoft.Json; +using RecrownedAthenaeum.DataTypes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RecrownedAthenaeum.Pipeline +{ + class NinePatchDataReader : ContentTypeReader + { + protected override DataTypes.NinePatch Read(ContentReader input, DataTypes.NinePatch existingInstance) + { + int length = input.ReadInt32(); + byte[] bytes = input.ReadBytes(length); + + return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(bytes)); + } + } +} diff --git a/RecrownedAthenaeum/Pipeline/TextureAtlasDataReader.cs b/RecrownedAthenaeum/Pipeline/TextureAtlasDataReader.cs index 1d05c1a..7ef1b5f 100644 --- a/RecrownedAthenaeum/Pipeline/TextureAtlasDataReader.cs +++ b/RecrownedAthenaeum/Pipeline/TextureAtlasDataReader.cs @@ -19,20 +19,8 @@ namespace RecrownedAthenaeum.Pipeline protected override DataTypes.TextureAtlas Read(ContentReader input, DataTypes.TextureAtlas existingInstance) { int length = input.ReadInt32(); - byte[] compressedBytes = input.ReadBytes(length); - byte[] decompressedBytes; - using (MemoryStream inStream = new MemoryStream(compressedBytes)) - { - using (GZipStream gZStream = new GZipStream(inStream, CompressionLevel.Optimal)) - { - using (MemoryStream outStream = new MemoryStream()) - { - gZStream.CopyTo(outStream); - decompressedBytes = outStream.ToArray(); - } - } - } - TextureAtlasData atlasData = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(decompressedBytes)); + byte[] bytes = input.ReadBytes(length); + TextureAtlasData atlasData = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(bytes)); DataTypes.TextureAtlas atlas; Texture2D atlasTexture = input.ContentManager.Load(atlasData.textureName); diff --git a/RecrownedAthenaeum/RecrownedAthenaeum.csproj b/RecrownedAthenaeum/RecrownedAthenaeum.csproj index 4e2707d..0f2e93b 100644 --- a/RecrownedAthenaeum/RecrownedAthenaeum.csproj +++ b/RecrownedAthenaeum/RecrownedAthenaeum.csproj @@ -63,6 +63,7 @@ +