I created a game in XNA which stored users in a binary file (I know it’s inefficient and that using a database is better, but I’m just beginning so this is the best method for me). In XNA, it stored a list of objects of type
Skin, which had a property of type
Color struct is not serializable in Monogame but it is in XNA. Thus, when I ported my game to Monogame, I had to create a
SerializableColor class that stores R, G, B, and A values and added some extension methods for conversions from
SerializableColor. But now, I can’t load users from the older version into the newer version. How could I do this? I’d be willing to convert these old users with the
Color object to new users with the
SeralizableColor object instead, and serialize these new users or something…
If this isn’t enough for you to help, please tell me and I’ll provide the additional necessary information. Thank you in advance.
EDIT: I created two classes,
OldUser which stored the old data types, and I then added conversion methods for these two. Unfortunately, it still didn’t work. Here is a screenshot of a popup generated by some error-handling code I have in there:
I use serialization myself for save-games and scripting a lot and I use a simple trick (instead of writing a wrapper).
I simply use Vector4() for colors like this:
/// This class holds all the information needed to describe a
/// particle-system in full extent.
public class ParticleSystemDescriptor
/// A Vector4 representing the color of the particles with
public Vector4 Color;
... and so on...
But I have to say I only use it with XML serialization, but that shouldn’t really matter.
So IMO the right way to go would be to use that and convert the colors before writing and after reading (Color = Color.Black.ToVector4();).
In XML that would give you the following:
<X>0</X> <!-- R -->
<Y>0</Y> <!-- G -->
<Z>0</Z> <!-- B -->
<W>0</W> <!-- Alpha channel -->
As for your ‘old’ save game. That’s a problem.
Since C# is a strongly typed language you cannot have an object that’s both, the old XNA Color and the new MG Color. But you would need to deserialize the file to an XNA Color and write it again as an MG Color.
I’ve ran into it as well and the thing I ended up doing is to not use the serializer when patching the file at all.
In my case that’s easy, since I use XML serialization and for the patch I simply replaced strings in the text-file without really parsing it from or to XML. When it’s patched I’d use the ‘new’ deserializer again…
Maybe you can do the same if you search for the right patterns in the binary file.
Maybe you can write a deserializer for the ‘old’ XNA color format and use that one to patch the files…