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

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

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace RecrownedAthenaeum.Pipeline.NinePatch namespace RecrownedAthenaeum.Pipeline.NinePatch
{ {
class NinePatchTemplate class NinePatchFile
{ {
public string name; public string name;
public string bounds; public string bounds;

View File

@ -11,13 +11,13 @@ using System.Xml.Serialization;
namespace RecrownedAthenaeum.Pipeline.TextureAtlas namespace RecrownedAthenaeum.Pipeline.TextureAtlas
{ {
internal class TextureAtlasImporter : ContentImporter<TextureAtlasTemplate> internal class TextureAtlasImporter : ContentImporter<TextureAtlasFile>
{ {
public override TextureAtlasTemplate Import(string filename, ContentImporterContext context) public override TextureAtlasFile Import(string filename, ContentImporterContext context)
{ {
StreamReader stream = new StreamReader(filename); StreamReader stream = new StreamReader(filename);
XmlSerializer serializer = new XmlSerializer(typeof(TextureAtlasTemplate)); XmlSerializer serializer = new XmlSerializer(typeof(TextureAtlasFile));
TextureAtlasTemplate atlas = (TextureAtlasTemplate)serializer.Deserialize(stream); TextureAtlasFile atlas = (TextureAtlasFile)serializer.Deserialize(stream);
context.AddDependency(atlas.textureName); context.AddDependency(atlas.textureName);
stream.Dispose(); stream.Dispose();
return atlas; return atlas;

View File

@ -10,10 +10,10 @@ using System.Threading.Tasks;
namespace RecrownedAthenaeum.Pipeline.TextureAtlas namespace RecrownedAthenaeum.Pipeline.TextureAtlas
{ {
class TextureAtlasProcessor : ContentProcessor<TextureAtlasTemplate, TextureAtlasTemplate> class TextureAtlasProcessor : ContentProcessor<TextureAtlasFile, TextureAtlasFile>
{ {
public override TextureAtlasTemplate Process(TextureAtlasTemplate input, ContentProcessorContext context) public override TextureAtlasFile Process(TextureAtlasFile input, ContentProcessorContext context)
{ {
return input; return input;
} }

View File

@ -8,7 +8,7 @@ using System.Xml.Serialization;
namespace RecrownedAthenaeum.Pipeline.TextureAtlas namespace RecrownedAthenaeum.Pipeline.TextureAtlas
{ {
public class TextureAtlasTemplate public class TextureAtlasFile
{ {
public string textureName; public string textureName;
public TextureAtlasRegion[] regions; public TextureAtlasRegion[] regions;

View File

@ -8,14 +8,14 @@ using System.Threading.Tasks;
namespace RecrownedAthenaeum.Pipeline.TextureAtlas namespace RecrownedAthenaeum.Pipeline.TextureAtlas
{ {
class TextureAtlasWriter : ContentTypeWriter<TextureAtlasTemplate> class TextureAtlasWriter : ContentTypeWriter<TextureAtlasFile>
{ {
public override string GetRuntimeReader(TargetPlatform targetPlatform) public override string GetRuntimeReader(TargetPlatform targetPlatform)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
protected override void Write(ContentWriter output, TextureAtlasTemplate value) protected override void Write(ContentWriter output, TextureAtlasFile value)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -35,13 +35,20 @@ namespace RecrownedAthenaeum.DataTypes
return dictionaryOfRegions[name].AsTexture2D(graphicsDevice, texture); return dictionaryOfRegions[name].AsTexture2D(graphicsDevice, texture);
} }
public struct TextureAtlasRegion : IComparable<TextureAtlasRegion>, IDisposable public class TextureAtlasRegion : IComparable<TextureAtlasRegion>, IDisposable
{ {
public string name; public readonly string name;
Rectangle sourceRectangle; readonly Rectangle sourceRectangle;
NinePatch ninepatch; readonly NinePatch ninepatch;
Texture2D regionTexture; 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) 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); 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 public class PreferencesManager
{ {
private readonly Dictionary<Type, Preferences> preferenceList; private readonly Dictionary<Type, object> preferenceList;
string savePath; string savePath;
XmlSerializer xmlSerializer; XmlSerializer xmlSerializer;
public PreferencesManager(string savePath, params Preferences[] preferences) public PreferencesManager(string savePath, params object[] preferences)
{ {
this.savePath = savePath; this.savePath = savePath;
Directory.CreateDirectory(savePath); Directory.CreateDirectory(savePath);
preferenceList = new Dictionary<Type, Preferences>(); preferenceList = new Dictionary<Type, object>();
Debug.WriteLine("Preference manager setting up..."); Debug.WriteLine("Preference manager setting up...");
Type[] preferenceTypes = new Type[preferences.Length]; Type[] preferenceTypes = new Type[preferences.Length];
for (int prefID = 0; prefID < preferences.Length; prefID++) for (int prefID = 0; prefID < preferences.Length; prefID++)
@ -26,10 +26,10 @@ namespace RecrownedAthenaeum.Persistence
Debug.WriteLine(preferences[prefID] + " added to list of preferences"); 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)]; return (T)preferenceList[typeof(T)];
} }
@ -49,7 +49,7 @@ namespace RecrownedAthenaeum.Persistence
public void Save() public void Save()
{ {
foreach (KeyValuePair<Type, Preferences> prefs in preferenceList) foreach (KeyValuePair<Type, object> prefs in preferenceList)
{ {
SaveSpecific(prefs.Key); SaveSpecific(prefs.Key);
} }
@ -61,7 +61,7 @@ namespace RecrownedAthenaeum.Persistence
if (File.Exists(path)) if (File.Exists(path))
{ {
Stream stream = new FileStream(path, FileMode.Open); Stream stream = new FileStream(path, FileMode.Open);
preferenceList[preference] = (Preferences)xmlSerializer.Deserialize(stream); preferenceList[preference] = xmlSerializer.Deserialize(stream);
stream.Close(); stream.Close();
return true; return true;
} }

View File

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