[gbrainy] Fixes exception making sure that objects are used when properly init



commit 582824c5e2c09e220d31d188998d21c49d816904
Author: Jordi Mas <jmas softcatala org>
Date:   Fri Nov 4 20:50:35 2011 +0100

    Fixes exception making sure that objects are used when properly init

 src/Core/Main/Game.cs        |    3 ++-
 src/Core/Main/GameAnswer.cs  |   10 ++++++++--
 src/Core/Main/Xml/GameXml.cs |   12 +++++-------
 3 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/src/Core/Main/Game.cs b/src/Core/Main/Game.cs
index 536a9fe..2b5133a 100644
--- a/src/Core/Main/Game.cs
+++ b/src/Core/Main/Game.cs
@@ -45,6 +45,7 @@ namespace gbrainy.Core.Main
 
 		protected Game ()
 		{
+			answer = new GameAnswer ();
 			containers = new List <Toolkit.Container> ();
 			difficulty = GameDifficulty.Medium;
 		}
@@ -59,7 +60,7 @@ namespace gbrainy.Core.Main
 		public ITranslations translations { 
 			set {  
 				_translations = value;
-				answer = new GameAnswer (translations);
+				answer.Translations = value;
 			}
 			get { return _translations; }
 		}
diff --git a/src/Core/Main/GameAnswer.cs b/src/Core/Main/GameAnswer.cs
index 681f6c5..abb0621 100644
--- a/src/Core/Main/GameAnswer.cs
+++ b/src/Core/Main/GameAnswer.cs
@@ -32,13 +32,19 @@ namespace gbrainy.Core.Main
 		string correct;
 		ITranslations translations;
 
-		public GameAnswer (ITranslations translations)
+		public GameAnswer ()
 		{
-			this.translations = translations;
 			CheckAttributes = GameAnswerCheckAttributes.Trim | GameAnswerCheckAttributes.IgnoreCase;
 			CheckExpression = ".+";
 		}
 
+		// This is a property because the object can be constructed and use it
+		// Only text related functions needed. Perhaps, a possible to do extract class pattern
+		public ITranslations Translations { 
+			set { translations = value; }
+			get { return translations; }
+		}
+
 		public char Separator {
 			get { return separator; }
 		}
diff --git a/src/Core/Main/Xml/GameXml.cs b/src/Core/Main/Xml/GameXml.cs
index a623c0a..785c23c 100644
--- a/src/Core/Main/Xml/GameXml.cs
+++ b/src/Core/Main/Xml/GameXml.cs
@@ -119,7 +119,6 @@ namespace gbrainy.Core.Main.Xml
 		void SetCheckAttributes ()
 		{
 			GameAnswerCheckAttributes attrib;
-
 			if (game.Variants.Count > 0 && game.Variants[current.Variant].CheckAttributes != GameAnswerCheckAttributes.None)
 				attrib = game.Variants[current.Variant].CheckAttributes;
 			else
@@ -137,6 +136,11 @@ namespace gbrainy.Core.Main.Xml
 			bool variants;
 			LocalizableString localizable_question, localizable_rationale;
 
+			xml_drawing.CreateDrawingObjects (game.DrawingObjects); // Draw objects shared by all variants
+
+			if (game.Variants.Count > 0)
+				xml_drawing.CreateDrawingObjects (game.Variants[current.Variant].DrawingObjects); // Draw variant specific objects
+
 			compiler = ServiceLocator.Instance.GetService <ICSharpCompiler> ();
 
 			variants = game.Variants.Count > 0;
@@ -242,12 +246,6 @@ namespace gbrainy.Core.Main.Xml
 				current.Variant = locator.Variant;
 				game = games [locator.Game];
 				SetCheckAttributes ();
-
-				xml_drawing.CreateDrawingObjects (game.DrawingObjects); // Draw objects shared by all variants
-
-				if (game.Variants.Count > 0)
-					xml_drawing.CreateDrawingObjects (game.Variants[current.Variant].DrawingObjects); // Draw variant specific objects
-
 				SetCheckExpression ();
 				SetAnswerCorrectShow ();
 			}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]