mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-25 08:22:15 +00:00
changed the bitmap font processor to use bson
This commit is contained in:
@@ -10,7 +10,7 @@ namespace MonoGame.Extended.Content.Pipeline
|
||||
{
|
||||
public override FontFile Import(string filename, ContentImporterContext context)
|
||||
{
|
||||
context.Logger.LogMessage("Importing {0}", filename);
|
||||
context.Logger.LogMessage("Importing XML file: {0}", filename);
|
||||
|
||||
using (var streamReader = new StreamReader(filename))
|
||||
{
|
||||
|
||||
@@ -2,28 +2,37 @@ using System;
|
||||
using System.IO;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline;
|
||||
using MonoGame.Extended.BitmapFonts;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Bson;
|
||||
|
||||
namespace MonoGame.Extended.Content.Pipeline
|
||||
{
|
||||
[ContentProcessor(DisplayName = "BMFont Processor - MonoGame.Extended")]
|
||||
public class BitmapFontProcessor : ContentProcessor<FontFile, BitmapFont>
|
||||
public class BsonData
|
||||
{
|
||||
public override BitmapFont Process(FontFile input, ContentProcessorContext context)
|
||||
public BsonData(byte[] data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
|
||||
public byte[] Data { get; private set; }
|
||||
}
|
||||
|
||||
[ContentProcessor(DisplayName = "BMFont Processor - MonoGame.Extended")]
|
||||
public class BitmapFontProcessor : ContentProcessor<FontFile, BsonData>
|
||||
{
|
||||
public override BsonData Process(FontFile input, ContentProcessorContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
context.Logger.LogMessage("Processing BMFont");
|
||||
|
||||
var fileName = input.Pages[0].File;
|
||||
context.Logger.LogMessage("fileName {0}", fileName);
|
||||
|
||||
var assetName = Path.GetFileNameWithoutExtension(fileName);
|
||||
context.Logger.LogMessage("assetName {0}", assetName);
|
||||
|
||||
return new BitmapFont(input)
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
TextureFilename = assetName
|
||||
};
|
||||
var jsonSerialzier = new JsonSerializer();
|
||||
var bsonWriter = new BsonWriter(memoryStream);
|
||||
jsonSerialzier.Serialize(bsonWriter, input);
|
||||
return new BsonData(memoryStream.ToArray());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -6,11 +6,11 @@ using Newtonsoft.Json;
|
||||
namespace MonoGame.Extended.Content.Pipeline
|
||||
{
|
||||
[ContentTypeWriter]
|
||||
public class BitmapFontWriter : ContentTypeWriter<BitmapFont>
|
||||
public class BitmapFontWriter : ContentTypeWriter<BsonData>
|
||||
{
|
||||
protected override void Write(ContentWriter output, BitmapFont value)
|
||||
protected override void Write(ContentWriter output, BsonData value)
|
||||
{
|
||||
output.Write("Hello world");
|
||||
output.Write(value.Data);
|
||||
}
|
||||
|
||||
public override string GetRuntimeType(TargetPlatform targetPlatform)
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace MonoGame.Extended.BitmapFonts
|
||||
{
|
||||
protected override BitmapFont Read(ContentReader input, BitmapFont existingInstance)
|
||||
{
|
||||
// http://james.newtonking.com/archive/2009/12/26/json-net-3-5-release-6-binary-json-bson-support
|
||||
var json = input.ReadString();
|
||||
var bitmapFont = JsonConvert.DeserializeObject<BitmapFont>(json);
|
||||
bitmapFont.Texture = input.ContentManager.Load<Texture2D>(bitmapFont.TextureFilename);
|
||||
|
||||
Reference in New Issue
Block a user