removed compression step, added ninepatch stuff to pipeline.

This commit is contained in:
Harrison Deng 2018-12-23 11:04:11 -06:00
parent a97cfa0309
commit 5f525fbb9f
9 changed files with 102 additions and 32 deletions

View File

@ -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<NinePatchData>
{
public override NinePatchData Import(string filename, ContentImporterContext context)
{
NinePatchData data;
using (StreamReader stream = new StreamReader(filename))
{
data = JsonConvert.DeserializeObject<NinePatchData>(stream.ReadToEnd());
}
context.AddDependency(data.textureName);
return data;
}
}
}

View File

@ -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<NinePatchData, byte[]>
{
public override byte[] Process(NinePatchData input, ContentProcessorContext context)
{
string serialized = JsonConvert.SerializeObject(input);
return Encoding.UTF8.GetBytes(serialized);
}
}
}

View File

@ -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<byte[]>
{
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);
}
}
}

View File

@ -50,7 +50,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="NinePatch\NinePatchImporter.cs" />
<Compile Include="NinePatch\NinePatchData.cs" />
<Compile Include="NinePatch\NinePatchProcessor.cs" />
<Compile Include="NinePatch\NinePatchWriter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TextureAtlas\TextureAtlasWriter.cs" />
<Compile Include="TextureAtlas\TextureAtlasImporter.cs" />

View File

@ -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
{

View File

@ -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);
}
}
}

View File

@ -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<DataTypes.NinePatch>
{
protected override DataTypes.NinePatch Read(ContentReader input, DataTypes.NinePatch existingInstance)
{
int length = input.ReadInt32();
byte[] bytes = input.ReadBytes(length);
return JsonConvert.DeserializeObject<DataTypes.NinePatch>(Encoding.UTF8.GetString(bytes));
}
}
}

View File

@ -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<TextureAtlasData>(Encoding.UTF8.GetString(decompressedBytes));
byte[] bytes = input.ReadBytes(length);
TextureAtlasData atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(Encoding.UTF8.GetString(bytes));
DataTypes.TextureAtlas atlas;
Texture2D atlasTexture = input.ContentManager.Load<Texture2D>(atlasData.textureName);

View File

@ -63,6 +63,7 @@
<Compile Include="Input\InputUtilities.cs" />
<Compile Include="ParticleSystem\Particle.cs" />
<Compile Include="Persistence\PreferencesManager.cs" />
<Compile Include="Pipeline\NinePatchDataReader.cs" />
<Compile Include="Pipeline\TextureAtlasDataReader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScreenSystem\ITransition.cs" />