Ejemplo n.º 1
0
 protected override bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode)
 {
     switch (childNode.Key)
     {
         case "Path":
     #if DEBUG
             if (Convert.ToInt32(childNode.KeyExtension) != Path.Count)
                 Console.WriteLine("LevelBuilder WARNING: Ribbon path points are not in order.");
     #endif
             Path.Add(ExtendedConvert.ToVector2(childNode.Value));
             return true;
         case "Start":
             Start = Convert.ToSingle(childNode.Value);
             return true;
         case "End":
             End = Convert.ToSingle(childNode.Value);
             return true;
         case "Loop":
             Loop = Convert.ToBoolean(childNode.Value);
             return true;
         case "Complete":
             Complete = Convert.ToBoolean(childNode.Value);
             return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 protected override void IntegrationPostprocess(LayoutTreeNode node)
 {
     if (worldNumber == 0)
         Console.WriteLine("LevelBuilder WARNING: A level was built in World 0.");
     if (levelNumber == 0)
         Console.WriteLine("LevelBuilder WARNING: A 0th level was built.");
 }
Ejemplo n.º 3
0
 protected override bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode)
 {
     if (childNode.Key == "Component")
     {
         spriteComponent = ExtendedConvert.ToEnum<SpriteComponents>(childNode.Value);
         spriteComponentSet = true;
         return true;
     }
     return false;
 }
Ejemplo n.º 4
0
 protected override void IntegrationPostprocess(LayoutTreeNode node)
 {
     if (spriteComponentSet && shape != null)
     {
         switch (shape)
         {
             case "Sinusoid":
                 AnimationCurve = new SineAnimationCurve(spriteComponent, new Sinusoid(amplitude, period, phase, dcOffset));
                 return;
         }
     }
 }
Ejemplo n.º 5
0
 protected override bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode)
 {
     switch (childNode.Key)
     {
         case "Ribbons":
             RibbonStorage ribbon = new RibbonStorage();
             ribbon.Integrate(null, childNode);
             ribbons.Add(ribbon);
             return true;
         case "World":
             worldNumber = Convert.ToInt32(childNode.Value);
             return true;
         case "Level":
             levelNumber = Convert.ToInt32(childNode.Value);
             return true;
     }
     return false;
 }
Ejemplo n.º 6
0
 protected override bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode)
 {
     switch (childNode.Key)
     {
         case "Shape":
             shape = childNode.Value;
             return true;
         case "Amplitude":
             amplitude = Convert.ToSingle(childNode.Value);
             return true;
         case "Period":
             period = Convert.ToSingle(childNode.Value);
             return true;
         case "Phase":
             phase = Convert.ToSingle(childNode.Value);
             return true;
         case "DCOffset":
             dcOffset = Convert.ToSingle(childNode.Value);
             return true;
     }
     return base.IntegrateChild(assets, childNode);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Applies a node of a layout tree to this object.
 /// </summary>
 /// <param name="assets">The AssetManager associated with the game; use null if unused by the tree.</param>
 /// <param name="node">The node to apply.</param>
 public void Integrate(AssetManager assets, LayoutTreeNode node)
 {
     IntegrationPreprocess(node);
     if (node.KeyExtension == null)
         LayoutName = node.Key;
     else
         LayoutName = node.KeyExtension;
     #if DEBUG
     //Verify that we're working with the right class
     String typeName = GetType().Name;
     if (typeName != node.Value)
         Console.WriteLine("LayoutEngine WARNING: We were given {0} but expected {1}.", node.Value, typeName);
     #endif
     foreach (LayoutTreeNode childNode in node.Children)
     {
         bool success = IntegrateChild(assets, childNode);
     #if DEBUG
         if (!success)
             Console.WriteLine("LayoutEngine WARNING: {0} hasn't been implemented yet.", childNode.Key);
     #endif
     }
     IntegrationPostprocess(node);
 }
Ejemplo n.º 8
0
 protected override void IntegrationPreprocess(LayoutTreeNode node)
 {
     ribbons = new List<RibbonStorage>();
 }
Ejemplo n.º 9
0
 protected override bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode)
 {
     bool orderError = false;
     switch (childNode.Key)
     {
         case "Texture":
             sprite = new Sprite(assets.GetAnimatedTexture(childNode.Value));
             return true;
         case "Position":
             if (sprite != null)
             {
                 sprite.Position = ExtendedConvert.ToVector2(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Rotation":
             if (sprite != null)
             {
                 sprite.Rotation = Convert.ToSingle(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Scale":
             if (sprite != null)
             {
                 sprite.Scale = ExtendedConvert.ToVector2(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Color":
             if (sprite != null)
             {
                 sprite.Color = ExtendedConvert.ToColor(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Anchor":
             if (sprite != null)
             {
                 sprite.Anchor = ExtendedConvert.ToEnum<Anchor>(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Animation":
             if (sprite != null)
             {
                 AnimationCurveElement animationCurve = null;
                 switch (childNode.Value)
                 {
                     case "PeriodicCurve":
                         animationCurve = new PeriodicAnimationCurveElement();
                         break;
                 }
                 if (animationCurve != null)
                 {
                     animationCurve.Integrate(assets, childNode);
                     if (animationCurve.AnimationCurve != null)
                     {
                         sprite.PushAnimationCurve(animationCurve.AnimationCurve);
                         return true;
                     }
     #if DEBUG
                     Console.WriteLine("LayoutEngine WARNING: An animation is missing an element.");
                     return true;
     #endif
                 }
             }
             else
                 orderError = true;
             break;
     }
     if (orderError)
     {
     #if DEBUG
         Console.WriteLine("ContextElement WARNING: Tried to set {0}'s {1} field before the Texture was specified.", LayoutName, childNode.Key);
     #endif
         return true;
     }
     return false;
 }
Ejemplo n.º 10
0
 protected override bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode)
 {
     bool orderError = false;
     switch (childNode.Key)
     {
         case "Font":
             font = assets.GetFont(childNode.Value);
             if (text != null)
                 sprite = new TextSprite(font, text);
             return true;
         case "Text":
             text = childNode.Value;
             if (font != null)
                 sprite = new TextSprite(font, text);
             return true;
         case "Position":
             if (sprite != null)
             {
                 sprite.Position = ExtendedConvert.ToVector2(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Rotation":
             if (sprite != null)
             {
                 sprite.Rotation = Convert.ToSingle(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Scale":
             if (sprite != null)
             {
                 sprite.Scale = ExtendedConvert.ToVector2(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Color":
             if (sprite != null)
             {
                 sprite.Color = ExtendedConvert.ToColor(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Anchor":
             if (sprite != null)
             {
                 sprite.Anchor = ExtendedConvert.ToEnum<Anchor>(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
     }
     if (orderError)
     {
     #if DEBUG
         Console.WriteLine("ContextElement WARNING: Tried to set {0}'s {1} field before the Text and Font were specified.", LayoutName, childNode.Key);
     #endif
         return true;
     }
     return false;
 }
Ejemplo n.º 11
0
 protected override bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode)
 {
     switch (childNode.Key)
     {
         case "BGColor":
             BackgroundColor = ExtendedConvert.ToColor(childNode.Value);
             return true;
         case "Elements":
             ContextElement contextElement = ContextHelper.ContextFromName(childNode.Value);
             if (contextElement != null)
             {
                 contextElement.SetComponents(this);
                 contextElement.Integrate(assets, childNode);
                 elements.Add(contextElement);
                 return true;
             }
             break;
     }
     return false;
 }
Ejemplo n.º 12
0
 protected override bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode)
 {
     switch (childNode.Key)
     {
         case "Transform":
             switch (childNode.Value)
             {
                 case "UITransform":
                     transform = new UITransform();
                     return true;
             }
             break;
         case "Elements":
             ContextElement contextElement = ContextHelper.ContextFromName(childNode.Value);
             if (contextElement != null)
             {
                 contextElement.SetComponents(UnderlyingContext);
                 contextElement.Integrate(assets, childNode);
                 elements.Add(contextElement);
                 return true;
             }
             break;
     }
     return false;
 }
Ejemplo n.º 13
0
 static void Parse(String sourceString, LayoutTreeNode node)
 {
     List<String> cSourceStrings = new List<string>();
     // Make the child source strings
     int bracketLevel = 0;
     int startIndex = 0;
     int length = 0;
     for (int i = 0; i < sourceString.Length; i++)
     {
         length++;
         if (sourceString[i] == '(')
             bracketLevel++;
         else if (sourceString[i] == ')')
         {
             // We're about to close the first bracket, so do stuff
             if (bracketLevel == 1)
             {
                 cSourceStrings.Add(sourceString.Substring(startIndex, length));
                 startIndex += length;
                 length = 0;
             }
             bracketLevel--;
         }
     }
     if (bracketLevel != 0)
     {
     #if DEBUG
         Console.WriteLine("LayoutEngine WARNING: At least one mismatched bracket found in parent key {0}.", node.Key);
     #endif
         return;
     }
     // Parse each child source string
     for (int i = 0; i < cSourceStrings.Count; i++)
     {
         string cSourceString = cSourceStrings[i];
         int equals = cSourceString.IndexOf('=');
         // Base case: No equals - no key/value
         if (equals == -1)
             return;
         string key = cSourceString.Substring(0, equals);
         int leftBracket = cSourceString.IndexOf('(');
         int rightBracket = cSourceString.LastIndexOf(')');
         if (leftBracket == -1 || rightBracket == -1)
         {
     #if DEBUG
             Console.WriteLine("LayoutEngine WARNING: Key {0} is missing a bracket.", key);
     #endif
             return;
         }
         string value = cSourceString.Substring(equals + 1, leftBracket - equals - 1);
         LayoutTreeNode currentNode = new LayoutTreeNode(key, value);
         node.Children.AddLast(currentNode);
         Parse(cSourceString.Substring(leftBracket + 1, rightBracket - leftBracket - 1), currentNode);
     }
 }
Ejemplo n.º 14
0
 protected override void IntegrationPreprocess(LayoutTreeNode node)
 {
     elements = new List<ContextElement>();
 }
Ejemplo n.º 15
0
 protected override bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode)
 {
     return false;
 }
Ejemplo n.º 16
0
 protected override void IntegrationPreprocess(LayoutTreeNode node)
 {
     Path = new List<Vector2>();
 }
Ejemplo n.º 17
0
 static void SaveNode(LayoutTreeNode node, List<string> strings, string indent)
 {
     strings.Add(String.Format("{0}{1}{2} = {3}{4}",
                         indent,
                         node.Key,
                         node.KeyExtension != null ? String.Format("[{0}]", node.KeyExtension) : "",
                         node.Value,
                         node.Children.Count == 0 ? ";" : ""));
     if (node.Children.Count > 0)
     {
         strings.Add(String.Format("{0}(", indent));
         string newIndent = indent + "    ";
         foreach (LayoutTreeNode n in node.Children)
             SaveNode(n, strings, newIndent);
         strings.Add(String.Format("{0})", indent));
     }
 }
Ejemplo n.º 18
0
 /// <summary>
 /// A method that is called once for every child of the node applied to this object.
 /// </summary>
 /// <param name="node">A single child of the node applied to this object.</param>
 protected abstract bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode);
Ejemplo n.º 19
0
 protected override void IntegrationPostprocess(LayoutTreeNode node)
 {
     contexts[currentContext].Initialize();
 }
Ejemplo n.º 20
0
 protected override bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode)
 {
     switch (childNode.Key)
     {
         case "InitialContext":
             for (int i = 0; i < contexts.Count; i++)
             {
                 if (contexts[i].LayoutName == childNode.Value)
                 {
                     currentContext = i;
                     return true;
                 }
             }
             Console.WriteLine("LayoutEngine WARNING: Couldn't find a context named {0}. Make sure the context has been created first.", childNode.Value);
             return true;
         case "Contexts":
             Context gameContext = new Context();
             gameContext.AssetManager = assets;
             gameContext.Canvas = canvas;
             gameContext.InputController = input;
             gameContext.StorageManager = storage;
             gameContext.Integrate(assets, childNode);
             contexts.Add(gameContext);
             return true;
     }
     return false;
 }
Ejemplo n.º 21
0
 protected override void IntegrationPreprocess(LayoutTreeNode node)
 {
     contexts = new List<Context>(node.Children.Count);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// An overridable method that is run immediately before a node's children are applied.
 /// </summary>
 /// <param name="node">The node to be applied to this object.</param>
 protected virtual void IntegrationPreprocess(LayoutTreeNode node)
 {
 }
Ejemplo n.º 23
0
 public static LayoutTree BuildLayout(Text source)
 {
     int length = source.Length;
     StringBuilder processed = new StringBuilder();
     for (int i = 0; i < length; i++)
     {
         String preprocessed = source[i];
         // State flags
         bool quote = false;
         bool array = false;
         bool script = false;
         bool comment = false;
         bool followsRightBracket = false;
         // Filter out all non-quote whitespace, turn
         // semicolons into empty brackets, and clear comments.
         for (int j = 0; j < preprocessed.Length; j++)
         {
             if (quote && preprocessed[j] != '\"')
             {
                 processed.Append(preprocessed[j]);
                 continue;
             }
             switch (preprocessed[j])
             {
                 case '\"':
                     quote = !quote;
                     break;
                 case '[':
                     array = true;
                     processed.Append('[');
                     break;
                 case ']':
                     array = false;
                     processed.Append(']');
                     break;
                 case ' ':
                     break;
                 case ',':
                     if (array)
                         processed.Append(',');
                     else if (!followsRightBracket)
                         processed.Append("()");
                     break;
                 case ')':
                     processed.Append("())");
                     followsRightBracket = true;
                     break;
                 case '#':
                     comment = true;
                     break;
                 default:
                     processed.Append(preprocessed[j]);
                     followsRightBracket = false;
                     break;
             }
             if (comment)
                 break;
         }
     #if DEBUG
         if (quote)
             Console.WriteLine("LayoutEngine WARNING: No matching endquote on line {0}.", i);
     #endif
     }
     // Dummy node because the root has not yet been born
     LayoutTreeNode dummy = new LayoutTreeNode("dummy", "dummy");
     Parse(processed.ToString(), dummy);
     LayoutTree layoutTree = new LayoutTree();
     layoutTree.Root = dummy.Children.First.Value;
     #if DEBUG
     Console.WriteLine("------------\r\n" + layoutTree.RepresentativeString + "------------");
     if (dummy.Children.Count > 1)
         Console.WriteLine("LayoutEngine WARNING: {0} top-level nodes found... the last {1} will be ignored.", dummy.Children.Count, dummy.Children.Count - 1);
     #endif
     return layoutTree;
 }