Changed BinaryReaderExtention files to be more split up.

Also added in function that simply logs which supported types are added for reading/saving.
This commit is contained in:
2018-05-06 19:31:10 -07:00
parent 42b039cf89
commit 62f07d731c
4 changed files with 47 additions and 12 deletions

View File

@ -46,6 +46,7 @@ namespace ModdedUtilitiesNetworking
possibleVoidFunctions.Add(displayMessageString, new voidFunc(displayMessage));
initializeBasicTypes();
}
@ -150,10 +151,29 @@ namespace ModdedUtilitiesNetworking
/// Initialize basic supported types.
/// </summary>
public static void initializeBasicTypes()
{
addObjectType(monitor,typeof(String), new ReadWriter(new reader(GenericExtentions.ReadString), new writer(GenericExtentions.WriteString)));
addObjectType(monitor,typeof(List<String>), new ReadWriter(new reader(GenericExtentions.ReadStringList), new writer(GenericExtentions.WriteStringList)));
}
/// <summary>
/// Safely adds types
/// </summary>
/// <param name="monitor"></param>
/// <param name="t"></param>
/// <param name="readWriter"></param>
public static void addObjectType(IMonitor monitor,Type t, ReadWriter readWriter)
{
objectTypes.Add(typeof(String).ToString(), new ReadWriter(new reader(BinaryReadWriteExtentions.ReadString), new writer(BinaryReadWriteExtentions.WriteString)));
if (objectTypes.ContainsKey(t.ToString()) == false)
{
objectTypes.Add(t.ToString(), readWriter);
monitor.Log("Added supported type: " + t.ToString() + " to ModdedUtilitiesNetworking.",LogLevel.Info);
}
else
{
monitor.Log("Error adding supported type: " + t.ToString() + " to ModdedUtilitiesNetworking. Type already supported!", LogLevel.Alert);
}
}
/// <summary>

View File

@ -10,15 +10,8 @@ using Netcode;
namespace ModdedUtilitiesNetworking.Framework.Extentions
{
public static class BinaryReadWriteExtentions
public static class GenericExtentions
{
public static Vector3 ReadVector3(this BinaryReader reader)
{
float x=reader.ReadSingle();
float y=reader.ReadSingle();
float z=reader.ReadSingle();
return new Vector3(x, y, z);
}
public static string ReadString(this BinaryReader reader)
{

View File

@ -0,0 +1,21 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModdedUtilitiesNetworking.Framework.Extentions
{
public static class XNAExtentions
{
public static Vector3 ReadVector3(this BinaryReader reader)
{
float x = reader.ReadSingle();
float y = reader.ReadSingle();
float z = reader.ReadSingle();
return new Vector3(x, y, z);
}
}
}

View File

@ -53,7 +53,8 @@
<Compile Include="Framework\Clients\CustomGalaxyClient.cs" />
<Compile Include="Framework\Clients\CustomLidgrenClient.cs" />
<Compile Include="Framework\Delegates\DelegateInfo.cs" />
<Compile Include="Framework\Extentions\BinaryReadWriteExtentions.cs" />
<Compile Include="Framework\Extentions\GenericExtentions.cs" />
<Compile Include="Framework\Extentions\XNAExtentions.cs" />
<Compile Include="Framework\Messages\OutgoingMessageBase.cs" />
<Compile Include="Framework\CustomMultiplayer.cs" />
<Compile Include="Framework\Network\NetBufferReadStream.cs" />