[gbrainy] Close on option properly
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gbrainy] Close on option properly
- Date: Sun, 31 Oct 2010 21:13:53 +0000 (UTC)
commit 76cae6678c80eb8c10c3f6e61fa8aa3d841ca305
Author: Jordi Mas <jmas softcatala org>
Date: Sun Oct 31 22:15:59 2010 +0100
Close on option properly
src/Core/Main/Xml/GameXmlFactory.cs | 49 ++++++++++++++++++++---------------
1 files changed, 28 insertions(+), 21 deletions(-)
---
diff --git a/src/Core/Main/Xml/GameXmlFactory.cs b/src/Core/Main/Xml/GameXmlFactory.cs
index bf3cc46..1fb518a 100644
--- a/src/Core/Main/Xml/GameXmlFactory.cs
+++ b/src/Core/Main/Xml/GameXmlFactory.cs
@@ -329,60 +329,67 @@ namespace gbrainy.Core.Main.Xml
else
game.Variables = reader.ReadElementString ();
break;
+
case "option":
- if (reader.NodeType != XmlNodeType.Element)
- break;
- OptionDrawingObject option_draw = new OptionDrawingObject ();
+ switch (reader.NodeType) {
+ case XmlNodeType.Element:
+ option = new OptionDrawingObject ();
+ break;
+ case XmlNodeType.EndElement:
+ if (String.IsNullOrEmpty (option.Answer) && option.RandomizedOrder == false)
+ throw new InvalidOperationException ("If the option is not randomized, you need to define an answer");
- if (reader.NodeType == XmlNodeType.Element) {
- option = option_draw;
- } else if (reader.NodeType == XmlNodeType.EndElement) {
option = null;
break;
+ default: // Do do any processing
+ break;
}
+ if (option == null)
+ break;
+
if (processing_variant)
- game.Variants[variant].AddDrawingObject (option_draw);
+ game.Variants[variant].AddDrawingObject (option);
else
- game.AddDrawingObject (option_draw);
+ game.AddDrawingObject (option);
- option_draw.Answer = reader.GetAttribute ("answer");
+ option.Answer = reader.GetAttribute ("answer");
- if (String.IsNullOrEmpty (option_draw.Answer))
- option_draw.Answer = reader.GetAttribute ("_answer");
+ if (String.IsNullOrEmpty (option.Answer))
+ option.Answer = reader.GetAttribute ("_answer");
str = reader.GetAttribute ("x");
if (String.IsNullOrEmpty (str) == false)
- option_draw.X = Double.Parse (str, CultureInfo.InvariantCulture);
+ option.X = Double.Parse (str, CultureInfo.InvariantCulture);
else
- option_draw.X = 0.1;
+ option.X = 0.1;
str = reader.GetAttribute ("y");
if (String.IsNullOrEmpty (str) == false)
- option_draw.Y = Double.Parse (str, CultureInfo.InvariantCulture);
+ option.Y = Double.Parse (str, CultureInfo.InvariantCulture);
else
- option_draw.Y = 0.1;
+ option.Y = 0.1;
str = reader.GetAttribute ("width");
if (String.IsNullOrEmpty (str) == false)
- option_draw.Width = Double.Parse (str, CultureInfo.InvariantCulture);
+ option.Width = Double.Parse (str, CultureInfo.InvariantCulture);
else
- option_draw.Width = 0.1;
+ option.Width = 0.1;
str = reader.GetAttribute ("height");
if (String.IsNullOrEmpty (str) == false)
- option_draw.Height = Double.Parse (str, CultureInfo.InvariantCulture);
+ option.Height = Double.Parse (str, CultureInfo.InvariantCulture);
else
- option_draw.Height = 0.1;
+ option.Height = 0.1;
str = reader.GetAttribute ("order");
if (String.IsNullOrEmpty (str) == false)
- option_draw.RandomizedOrder = true;
+ option.RandomizedOrder = true;
str = reader.GetAttribute ("correct");
if (String.Compare (str, "yes", true) == 0)
- option_draw.Correct = true;
+ option.Correct = true;
break;
default:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]