preferences now use object as type for serialization and no longer uses marker interface.

This commit is contained in:
2018-12-05 00:03:00 -06:00
parent 151480eaee
commit 87823b26d6
9 changed files with 28 additions and 35 deletions

View File

@@ -35,13 +35,20 @@ namespace RecrownedAthenaeum.DataTypes
return dictionaryOfRegions[name].AsTexture2D(graphicsDevice, texture);
}
public struct TextureAtlasRegion : IComparable<TextureAtlasRegion>, IDisposable
public class TextureAtlasRegion : IComparable<TextureAtlasRegion>, IDisposable
{
public string name;
Rectangle sourceRectangle;
NinePatch ninepatch;
public readonly string name;
readonly Rectangle sourceRectangle;
readonly NinePatch ninepatch;
Texture2D regionTexture;
public TextureAtlasRegion(string name, Rectangle source, NinePatch ninePatch)
{
this.name = name;
this.sourceRectangle = source;
this.ninepatch = ninePatch;
}
public void Draw(SpriteBatch batch, Rectangle destination, Texture2D fromTexture, Color color, float rotation, Vector2 origin)
{
batch.Draw(fromTexture, destination, sourceRectangle, color, rotation, origin, SpriteEffects.None, 0f);

View File

@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace RecrownedAthenaeum.Persistence
{
public interface Preferences
{
}
}

View File

@@ -8,15 +8,15 @@ namespace RecrownedAthenaeum.Persistence
{
public class PreferencesManager
{
private readonly Dictionary<Type, Preferences> preferenceList;
private readonly Dictionary<Type, object> preferenceList;
string savePath;
XmlSerializer xmlSerializer;
public PreferencesManager(string savePath, params Preferences[] preferences)
public PreferencesManager(string savePath, params object[] preferences)
{
this.savePath = savePath;
Directory.CreateDirectory(savePath);
preferenceList = new Dictionary<Type, Preferences>();
preferenceList = new Dictionary<Type, object>();
Debug.WriteLine("Preference manager setting up...");
Type[] preferenceTypes = new Type[preferences.Length];
for (int prefID = 0; prefID < preferences.Length; prefID++)
@@ -26,10 +26,10 @@ namespace RecrownedAthenaeum.Persistence
Debug.WriteLine(preferences[prefID] + " added to list of preferences");
}
xmlSerializer = new XmlSerializer(typeof(Preferences), preferenceTypes);
xmlSerializer = new XmlSerializer(typeof(object), preferenceTypes);
}
public T GetPreferences<T>() where T : Preferences
public T GetPreferences<T>()
{
return (T)preferenceList[typeof(T)];
}
@@ -49,7 +49,7 @@ namespace RecrownedAthenaeum.Persistence
public void Save()
{
foreach (KeyValuePair<Type, Preferences> prefs in preferenceList)
foreach (KeyValuePair<Type, object> prefs in preferenceList)
{
SaveSpecific(prefs.Key);
}
@@ -61,7 +61,7 @@ namespace RecrownedAthenaeum.Persistence
if (File.Exists(path))
{
Stream stream = new FileStream(path, FileMode.Open);
preferenceList[preference] = (Preferences)xmlSerializer.Deserialize(stream);
preferenceList[preference] = xmlSerializer.Deserialize(stream);
stream.Close();
return true;
}

View File

@@ -64,7 +64,6 @@
<Compile Include="obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs" />
<Compile Include="obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs" />
<Compile Include="ParticleSystem\Particle.cs" />
<Compile Include="Persistence\Preferences.cs" />
<Compile Include="Persistence\PreferencesManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScreenSystem\ITransition.cs" />