Edit The JsonContentTypeWriter
On the previous page we discussed the anatomy of a ContentTypeWriter
. Now that we have an understanding of this, let's make the changes necessary to our JsonContentTypeWriter
class so that it writes the results to an .xnb
file.
Open the JsonContentTypeWriter.cs
file and make the following adjustments:
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using TInput = JsonContentPipelineExtension.JsonContentResult;
namespace JsonContentPipelineExtension
{
[ContentTypeWriter]
internal class JsonContentTypeWriter : ContentTypeWriter<TInput>
{
protected override void Write(ContentWriter output, TInput value)
{
output.Write(value.Json);
}
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return "JsonContentPipeline.JsonContentReader, JsonContentPipeline";
}
}
}
For the purposes of the example being used in this tutorial, there was not much we needed to adjust here.
- The
TInput
using alias was changed to ourJsonContentResult
type. - We updated the logic of the
Write(ContentWriter, TInput)
method to write out JSON string to the.xnb
file.
Note, however, the value that we are returning for the GetRuntimeReader(TargetPlatform)
method. The fully-qualified type path uses an assembly name that is different than our JsonContentPipelineExtension
assembly. This is because we're going to place the reader in a separate project, which will be explained in the upcoming sections.
Next Steps
That is it for our JSON writer. It simply just takes in the data given from the JsonContentProcessor
and writes the single JSON string to the .xnb
file.
On the next page, we'll go over creating a new MonoGame Game Library project that we'll put our JsonContentTypeReader
into and go over the reasons why we do this.