From 62f07d731ccd316674ab51169b8906cdbcd02781 Mon Sep 17 00:00:00 2001 From: Date: Sun, 6 May 2018 19:31:10 -0700 Subject: [PATCH] Changed BinaryReaderExtention files to be more split up. Also added in function that simply logs which supported types are added for reading/saving. --- .../ModdedUtilitiesNetworking/Class1.cs | 26 ++++++++++++++++--- ...riteExtentions.cs => GenericExtentions.cs} | 9 +------ .../Framework/Extentions/XNAExtentions.cs | 21 +++++++++++++++ .../ModdedUtilitiesNetworking.csproj | 3 ++- 4 files changed, 47 insertions(+), 12 deletions(-) rename GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/{BinaryReadWriteExtentions.cs => GenericExtentions.cs} (90%) create mode 100644 GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/XNAExtentions.cs diff --git a/GeneralMods/ModdedUtilitiesNetworking/Class1.cs b/GeneralMods/ModdedUtilitiesNetworking/Class1.cs index 15a2edf9..a400fa0b 100644 --- a/GeneralMods/ModdedUtilitiesNetworking/Class1.cs +++ b/GeneralMods/ModdedUtilitiesNetworking/Class1.cs @@ -46,6 +46,7 @@ namespace ModdedUtilitiesNetworking possibleVoidFunctions.Add(displayMessageString, new voidFunc(displayMessage)); initializeBasicTypes(); + } @@ -150,10 +151,29 @@ namespace ModdedUtilitiesNetworking /// Initialize basic supported types. /// public static void initializeBasicTypes() + { + addObjectType(monitor,typeof(String), new ReadWriter(new reader(GenericExtentions.ReadString), new writer(GenericExtentions.WriteString))); + addObjectType(monitor,typeof(List), new ReadWriter(new reader(GenericExtentions.ReadStringList), new writer(GenericExtentions.WriteStringList))); + + } + + /// + /// Safely adds types + /// + /// + /// + /// + 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); + } } /// diff --git a/GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/BinaryReadWriteExtentions.cs b/GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/GenericExtentions.cs similarity index 90% rename from GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/BinaryReadWriteExtentions.cs rename to GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/GenericExtentions.cs index 0079116d..7c157829 100644 --- a/GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/BinaryReadWriteExtentions.cs +++ b/GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/GenericExtentions.cs @@ -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) { diff --git a/GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/XNAExtentions.cs b/GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/XNAExtentions.cs new file mode 100644 index 00000000..2e6a2d42 --- /dev/null +++ b/GeneralMods/ModdedUtilitiesNetworking/Framework/Extentions/XNAExtentions.cs @@ -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); + } + } +} diff --git a/GeneralMods/ModdedUtilitiesNetworking/ModdedUtilitiesNetworking.csproj b/GeneralMods/ModdedUtilitiesNetworking/ModdedUtilitiesNetworking.csproj index b0671a4f..3d5d8e60 100644 --- a/GeneralMods/ModdedUtilitiesNetworking/ModdedUtilitiesNetworking.csproj +++ b/GeneralMods/ModdedUtilitiesNetworking/ModdedUtilitiesNetworking.csproj @@ -53,7 +53,8 @@ - + +