untested texture atlas pipeline system complete.
This commit is contained in:
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline.NinePatch
|
||||
{
|
||||
class NinePatchFile
|
||||
public class NinePatchData
|
||||
{
|
||||
public string name;
|
||||
public string bounds;
|
@@ -50,18 +50,12 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="NinePatch\NinePatchTemplate.cs" />
|
||||
<Compile Include="NinePatch\NinePatchData.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TextureAtlas\TextureAtlasWriter.cs" />
|
||||
<Compile Include="TextureAtlas\TextureAtlasImporter.cs" />
|
||||
<Compile Include="TextureAtlas\TextureAtlasProcessor.cs" />
|
||||
<Compile Include="TextureAtlas\TextureAtlasTemplate.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RecrownedAthenaeum\RecrownedAthenaeum.csproj">
|
||||
<Project>{95a926dc-1482-4368-91da-8d30ac04740a}</Project>
|
||||
<Name>RecrownedAthenaeum</Name>
|
||||
</ProjectReference>
|
||||
<Compile Include="TextureAtlas\TextureAtlasData.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
@@ -1,4 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Newtonsoft.Json;
|
||||
using RecrownedAthenaeum.Pipeline.NinePatch;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -8,15 +10,16 @@ using System.Xml.Serialization;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline.TextureAtlas
|
||||
{
|
||||
public class TextureAtlasFile
|
||||
public class TextureAtlasData
|
||||
{
|
||||
public string textureName;
|
||||
public TextureAtlasRegion[] regions;
|
||||
public string textureName;
|
||||
|
||||
public class TextureAtlasRegion
|
||||
{
|
||||
public string name;
|
||||
public Rectangle location;
|
||||
public NinePatchData ninePatchData;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
using Microsoft.Xna.Framework.Content.Pipeline;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.DataTypes;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -11,15 +11,16 @@ using System.Xml.Serialization;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline.TextureAtlas
|
||||
{
|
||||
internal class TextureAtlasImporter : ContentImporter<TextureAtlasFile>
|
||||
[ContentImporter(".atlas", DisplayName = "Texture Atlas Importer")]
|
||||
internal class TextureAtlasImporter : ContentImporter<TextureAtlasData>
|
||||
{
|
||||
public override TextureAtlasFile Import(string filename, ContentImporterContext context)
|
||||
public override TextureAtlasData Import(string filename, ContentImporterContext context)
|
||||
{
|
||||
StreamReader stream = new StreamReader(filename);
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(TextureAtlasFile));
|
||||
TextureAtlasFile atlas = (TextureAtlasFile)serializer.Deserialize(stream);
|
||||
context.AddDependency(atlas.textureName);
|
||||
stream.Dispose();
|
||||
TextureAtlasData atlas;
|
||||
using (StreamReader stream = new StreamReader(filename))
|
||||
{
|
||||
atlas = JsonConvert.DeserializeObject<TextureAtlasData>(stream.ReadToEnd());
|
||||
}
|
||||
return atlas;
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +1,35 @@
|
||||
using Microsoft.Xna.Framework.Content.Pipeline;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.DataTypes;
|
||||
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.TextureAtlas
|
||||
{
|
||||
class TextureAtlasProcessor : ContentProcessor<TextureAtlasFile, TextureAtlasFile>
|
||||
[ContentProcessor(DisplayName = "Texture Atlas Processor")]
|
||||
class TextureAtlasProcessor : ContentProcessor<TextureAtlasData, byte[]>
|
||||
{
|
||||
|
||||
public override TextureAtlasFile Process(TextureAtlasFile input, ContentProcessorContext context)
|
||||
public override byte[] Process(TextureAtlasData input, ContentProcessorContext context)
|
||||
{
|
||||
return input;
|
||||
string serialized = JsonConvert.SerializeObject(input);
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(serialized);
|
||||
|
||||
MemoryStream outStream = new MemoryStream();
|
||||
GZipStream gZStream = new GZipStream(outStream, CompressionLevel.Optimal);
|
||||
|
||||
gZStream.Write(bytes, 0, bytes.Length);
|
||||
|
||||
byte[] compressed = outStream.ToArray();
|
||||
|
||||
gZStream.Dispose();
|
||||
outStream.Dispose();
|
||||
return compressed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,16 +8,18 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline.TextureAtlas
|
||||
{
|
||||
class TextureAtlasWriter : ContentTypeWriter<TextureAtlasFile>
|
||||
[ContentTypeWriter]
|
||||
class TextureAtlasWriter : ContentTypeWriter<byte[]>
|
||||
{
|
||||
public override string GetRuntimeReader(TargetPlatform targetPlatform)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return "RecrownedAthenaeum.Pipeline, TextureAtlasDataReader";
|
||||
}
|
||||
|
||||
protected override void Write(ContentWriter output, TextureAtlasFile value)
|
||||
protected override void Write(ContentWriter output, byte[] value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
output.Write(value.Length);
|
||||
output.Write(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user