Beispiel #1
0
    public static void CreateLevelFromXML(string path, Vector3 startPos)
    {
        XmlDocument doc = new XmlDocument();

        doc.Load(path);
        XmlNode levelNode = doc.SelectSingleNode(LEVEL_NODE);

        LevelText.Initialize(startPos);

        TextCharDef currentDef = TextCharDef.CreateDefault();

        foreach (XmlNode node in levelNode.ChildNodes)
        {
            if (node.Name == PARAGRAPH_NODE)
            {
                Paragraph currentParagraph = LevelText.AttachNewParagraph();
                currentDef = ChangeDefOnDemand(currentDef, node.Attributes);

                foreach (XmlNode textNode in node.ChildNodes)
                {
                    if (textNode.Name == TEXT_NODE)
                    {
                        string text = node.InnerText;
                        foreach (char c in text)
                        {
                            char convertedC = c.ToString().ToLower().ToCharArray()[0];
                            if (ValidateChar(convertedC))
                            {
                                currentDef.theChar = convertedC;
                                currentParagraph.AddChar(currentDef);
                            }
                        }
                    }

                    if (textNode.Name == LETTER_NODE)
                    {
                        TextCharDef backup = currentDef;
                        currentDef = ChangeDefOnDemand(currentDef, node.Attributes);
                        char convertedC = node.InnerText.ToLower().ToCharArray()[0];
                        if (ValidateChar(convertedC))
                        {
                            currentDef.theChar = convertedC;
                            currentParagraph.AddChar(currentDef);
                        }
                        currentDef = backup;
                    }
                }
            }
        }
        LevelText.RecalculateLength();
    }