Ejemplo n.º 1
0
    public PT_XMLReader xmlr; // Just like Deck, this has an PT_XMLReader

    #endregion Fields

    #region Methods

    // This function is called to read in the LayoutXML.xml file
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(xmlText); // The XML is parsed
        xml = xmlr.xml["xml"][0]; // And xml is set as a shortcut to the XML
        // Read in the multiplier, which sets card spacing
        multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"));
        // Read in the slots
        SlotDef tSD;
        // slotsX is used as a shortcut to all the <slot>s
        PT_XMLHashList slotsX = xml["slot"];
        for (int i=0; i<slotsX.Count; i++) {
            tSD = new SlotDef(); // Create a new SlotDef instance
            if (slotsX[i].HasAtt("type")) {
                // If this <slot> has a type attribute parse it
                tSD.type = slotsX[i].att("type");
            } else {
                // If not, set its type to "slot"
                tSD.type = "slot";
            }
            // Various attributes are parsed into numerical values
            tSD.x = float.Parse( slotsX[i].att("x") );
            tSD.y = float.Parse( slotsX[i].att("y") );
            tSD.pos = new Vector3( tSD.x*multiplier.x, tSD.y*multiplier.y, 0 );
            // Sorting Layers
            tSD.layerID = int.Parse( slotsX[i].att("layer") );
            // In this game, the Sorting Layers are named 1, 2, 3, ...through 10
            // This converts the number of the layerID into a text layerName
            tSD.layerName = tSD.layerID.ToString();
            // The layers are used to make sure that the correct cards are
            // on top of the others. In Unity 2D, all of our assets are
            // effectively at the same Z depth, so sorting layers are used
            // to differentiate between them.
            // pull additional attributes based on the type of each <slot>
            switch (tSD.type) {
            case "slot":
                // ignore slots that are just of the "slot" type
                break;
            case "drawpile":
                // The drawPile xstagger is read but not actually used in Bartok
                tSD.stagger.x = float.Parse( slotsX[i].att("xstagger") );
                drawPile = tSD;
                break;
            case "discardpile":
                discardPile = tSD;
                break;
            case "target":
                // The target card has a different layer from discardPile
                target = tSD;
                break;
            case "hand":
                // Information for each player's hand
                tSD.player = int.Parse( slotsX[i].att("player") );
                tSD.rot = float.Parse( slotsX[i].att("rot") );
                slotDefs.Add (tSD);
                break;
            }
        }
    }
Ejemplo n.º 2
0
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(xmlText);
        xml = xmlr.xml["xml"][0];

        multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"));

        SlotDef tSD;

        PT_XMLHashList slotsX = xml["slot"];

        for (int i = 0; i < slotsX.Count; i++)
        {
            tSD = new SlotDef();

            if (slotsX[i].HasAtt("type"))
            {
                tSD.type = slotsX[i].att("type");
            }
            else
            {
                tSD.type = "slot";
            }

            tSD.x       = float.Parse(slotsX[i].att("x"));
            tSD.y       = float.Parse(slotsX[i].att("y"));
            tSD.layerID = int.Parse(slotsX[i].att("layer"));

            tSD.layerName = sortingLayerNames[tSD.layerID];

            switch (tSD.type)
            {
            case "slot":
                tSD.faceUp = (slotsX[i].att("faceup") == "1");
                tSD.id     = int.Parse(slotsX[i].att("id"));
                if (slotsX[i].HasAtt("hiddenby"))
                {
                    string[] hiding = slotsX[i].att("hiddenby").Split(',');
                    foreach (string s in hiding)
                    {
                        tSD.hiddenBy.Add(int.Parse(s));
                    } //foreach
                }     //if

                slotDefs.Add(tSD);
                break;

            case "drawpile":
                tSD.stagger.x = float.Parse(slotsX[i].att("xstagger"));
                drawPile      = tSD;
                break;

            case "discardpile":
                discardPile = tSD;
                break;
            } //switch
        }     //for
    }
Ejemplo n.º 3
0
    // Loads all of the Shots from PlayerPrefs
    static public void LoadShots()
    {
        shots = new List <Shot>();
        if (!PlayerPrefs.HasKey(prefsName))
        {
            return;
        }

        // Get the full XML and parse it
        string       shotsXML = PlayerPrefs.GetString(prefsName);
        PT_XMLReader xmlr     = new PT_XMLReader();

        xmlr.Parse(shotsXML);

        // Pull the PT_XMLHashList of all <shot>s
        PT_XMLHashList hl = xmlr.xml["xml"][0]["shot"];

        for (int i = 0; i < hl.Count; i++)
        {
            // Parse each <shot> in the PT_XMLHashlist
            PT_XMLHashtable ht = hl[i];
            Shot            sh = ParseShotXML(ht);
            shots.Add(sh);
        }
    }
Ejemplo n.º 4
0
    // Загружает все выстрелы из PlayerPrefs
    static public void LoadShots()
    {
        // Пустой список снимков
        shots = new List <Shot>();
        if (!PlayerPrefs.HasKey(prefsName))
        {
            // Пока ещё нет снимков
            return;
        }

        // Полностью достаём XML и переводим его
        string       shotsXML = PlayerPrefs.GetString(prefsName);
        PT_XMLReader xmlr     = new PT_XMLReader();

        xmlr.Parse(shotsXML);

        // Достаём список всех <shot>s
        PT_XMLHashList hl = xmlr.xml["xml"][0]["shot"];

        for (int i = 0; i < hl.Count; i++)
        {
            // Делаем сокращение
            PT_XMLHashtable ht = hl[i];
            Shot            sh = ParseShotXML(ht);
            // Добавляем в список
            shots.Add(sh);
        }
    }
Ejemplo n.º 5
0
    public void readDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(deckXMLText);

        string s = "xml[0] decorator[0] ";

        s += "type=" + xmlr.xml["xml"][0]["decorator"][0].att("type");
        s += " x=" + xmlr.xml["xml"][0]["decorator"][0].att("x");
        s += " y=" + xmlr.xml["xml"][0]["decorator"][0].att("y");
        s += " scale=" + xmlr.xml["xml"][0]["decorator"][0].att("scale");
        //print(s); commented out to remove debug line.

        decorators = new List <Decorator>();
        PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"];
        Decorator      deco;

        for (int i = 0; i < xDecos.Count; i++)
        {
            deco       = new Decorator();
            deco.type  = xDecos[i].att("type");
            deco.flip  = (xDecos[i].att("flip") == "1");
            deco.scale = float.Parse(xDecos[i].att("scale"));
            deco.loc.x = float.Parse(xDecos[i].att("x"));
            deco.loc.y = float.Parse(xDecos[i].att("y"));
            deco.loc.z = float.Parse(xDecos[i].att("z"));
            decorators.Add(deco);
        }
        cardDefs = new List <CardDefinition>();
        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];

        for (int i = 0; i < xCardDefs.Count; i++)
        {
            CardDefinition cDef = new CardDefinition();
            cDef.rank = int.Parse(xCardDefs[i].att("rank"));
            PT_XMLHashList xPips = xCardDefs[i]["pip"];
            if (xPips != null)
            {
                for (int j = 0; j < xPips.Count; j++)
                {
                    deco       = new Decorator();
                    deco.type  = "pip";
                    deco.flip  = (xPips[j].att("fip") == "1");
                    deco.loc.x = float.Parse(xPips[j].att("x"));
                    deco.loc.y = float.Parse(xPips[j].att("y"));
                    deco.loc.z = float.Parse(xPips[j].att("z"));
                    if (xPips[j].HasAtt("scale"))
                    {
                        deco.scale = float.Parse(xPips[j].att("scale"));
                    }
                    cDef.pips.Add(deco);
                }
            }
            if (xCardDefs[i].HasAtt("face"))
            {
                cDef.face = xCardDefs[i].att("face");
            }
            cardDefs.Add(cDef);
        }
    }
    // This function is called to read in the LayoutXML.xml file
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(xmlText);      // The XML is parsed
        xml = xmlr.xml["xml"][0]; // And xml is set as a shortcut to the XML
                                  // Read in the multiplier, which sets card spacing
        multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"));
        // Read in the slots
        SlotDef tSD;
        // slotsX is used as a shortcut to all the <slot>s
        PT_XMLHashList slotsX = xml["slot"];

        for (int i = 0; i < slotsX.Count; i++)
        {
            tSD = new SlotDef(); // Create a new SlotDef instance
            if (slotsX[i].HasAtt("type"))
            {
                // If this <slot> has a type attribute parse it
                tSD.type = slotsX[i].att("type");
            }
            else
            {
                // If not, set its type to "slot"; it's a card in the rows
                tSD.type = "slot";
            }
            // Various attributes are parsed into numerical values
            tSD.x       = float.Parse(slotsX[i].att("x"));
            tSD.y       = float.Parse(slotsX[i].att("y"));
            tSD.layerID = int.Parse(slotsX[i].att("layer"));
            // This converts the number of the layerID into a text layerName
            tSD.layerName = sortingLayerNames[tSD.layerID]; // a
            switch (tSD.type)
            {
            // pull additional attributes based on the type of this <slot>
            case "slot":
                tSD.faceUp = (slotsX[i].att("faceup") == "1");
                tSD.id     = int.Parse(slotsX[i].att("id"));
                if (slotsX[i].HasAtt("hiddenby"))
                {
                    string[] hiding = slotsX[i].att("hiddenby").Split(',');
                    foreach (string s in hiding)
                    {
                        tSD.hiddenBy.Add(int.Parse(s));
                    }
                }
                slotDefs.Add(tSD);
                break;

            case "drawpile":
                tSD.stagger.x = float.Parse(slotsX[i].att("xstagger"));
                drawPile      = tSD;
                break;

            case "discardpile":
                discardPile = tSD;
                break;
            }
        }
    }
Ejemplo n.º 7
0
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(xmlText);
        xml = xmlr.xml["xml"][0];

        multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"));

        SlotDef        tSD;
        PT_XMLHashList slotsX = xml["slot"];

        for (int i = 0; i < slotsX.Count; i++)
        {
            tSD = new SlotDef();

            if (slotsX[i].HasAtt("type"))
            {
                tSD.type = slotsX[i].att("type");
            }
            else
            {
                tSD.type = "slot";
            }

            tSD.x = float.Parse(slotsX[i].att("x"));
            tSD.y = float.Parse(slotsX[i].att("y"));

            tSD.pos = new Vector3(tSD.x * multiplier.x, tSD.y * multiplier.y, 0);

            tSD.layerID   = int.Parse(slotsX[i].att("layer"));
            tSD.layerName = tSD.layerID.ToString();

            switch (tSD.type)
            {
            case "slot":
                break;

            case "drawpile":
                tSD.stagger.x = float.Parse(slotsX[i].att("xstagger"));
                drawPile      = tSD;
                break;

            case "discardpile":
                discardPile = tSD;
                break;

            case "target":
                target = tSD;
                break;

            case "hand":
                tSD.player = int.Parse(slotsX[i].att("player"));
                tSD.rot    = float.Parse(slotsX[i].att("rot"));
                slotDefs.Add(tSD);
                break;
            }
        }
    }
Ejemplo n.º 8
0
    public PT_XMLReader xmlr; // Just like Deck, this has a PT_XMLReader

    #endregion Fields

    #region Methods

    // This function is called to read in the LayoutXML.xml file
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(xmlText);      // The XML is parsed
        xml = xmlr.xml["xml"][0]; // And xml is set as a shortcut to the XML

        // Read in the multiplier, which sets card spacing
        multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"));

        // Read in the slots
        SlotDef tSD;
        // slotsX is used as a shortcut to all the <slot>s
        PT_XMLHashList slotsX = xml["slot"];

        for (int i=0; i<slotsX.Count; i++) {
            tSD = new SlotDef();  // Create a new SlotDef instance
            if (slotsX[i].HasAtt("type")) {
                // If this <slot> has a type attribute parse it
                tSD.type = slotsX[i].att("type");
            } else {
                // If not, set its type to "slot"; it's a tableau card
                tSD.type = "slot";
            }
            // Various attributes are parsed into numerical values
            tSD.x = float.Parse( slotsX[i].att("x") );
            tSD.y = float.Parse( slotsX[i].att("y") );
            tSD.layerID = int.Parse( slotsX[i].att("layer") );
            // This converts the number of the layerID into a text layerName
            tSD.layerName = sortingLayerNames[ tSD.layerID ];
            // The layers are used to make sure that the correct cards are
            //   on top of the others. In Unity 2D, all of our assets are
            //   effectively at the same Z depth, so the layer is used
            //   to differentiate between them.

            switch (tSD.type) {
                // pull additional attributes based on the type of this <slot>
            case "slot":
                tSD.faceUp = (slotsX[i].att("faceup") == "1");
                tSD.id = int.Parse( slotsX[i].att("id") );
                if (slotsX[i].HasAtt("hiddenby")) {
                    string[] hiding = slotsX[i].att("hiddenby").Split(',');
                    foreach( string s in hiding ) {
                        tSD.hiddenBy.Add ( int.Parse(s) );
                    }
                }
                slotDefs.Add(tSD);
                break;

            case "drawpile":
                tSD.stagger.x = float.Parse( slotsX[i].att("xstagger") );
                drawPile = tSD;
                break;
            case "discardpile":
                discardPile = tSD;
                break;
            }
        }
    }
Ejemplo n.º 9
0
    //以下函数将被调用来读取LayoutXML.xml文件内容
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(xmlText);      //对XML格式字符串进行解析
        xml = xmlr.xml["xml"][0]; //将xml设置为访问XML内容的快捷方式

        //读取用于设置纸牌间距的系数
        multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"));
        //读入牌的位置
        SlotDef tSD;
        //slotsX是读取所有的<slot>的快捷方式
        PT_XMLHashList slotsX = xml["slot"];

        for (int i = 0; i < slotsX.Count; i++)
        {
            tSD = new SlotDef();//新建一个SlotDef实例
            if (slotsX[i].HasAtt("type"))
            {
                //如果<slot>标签中有type属性,则解析其内容
                tSD.type = slotsX[i].att("type");
            }
            else
            {
                //如果没有type属性,则将type设置为"slot",表示场景中的纸牌
                tSD.type = "slot";
            }
            //各种属性均被解析为数值
            tSD.x         = float.Parse(slotsX[i].att("x"));
            tSD.y         = float.Parse(slotsX[i].att("y"));
            tSD.layerID   = int.Parse(slotsX[i].att("layer"));
            tSD.layerName = sortingLayerName[tSD.layerID];
            switch (tSD.type)
            {
            case "slot":
                tSD.faceUp = (slotsX[i].att("faceup") == "1");
                tSD.id     = int.Parse(slotsX[i].att("id"));
                if (slotsX[i].HasAtt("hiddenby"))
                {
                    string[] hiding = slotsX[i].att("hiddenby").Split(',');
                    foreach (string s in hiding)
                    {
                        tSD.hiddenBy.Add(int.Parse(s));
                    }
                }
                slotDefs.Add(tSD);
                break;

            case "drawpile":
                tSD.stagger.x = float.Parse(slotsX[i].att("xstagger"));
                drawPile      = tSD;
                break;

            case "discardpile":
                discardPile = tSD;
                break;
            }
        }
    }
    //读取LayoutXML.xml中的纸牌排列信息
    public void ReadLayout(string xmlTest)
    {
        xmlr = new PT_XMLReader();    //调用PT_XMLReader脚本
        xmlr.Parse(xmlTest);
        xml = xmlr.xml["xml"][0];

        //读取缩放系数multiplier
        multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"));

        //读取slot中的信息
        SlotDef        tSD;
        PT_XMLHashList slotsX = xml["slot"];

        for (int i = 0; i < slotsX.Count; i++)
        {
            tSD = new SlotDef();
            if (slotsX[i].HasAtt("type"))     //说明是两种牌堆之一
            {
                tSD.type = slotsX[i].att("type");
            }
            else               //说明是row1-row3
            {
                tSD.type = "slot";
            }
            tSD.x       = float.Parse(slotsX[i].att("x"));
            tSD.y       = float.Parse(slotsX[i].att("y"));
            tSD.layerID = int.Parse(slotsX[i].att("layer"));
            //把layerID转换成text layerName
            tSD.layerName = sortingLayerNames[tSD.layerID];

            switch (tSD.type)
            {
            case "slot":
                tSD.faceUp = (slotsX[i].att("faceup") == "1"); //bool
                tSD.id     = int.Parse(slotsX[i].att("id"));
                if (slotsX[i].HasAtt("hiddenby"))              //对于不是在最上面的那几排
                {
                    string[] hiding = slotsX[i].att("hiddenby").Split(',');
                    foreach (string s in hiding)
                    {
                        tSD.hiddenBy.Add(int.Parse(s));
                    }
                }
                slotDefs.Add(tSD);       //加入了row0-row3中的一张牌
                break;

            case "drawpile":
                tSD.stagger.x = float.Parse(slotsX[i].att("xstagger"));
                drawPile      = tSD;
                break;

            case "discardpile":
                discardPile = tSD;
                break;
            }
        }
    }
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(xmlText);
        xml = xmlr.xml["xml"][0];

        multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"));

        SolSlotDef     tSD;
        PT_XMLHashList slotsX = xml["slot"];

        for (int i = 0; i < slotsX.Count; i++)
        {
            tSD = new SolSlotDef();
            if (slotsX[i].HasAtt("type"))
            {
                tSD.type = slotsX[i].att("type");
            }
            else
            {
                tSD.type = "slot";
            }

            tSD.x   = float.Parse(slotsX[i].att("x"));
            tSD.y   = float.Parse(slotsX[i].att("y"));
            tSD.pos = new Vector3(tSD.x * multiplier.x, tSD.y * multiplier.y, 0);

            tSD.layerID   = int.Parse(slotsX[i].att("layer"));
            tSD.layerName = tSD.layerID.ToString();

            switch (tSD.type)
            {
            case "slot":
                tSD.faceUp = slotsX[i].att("faceup") == "1";
                tSD.id     = int.Parse(slotsX[i].att("id"));
                if (slotsX[i].HasAtt("hiddenby"))
                {
                    tSD.hiddenBy = int.Parse(slotsX[i].att("hiddenby"));
                }
                slotDefs.Add(tSD);
                break;

            case "drawpile":
                tSD.stagger.x = float.Parse(slotsX[i].att("xstagger"));
                drawPile      = tSD;
                break;

            case "discardpile":
                discardPile = tSD;
                break;

            case "aces":
                aces.Add(tSD);
                break;
            }
        }
    }
Ejemplo n.º 12
0
	void Start(){
		S = this; 
		GameObject tAnc = new GameObject("TileAnchor");
		tileAnchor = tAnc.transform;
		roomsXMLR = new PT_XMLReader(); 
		roomsXMLR.Parse(roomsText.text); 
		roomsXML = roomsXMLR.xml["xml"][0]["room"]; 
		BuildRoom(roomNumber);
	}//end of Start()
Ejemplo n.º 13
0
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader ();
        xmlr.Parse (xmlText);
        xml = xmlr.xml ["xml"][0];

        multiplier.x = float.Parse (xml ["multiplier"] [0].att ("x"));
        multiplier.y = float.Parse (xml ["multiplier"] [0].att ("y"));

        SlotDef tSD;
        PT_XMLHashList slotsX = xml ["slot"];

        for (int i = 0; i < slotsX.Count; i++) {

            tSD = new SlotDef ();

            if(slotsX[i].HasAtt("type")){

                tSD.type = slotsX[i].att("type");

            }else{

                tSD.type = "slot";

            }
            tSD.x = float.Parse(slotsX[i].att("x"));
            tSD.y = float.Parse(slotsX[i].att("y"));
            tSD.layerID = int.Parse(slotsX[i].att("layer"));
            tSD.layerName = sortLayerNames[tSD.layerID];

            switch(tSD.type){

            case "slot":
                tSD.faceUp = (slotsX[i].att ("faceup") == "1");
                tSD.id = int.Parse (slotsX[i].att ("id"));
                if(slotsX[i].HasAtt ("hiddenby")){

                    string[] hiding = slotsX[i].att ("hiddenby").Split (',');
                    foreach(string s in hiding){ tSD.hiddenBy.Add(int.Parse(s)); }

                }
                slotDefs.Add (tSD);
                break;

            case "drawpile":
                tSD.stagger.x = float.Parse( slotsX[i].att ("xstagger") );
                drawPile = tSD;
                break;

            case "discardpile":
                discardPile = tSD;
                break;

            }

        }
    }
Ejemplo n.º 14
0
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(xmlText);
        xml = xmlr.xml["xml"][0];

        multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"));

        SlotDefMatching tSD;
        PT_XMLHashList  slotsX = xml["slot"];

        for (int i = 0; i < slotsX.Count; i++)
        {
            tSD = new SlotDefMatching();
            if (slotsX[i].HasAtt("type"))
            {
                tSD.type = slotsX[i].att("type");
            }
            else
            {
                tSD.type = "slot";
            }

            tSD.x   = float.Parse(slotsX[i].att("x"));
            tSD.y   = float.Parse(slotsX[i].att("y"));
            tSD.pos = new Vector3(tSD.x * multiplier.x, tSD.y * multiplier.y, 0);

            tSD.layerID   = int.Parse(slotsX[i].att("layer"));
            tSD.layerName = tSD.layerID.ToString();

            switch (tSD.type)
            {
            case "slot":
                tSD.id     = int.Parse(slotsX[i].att("id"));
                tSD.faceUp = (slotsX[i].att("faceup") == "1");
                if (tSD.id <= 25)
                {
                    cardGroupOne.Add(tSD);
                }
                else
                {
                    cardGroupTwo.Add(tSD);
                }
                break;

            case "matchesP1":
                playerOneMatches = tSD;
                break;

            case "matchesP2":
                playerTwoMatches = tSD;
                break;
            }
        }
    }
Ejemplo n.º 15
0
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader ();
        xmlr.Parse (xmlText);
        xml = xmlr.xml ["xml"] [0];

        multiplier.x = float.Parse(xml["multiplier"][0].att ("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att ("y"));

        SlotDef tSD;
        PT_XMLHashList slotsX = xml ["slot"];

        for (int i = 0; i < slotsX.Count; i++) {

            tSD = new SlotDef();
            if(slotsX[i].HasAtt("type"))
                tSD.type = slotsX[i].att("type");
            else
                tSD.type = "slot";

            tSD.x = float.Parse (slotsX[i].att("x"));
            tSD.y = float.Parse (slotsX[i].att("y"));

            tSD.pos = new Vector3 (tSD.x * multiplier.x, tSD.y * multiplier.y, 0);

            tSD.layerID = int.Parse ( slotsX[i].att ("layer"));
            tSD.layerName = tSD.layerID.ToString();

            switch(tSD.type){

            case "slot":
                break;

            case "drawpile":
                tSD.stagger.x = float.Parse(slotsX[i].att("xstagger"));
                drawPile = tSD;
                break;

            case "discardpile":
                discardPile = tSD;
                break;

            case "target":
                target = tSD;
                break;

            case "hand":
                tSD.player = int.Parse(slotsX[i].att ("player"));
                tSD.rot = float.Parse(slotsX[i].att ("rot"));
                slotDefs.Add(tSD);
                break;

            }

        }
    }
Ejemplo n.º 16
0
    void ReadDescription(string text)
    {
        if (text != null)
        {
            PT_XMLReader xmlr = Utils.GetXMLReader();
            xmlr.Parse(text);

            description = xmlr.xml["description"][0]["name"][0].text;
        }
    }
Ejemplo n.º 17
0
	public void ReadLayout(string xmlText){
		//bring in the XML and set a shortcut reference to it as xml
		xmlr = new PT_XMLReader ();
		xmlr.Parse (xmlText);
		xml = xmlr.xml ["xml"] [0];

		//set up multiplier
		multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
		multiplier.y = float.Parse(xml["multiplier"][0].att("y"));

		SlotDef tSD;

		PT_XMLHashList slotsX = xml ["slot"];

		for (int i = 0; i < slotsX.Count; i++) {
			tSD = new SlotDef ();
			if (slotsX [i].HasAtt ("type")) tSD.type = slotsX [i].att ("type");
			else tSD.type = "slot";

			//parse various values into floats to assign them to the temporary slot definition
			tSD.x = float.Parse (slotsX [i].att ("x"));
			tSD.y = float.Parse (slotsX [i].att ("y"));
			tSD.pos = new Vector3 (tSD.x * multiplier.x, tSD.y * multiplier.y, 0);

			//layer sorting
			//layers are assigned numerical values 1-10
			tSD.layerID = int.Parse(slotsX[i].att("layer"));
			tSD.layerName = tSD.layerID.ToString (); //converts layer number to a string

			switch (tSD.type) {
			case "slot":
				break;

			case "drawpile":
				tSD.stagger.x = float.Parse (slotsX [i].att ("xstagger"));
				drawPile = tSD;
				break;

			case "discardpile":
				discardPile = tSD;
				break;

			case "target":
				target = tSD;
				break;

			case "hand":
				tSD.player = int.Parse (slotsX [i].att ("player"));
				tSD.rot = float.Parse (slotsX [i].att ("rot"));
				slotDefs.Add (tSD);
				break;
			}//end of switch(tSD.type)
		}//end of for i
	}//end of ReadLayout(string xmlText)
Ejemplo n.º 18
0
	void Awake() {
		S = this; // Set the Singleton for LayoutTiles
		// Make a new GameObject to be the TileAnchor (the parent transform of
		// all Tiles). This keeps Tiles tidy in the Hierarchy pane.
		GameObject tAnc = new GameObject("TileAnchor");
		tileAnchor = tAnc.transform;
		// Read the XML
		roomsXMLR = new PT_XMLReader(); // Create a PT_XMLReader
		roomsXMLR.Parse(roomsText.text); // Parse the Rooms.xml file
		roomsXML = roomsXMLR.xml["xml"][0]["room"]; // Pull all the <room>s
		// Build the 0th Room
		BuildRoom(roomNumber);
	}
Ejemplo n.º 19
0
    void Awake()
    {
        S = this;   // Задаём синглтон

        // Создаём новый ио чтобы быть якорем для всех плит
        // сохранит нашу иерархию чистой
        GameObject tAnc = new GameObject("TileAnchor");

        tileAnchor = tAnc.transform;

        // Читаем XML
        roomsXMLR = new PT_XMLReader();             // Создаём считыватель
        roomsXMLR.Parse(roomsText.text);            // Передаём Rooms.xml
        roomsXML = roomsXMLR.xml["xml"][0]["room"]; // Достаём все комнаты
    }
Ejemplo n.º 20
0
    void Awake()
    {
        S = this;         // Set the Singleton for LayoutTiles
        // Make a new GameObject to be the TileAnchor (the parent transform of
        //  all Tiles). This keeps Tiles tidy in the Hierarchy pane.
        GameObject tAnc = new GameObject("TileAnchor");

        tileAnchor = tAnc.transform;
        // Read the XML
        roomsXMLR = new PT_XMLReader();             // Create a PT_XMLReader
        roomsXMLR.Parse(roomsText.text);            // Parse the Rooms.xml file
        roomsXML = roomsXMLR.xml["xml"][0]["room"]; // Pull all the <room>s
        // Build the 0th Room
        BuildRoom(roomNumber);
    }
Ejemplo n.º 21
0
	public void ReadDeck(string deckXMLText){
		xmlr = new PT_XMLReader ();
		xmlr.Parse (deckXMLText);

		string s = "xml[0] decorator[0]";
		s += "type=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("type");
		s += " x=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("x");
		s += " y=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("y");
		s += "scale=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("scale");
		//print (s);

		decorators = new List<Decorator>();

		PT_XMLHashList xDecos = xmlr.xml ["xml"] [0] ["decorator"];
		Decorator deco;
		for (int i = 0; i<xDecos.Count; i++) {
				deco = new Decorator ();
				deco.type = xDecos [i].att ("type");

				//set bool flip based on text being 1 or not 1
				deco.flip = (xDecos [i].att ("flip") == "1");
				//floats parsed from attribute strings
				deco.scale = float.Parse (xDecos [i].att ("scale"));

				deco.loc.x = float.Parse (xDecos [i].att ("x"));
				deco.loc.y = float.Parse (xDecos [i].att ("y"));
				deco.loc.z = float.Parse (xDecos [i].att ("z"));

				decorators.Add (deco);
			}

		cardDefs = new List<CardDefinition> ();
		PT_XMLHashList xCardDefs = xmlr.xml ["xml"] [0] ["card"];
		for(int i = 0; i<xCardDefs.Count; i++)
		{
			CardDefinition cDef = new CardDefinition();
			cDef.rank = int.Parse(xCardDefs[i].att("rank"));
			//get hashlist of all pips
			PT_XMLHashList xPipe = xCardDefs[i]["pip"];
			if(xPips != null){
				for(int j=0; j<xPips.Count;j++){
					deco = new Decorator();
					deco.type = "pip";
					deco.flip = (xPips[j].att("flip") == "1");
					deco.loc.x = float.Parse (xPips[j].att ("x"));
					deco.loc.y = float.Parse (xPips[j].att ("y"));
					deco.loc.z = float.Parse (xPips[j].att ("z"));
					if(xPips.[j].HasAtt("scale")){
Ejemplo n.º 22
0
    //Methods

    void Start()
    {
        S = this;

        //Make tile anchor
        GameObject tAnc = new GameObject("TileAnchor");

        tileAnchor = tAnc.transform;

        //Read room xml
        roomsXMLR = new PT_XMLReader();
        roomsXMLR.Parse(roomsText.text);
        roomsXML = roomsXMLR.xml ["xml"] [0] ["room"];

        //Build 0th room
        BuildRoom(roomNumber);
    }
Ejemplo n.º 23
0
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(xmlText);
        xml = xmlr.xml["xml"][0];

        multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"));

        SlotDef tSD;

        PT_XMLHashList slotsX = xml["slot"];

        for (int i = 0; i < slotsX.Count; i++)
        {
            tSD = new SlotDef();
            if (slotsX[i].HasAtt("type"))
            {
                tSD.type = slotsX[i].att("type");
            }
            else
            {
                tSD.type = "slot";
            }
            tSD.x = float.Parse(slotsX[i].att("x"));
            tSD.y = float.Parse(slotsX[i].att("y"));

            switch (tSD.type)
            {
            case "slot":
                tSD.faceUp = (slotsX[i].att("faceup") == "1");
                tSD.id     = int.Parse(slotsX[i].att("id"));
                slotDefs.Add(tSD);
                break;

            case "drawpile":
                tSD.stagger.x = float.Parse(slotsX[i].att("xstagger"));
                drawPile      = tSD;
                break;

            case "discardpile":
                discardPile = tSD;
                break;
            }
        }
    }
Ejemplo n.º 24
0
    private void Start()
    {
        S = this;
        //Make a new GameObject to be the TileAnchor (the parent transform of all tiles).
        //This keeps Tiles tidy in the Hierarchy pane;
        GameObject tAnc = new GameObject("TileAnchor");

        tileAnchor = tAnc.transform;

        //Read the XML
        roomsXMLR = new PT_XMLReader();
        roomsXMLR.Parse(roomsText.text);
        roomsXML = roomsXMLR.xml["xml"][0]["room"]; // Get all the <rooms>s

        //Build the 0 room
        BuildRoom(roomNumber);
    }
Ejemplo n.º 25
0
    void Start()
    {
        S = this;         //Singleton for LayoutTiles

        //Make a new GameObject to be the TileAnchor (the parent transform of all Tiles). To keep Tiles tidy in the hierarchy pane
        GameObject tAnc = new GameObject("TileAnchor");

        tileAnchor = tAnc.transform;

        //Read the XML
        roomsXMLR = new PT_XMLReader();             //Create a PT_XMLReader, which is lighter-weight that what's on .NET
        roomsXMLR.Parse(roomsText.text);            //Parse the Rooms.xml file
        roomsXML = roomsXMLR.xml["xml"][0]["room"]; //Pull all the <room>s

        //Build the 0th room
        BuildRoom(roomNumber);
    }
Ejemplo n.º 26
0
    // ReadDeck parses the XML file passed to it into CardDefinitions
    public void ReadDeck(string lootDeckXMLText)
    {
        xmlr = new PT_XMLReader();   // Create a new PT_XMLReader
        xmlr.Parse(lootDeckXMLText); // Use that PT_XMLReader to parse DeckXML

        // Read skull locations for each card number
        cardDefs = new List <CardDefinition>(); // Init the List of Cards
        // Grab an PT_XMLHashList of all the <card>s in the XML file
        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];

        for (int i = 0; i < xCardDefs.Count; i++)
        {
            // For each of the <card>s
            // Create a new CardDefinition
            CardDefinition cDef = new CardDefinition();
            // Parse the attribute values and add them to cDef
            cDef.value = int.Parse(xCardDefs[i].att("value"));
        }
    }
Ejemplo n.º 27
0
	static public void LoadShots()
	{
		shots = new List<Shot> ();

		if (!PlayerPrefs.HasKey(prefsName))
		{
			return;
		}

		string shotsXML = PlayerPrefs.GetString (prefsName);
		PT_XMLReader xmlr = new PT_XMLReader ();
		xmlr.Parse (shotsXML);

		PT_XMLHashList hl = xmlr.xml["xml"] [0] ["shot"];
		for (int i=0; i<hl.Count; i++)
		{
			PT_XMLHashtable ht = hl[i];
			Shot sh = ParseShotXML(ht);shots.Add(sh);
		}
	}
Ejemplo n.º 28
0
    private void Awake()
    {
        //为LayoutTiles设置Singleton值
        S = this;

        //创建一个新的GameObject为TileAnchor
        GameObject tAnc = new GameObject("TileAnchor");

        tileAnchor = tAnc.transform;

        //读取XML
        //创建一个PT_XMLReader对象
        roomsXMLR = new PT_XMLReader();
        //解析Rooms.xml文件
        roomsXMLR.Parse(roomsText.text);
        //导出所有<room>
        roomsXML = roomsXMLR.xml["xml"][0]["room"];

        //建立第0个room
        BuildRoom(roomNumber);
    }
Ejemplo n.º 29
0
    static public void LoadShots()
    {
        shots = new List <Shot> ();

        if (!PlayerPrefs.HasKey(prefsName))
        {
            return;
        }

        string       shotsXML = PlayerPrefs.GetString(prefsName);
        PT_XMLReader xmlr     = new PT_XMLReader();

        xmlr.Parse(shotsXML);

        PT_XMLHashList hl = xmlr.xml["xml"] [0] ["shot"];

        for (int i = 0; i < hl.Count; i++)
        {
            PT_XMLHashtable ht = hl[i];
            Shot            sh = ParseShotXML(ht); shots.Add(sh);
        }
    }
Ejemplo n.º 30
0
    //把xml文件编译后传递到CarDefinitions中
    public void ReadDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(deckXMLText);   //用PT_XMLReader脚本的Parse方法读xml
        string s = "xml[0] decorator[0] ";

        s += "type=" + xmlr.xml["xml"][0]["decorator"][0].att("type");
        s += " x=" + xmlr.xml["xml"][0]["decorator"][0].att("x");
        s += " y=" + xmlr.xml["xml"][0]["decorator"][0].att("y");
        s += " scale=" + xmlr.xml["xml"][0]["decorator"][0].att("scale");
        // print(s);

        //read decorators for all Cards
        decorators = new List <Decorator>();
        PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"]; //得到全部“decorator”下的信息
        Decorator      deco;                                     //声明其中一个<decorator>

        //对于xml中的每个<decorator>, 这个项目中为Count=4
        for (int i = 0; i < xDecos.Count; i++)
        {
            deco = new Decorator();
            //deco储存每一个decorator中的信息
            deco.type  = xDecos[i].att("type");
            deco.flip  = (xDecos[i].att("flip") == "1");  //true if flip att is "1"
            deco.scale = float.Parse(xDecos[i].att("scale"));
            deco.loc.x = float.Parse(xDecos[i].att("x"));
            deco.loc.y = float.Parse(xDecos[i].att("y"));
            deco.loc.z = float.Parse(xDecos[i].att("z"));
            decorators.Add(deco);
        }

        //read图案排列图形,xml文件中的所有<card>
        cardDefs = new List <CardDefinition>();
        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];  //得到全部<card>下的信息

        for (int i = 0; i < xCardDefs.Count; i++)
        {
            CardDefinition cDef = new CardDefinition();
            cDef.rank = int.Parse(xCardDefs[i].att("rank"));
            PT_XMLHashList xPips = xCardDefs[i]["pip"]; //"pip"不是xml中的att
            if (xPips != null)                          //针对1-10
            {
                for (int j = 0; j < xPips.Count; j++)
                {
                    deco       = new Decorator();
                    deco.type  = "pip";
                    deco.flip  = (xPips[j].att("flip") == "1");
                    deco.loc.x = float.Parse(xPips[j].att("x"));
                    deco.loc.y = float.Parse(xPips[j].att("y"));
                    deco.loc.z = float.Parse(xPips[j].att("z"));
                    if (xPips[j].HasAtt("scale"))     //针对1
                    {
                        deco.scale = float.Parse(xPips[j].att("scale"));
                    }
                    cDef.pips.Add(deco);
                }
            }
            if (xCardDefs[i].HasAtt("face"))    //针对JQK,“face”是此xml中的att
            {
                cDef.face = xCardDefs[i].att("face");
            }
            cardDefs.Add(cDef);
        }
    }
Ejemplo n.º 31
0
    // Readdeck parses the XML file passed to it into CardDefinitions
    public void ReadDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader();                        // Create a new PT_XMLReader
        xmlr.Parse(deckXMLText);                          // Use that PT_XMLReader to parse DeckXML

        //This prints a test line to show you how xmlr can be used.
        string s = "xml[0] decorator[0] ";

        s += "type=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att("type");
        s += " x=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att("x");
        s += " y=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att("y");
        s += " scale" + xmlr.xml ["xml"] [0] ["decorator"] [0].att("scale");
        // print (s); // Commented out as this is just for testing

        //Read decorators for all Cards
        decorators = new List <Decorator> ();        //Init the List of Decorators
        //Grab a PT_XMLHashList of all <decorator>s in the XML file
        PT_XMLHashList xDecos = xmlr.xml ["xml"] [0] ["decorator"];
        Decorator      deco;

        for (int i = 0; i < xDecos.Count; i++)
        {
            // For each <decorator> in the XML
            deco = new Decorator();                                      // Make a new Decorator
            //Copy the attributes of the <decorator> to the Decorator
            deco.type = xDecos [i].att("type");
            // Set the bool flip based on whetherthe text of the attribute is "1" or something else.
            // This is an atrypical but perfectly fine use of the == comparison operator.
            // It will return a true or false, which will be assigned to deco.flip
            deco.flip = (xDecos [i].att("flip") == "1");
            // floats need to be parsed from the attribute strings
            deco.scale = float.Parse(xDecos [i].att("scale"));
            // Vector3 loc initializes to [0,0,0], so we just need to modify it
            deco.loc.x = float.Parse(xDecos [i].att("x"));
            deco.loc.y = float.Parse(xDecos [i].att("y"));
            deco.loc.z = float.Parse(xDecos [i].att("z"));
            // Add the temporary deco to the List decorators
            decorators.Add(deco);
        }

        // Read pip locations for each card number
        cardDefs = new List <CardDefinition> ();        // Init the List of Cards
        // Grab a PT_XMLHashList of all the <card>s in the XML file
        PT_XMLHashList xCardDefs = xmlr.xml ["xml"] [0] ["card"];

        for (int i = 0; i < xCardDefs.Count; i++)
        {
            // For each of the <card>s
            // Create a new CardDefinition
            CardDefinition cDef = new CardDefinition();
            // Parse the attribute values and add them to cDef
            cDef.rank = int.Parse(xCardDefs [i].att("rank"));
            // Grab a PT_XMLHastlist of all the <pip>s on this <card>
            PT_XMLHashList xPips = xCardDefs [i] ["pip"];
            if (xPips != null)
            {
                for (int j = 0; j < xPips.Count; j++)
                {
                    //Iterate through all the <pip>s
                    deco = new Decorator();
                    // <pip>s on the <card> are handled via the Decorator Class
                    deco.type  = "pip";
                    deco.flip  = (xPips [j].att("flip") == "1");
                    deco.loc.x = float.Parse(xPips [j].att("x"));
                    deco.loc.y = float.Parse(xPips [j].att("y"));
                    deco.loc.z = float.Parse(xPips [j].att("z"));
                    if (xPips [j].HasAtt("scale"))
                    {
                        deco.scale = float.Parse(xPips [j].att("scale"));
                    }
                    cDef.pips.Add(deco);
                }
            }
            // Face cards (Jack, Queen, & King) have a face attribute
            // cDef.face is the base name of the face card Sprite
            // e.g., FaceCard_11 is the base name for the Jack face Sprites
            // the Jack of CLubs is FaceCard_11C, hearts is FaceCard_11H, etc.
            if (xCardDefs [i].HasAtt("face"))
            {
                cDef.face = xCardDefs [i].att("face");
            }
            cardDefs.Add(cDef);
        }
    }
Ejemplo n.º 32
0
	//ReadDeck parses the XML file passed to it into CardDefinitions
	public void ReadDeck(string deckXMLText)
	{
		xmlr = new PT_XMLReader();  //Create a new PT_XMLReader
		xmlr.Parse(deckXMLText);  //Use that PT_XMLReader to parse DeckXML
		
		//This prints a test line to show you how xmlr can be used.
		//For more info read about XML in the Useful Concepts section of book
		string s = "xmlr.xml[0] decorator[0]";
		s += "type="+xmlr.xml["xml"][0]["decorator"][0].att("type");
		s += " x="+xmlr.xml["xml"][0]["decorator"][0].att("x");
		s += " y="+xmlr.xml["xml"][0]["decorator"][0].att("y");
		s += " scale="+xmlr.xml["xml"][0]["decorator"][0].att("scale");
		//print(s);  //Done with this test now
		
		//Read decorators for all Cards
		decorators = new List<Decorator>();  //Init the list of Decorator
		//Grab a PT_XMLHashList of all <decorator>s in the XML file
		PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"];
		Decorator deco;
		for (int i=0; i<xDecos.Count; i++)
		{
			//For each decorator in the xml
			deco = new Decorator();  //Make new Decorator
			//Copy the attributes of the <decorator> to the Decorator
			deco.type = xDecos[i].att("type");
			//Set the bool flip based on bwether the text of the attribute is 
			//"1" or something else.  This is an atypical but perfectly fine
			//use of the == comparison operator.  It will return a true or 
			//false, which will be assigned to deco.flip.
			deco.flip = (xDecos[i].att ("flip") == "1");
			//floats need to be parsed from the attribute strings
			deco.scale = float.Parse(xDecos[i].att ("scale"));
			//Vector3 loc initializes to [0,0,0], so we just need to modify it
			deco.loc.x = float.Parse(xDecos[i].att ("x"));
			deco.loc.y = float.Parse(xDecos[i].att ("y"));
			deco.loc.z = float.Parse(xDecos[i].att ("z"));
			//Add the temporary deco to the list decorators
			decorators.Add (deco);
		}
		
		//Read pip locations for each card number
		cardDefs = new List<CardDefinition>();  //Init the list of cards
		//Grab a PT_XMLHashList of all the <card>s in the xml file
		PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];
		for (int i=0; i<xCardDefs.Count; i++)
		{
			//for each of the <card>s
			//create new CardDefinition
			CardDefinition cDef = new CardDefinition();
			//parse the attribute values and add them to cDef
			cDef.rank = int.Parse(xCardDefs[i].att ("rank"));
			//Grab a PT_XMLHashList of all the <pip>s on this <card>
			PT_XMLHashList xPips = xCardDefs[i]["pip"];
			if (xPips != null)
			{
				for (int j=0; j<xPips.Count; j++)
				{
					//Iterate through all of the <pip>s
					deco = new Decorator();
					//<pip>s on the <card> are handled via the decorator class
					deco.type = "pip";
					deco.flip = (xPips[j].att ("flip") == "1");
					deco.loc.x = float.Parse(xPips[j].att ("x"));
					deco.loc.y = float.Parse(xPips[j].att ("y"));
					deco.loc.z = float.Parse(xPips[j].att ("z"));
					if (xPips[j].HasAtt("scale"))
					{
						deco.scale = float.Parse(xPips[j].att ("scale"));
					}
					cDef.pips.Add(deco);
				}
			}
			//Face cards (Jack, King, Queen) have a face attribute
			//cDef.face is the name of the face card Sprite
			//e.g., Jack of clubs is FaceCard_11c, hearts is FaceCard_11H, etc.
			if (xCardDefs[i].HasAtt("face"))
			{
				cDef.face = xCardDefs[i].att ("face");
			}
			cardDefs.Add(cDef);
		}
	}
Ejemplo n.º 33
0
    // This function is called to read in the LayoutXML.xml file
    public void ReadLayout(string xmlText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(xmlText);      // The XML is parsed
        xml = xmlr.xml["xml"][0]; // And xml is set as a shortcut to the XML

        // Read in the multiplier, which sets card spacing
        multiplier.x = float.Parse(xml["multiplier"][0].att("x"));
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"));

        // Read in the slots
        SlotDef tSD;
        // slotsX is used as a shortcut to all the <slot>s
        PT_XMLHashList slotsX = xml["slot"];

        for (int i = 0; i < slotsX.Count; i++)
        {
            tSD = new SlotDef();  // Create a new SlotDef instance
            if (slotsX[i].HasAtt("type"))
            {
                // If this <slot> has a type attribute parse it
                tSD.type = slotsX[i].att("type");
            }
            else
            {
                // If not, set its type to "slot"
                tSD.type = "slot";
            }

            // Various attributes are parsed into numerical values
            tSD.x   = float.Parse(slotsX[i].att("x"));
            tSD.y   = float.Parse(slotsX[i].att("y"));
            tSD.pos = new Vector3(tSD.x * multiplier.x, tSD.y * multiplier.y, 0);

            // Sorting Layers
            tSD.layerID = int.Parse(slotsX[i].att("layer"));
            // In this game, the Sorting Layers are named 1, 2, 3, ...through 10
            // This converts the number of the layerID into a text layerName
            tSD.layerName = tSD.layerID.ToString();
            // The layers are used to make sure that the correct cards are
            //   on top of the others. In Unity 2D, all of our assets are
            //   effectively at the same Z depth, so sorting layers are used
            //   to differentiate between them.

            // pull additional attributes based on the type of each <slot>
            switch (tSD.type)
            {
            case "slot":
                // ignore slots that are just of the "slot" type
                break;

            case "drawpile":
                // The drawPile xstagger is read but not actually used in Bartok
                tSD.stagger.x = float.Parse(slotsX[i].att("xstagger"));
                drawPile      = tSD;
                break;

            case "discardpile":
                discardPile = tSD;
                break;

            case "target":
                // The target card has a different layer from discardPile
                target = tSD;
                break;

            case "hand":
                // Information for each player's hand
                tSD.player = int.Parse(slotsX[i].att("player"));
                tSD.rot    = float.Parse(slotsX[i].att("rot"));
                slotDefs.Add(tSD);
                break;
            }
        }
    }
Ejemplo n.º 34
0
    // ReadDeck parses the XML file passed to it into Card Definitions
    public void ReadDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(deckXMLText);


        string s = "xml[0] decorator [0] ";

        s += "type=" + xmlr.xml["xml"][0]["decorator"][0].att("type");
        s += " x=" + xmlr.xml["xml"][0]["decorator"][0].att("x");
        s += " y=" + xmlr.xml["xml"][0]["decorator"][0].att("y");
        s += " scale=" + xmlr.xml["xml"][0]["decorator"][0].att("scale");
        print(s);

        //Read decorators for all cards

        decorators = new List <Decorator>();

        PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"];
        Decorator      deco;

        for (int i = 0; i < xDecos.Count; i++)
        {
            // for each decorator in the XML, copy attributes and set up location and flip if needed
            deco       = new Decorator();
            deco.type  = xDecos[i].att("type");
            deco.flip  = (xDecos[i].att("flip") == "1");
            deco.scale = float.Parse(xDecos[i].att("scale"));
            deco.loc.x = float.Parse(xDecos[i].att("x"));
            deco.loc.y = float.Parse(xDecos[i].att("y"));
            deco.loc.z = float.Parse(xDecos[i].att("z"));
            decorators.Add(deco);
        }


        cardDefs = new List <CardDefinition>();
        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];

        for (int i = 0; i < xCardDefs.Count; i++)
        {
            // for each carddef in the XML, copy attributes and set up in cDef
            CardDefinition cDef = new CardDefinition();
            cDef.rank = int.Parse(xCardDefs[i].att("rank"));

            PT_XMLHashList xPips = xCardDefs[i]["pip"];
            if (xPips != null)
            {
                for (int j = 0; j < xPips.Count; j++)
                {
                    deco      = new Decorator();
                    deco.type = "pip";
                    deco.flip = (xPips[j].att("flip") == "1");   // too cute by half - if it's 1, set to 1, else set to 0

                    deco.loc.x = float.Parse(xPips[j].att("x"));
                    deco.loc.y = float.Parse(xPips[j].att("y"));
                    deco.loc.z = float.Parse(xPips[j].att("z"));
                    if (xPips[j].HasAtt("scale"))
                    {
                        deco.scale = float.Parse(xPips[j].att("scale"));
                    }
                    cDef.pips.Add(deco);
                }
            }
            if (xCardDefs[i].HasAtt("face"))
            {
                cDef.face = xCardDefs[i].att("face");
            }
            cardDefs.Add(cDef);
        } // for i < xCardDefs.Count
    }     // ReadDeck
    // ReadDeck parses the XML file passed to it into CardDefinitions
    public void ReadDeck(string deckXMLText)
    {
        // Create a new PT_XMLReader
        xmlr = new PT_XMLReader();

        // Use that PT_XMLReader to parse DeckXML
        xmlr.Parse(deckXMLText);

        // This prints a test line to show you how xmlr can be used
        // For more information read about the XML in the Useful Concept Appendix
        string s = "xml[0] decorator[0]";

        s += "type=" + xmlr.xml["xml"][0]["decorator"][0].att("type");
        s += " x=" + xmlr.xml["xml"][0]["decorator"][0].att("x");
        s += " y=" + xmlr.xml["xml"][0]["decorator"][0].att("y");
        s += " scale=" + xmlr.xml["xml"][0]["decorator"][0].att("scale");
        //print(s); // Comment out this line, since we are done with the test



        // Read decorators for all Cards
        // Init the list of decorators
        decorators = new List <Decorator>();
        // Grab a PT_XMLHashList of all <decorator>s in the XML file
        PT_XMLHashList decoHashList = xmlr.xml["xml"][0]["decorator"];

        // Initialize the decorators in the xml and add them into the decorators list.
        Decorator deco;

        // For each decorator to work, we need four variables: the type of the suit/letter as string,
        // the location of the suit/letter as vector3, the size as float, and whether it is flipped as bool
        for (int i = 0; i < decoHashList.Count; i++)
        {
            // Make a new decorator
            deco = new Decorator();

            // Find the four variable attribution of the [i] element
            string  type     = decoHashList[i].att("type");
            Vector3 location = new Vector3();
            location.x = float.Parse(decoHashList[i].att("x"));
            location.y = float.Parse(decoHashList[i].att("y"));
            location.z = float.Parse(decoHashList[i].att("z"));

            float size    = float.Parse(decoHashList[i].att("scale"));
            bool  flipped = (decoHashList[i].att("flip") == "1");

            // Assign them to the new decorator
            deco.flip  = flipped;
            deco.loc   = location;
            deco.scale = size;
            deco.type  = type;

            // Add them to the new decorator list
            decorators.Add(deco);
        }


        // Read pip location for each card number
        // Init the List of the Cards
        cardDefs = new List <CardDefinition>();

        // Grab a PT_XMLHashList of all the <card>s in the XML file
        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];

        // For each cardDefinition, we need 3 infos, the rank of a int number
        // the face if it is a faced card, and a list of decorators as pip
        for (int i = 0; i < xCardDefs.length; i++)
        {
            // Make a new cardDef
            CardDefinition cardDef = new CardDefinition();

            // Find the variables of the [i] element as a card definition
            cardDef.rank = int.Parse(xCardDefs[i].att("rank"));

            // Iterate through all the pips in the hashlist and creates decorators
            // After initialize the new decorators with data,
            // add them into the pip list of the cardDef
            PT_XMLHashList xPips = xCardDefs[i]["pip"];
            if (xPips != null)
            {
                for (int j = 0; j < xPips.length; j++)
                {
                    // Make a new decorator for use
                    Decorator decorator = new Decorator();

                    // type, location, scale and flip
                    decorator.type  = "pip";
                    decorator.loc.x = float.Parse(xPips[j].att("x"));
                    decorator.loc.y = float.Parse(xPips[j].att("y"));
                    decorator.loc.z = float.Parse(xPips[j].att("z"));

                    if (xPips[i].HasAtt("scale"))
                    {
                        decorator.scale = float.Parse(xPips[i].att("scale"));
                    }

                    decorator.flip = (xPips[j].att("flip") == "1");

                    // add them into the pip list of the cardDef
                    cardDef.pips.Add(decorator);
                }
            }

            // Face cards (Jack, Queen, & King) have a face attribute
            // cDef.face is the best name of the face Sprite
            // e.g., FaceCard_11 is the base name for the Jack face Sprites
            // the Jack of Clubs is FaceCard_11C, hearts is FaceCard_11H, etc.
            if (xCardDefs[i].HasAtt("face"))
            {
                cardDef.face = xCardDefs[i].att("face");
            }

            cardDefs.Add(cardDef);
        }
    }
Ejemplo n.º 36
0
    //ReadDeck parses the XML file passed to it into CardDefinitions
    public void ReadDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader(); //Create a new PT_XMLReader
        xmlr.Parse(deckXMLText); //use that PT_XMLREeader to parse DeckXML

        //This prints a test line to show you how xmlr can be used

        string s = "xml[0] decorator[0] ";
        s += "type="+xmlr.xml["xml"][0]["decorator"][0].att ("type");
        s += " x="+xmlr.xml["xml"][0]["decorator"][0].att ("x");
        s += " y="+xmlr.xml["xml"][0]["decorator"][0].att ("y");
        s += " scale="+xmlr.xml["xml"][0]["decorator"][0].att ("scale");
        //print (s);

        //Read decorators for all Cards
        decorators = new List<Decorator>();
        //Grab a PT_XMLHasList of all <decorators> in the XML file
        PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"];
        Decorator deco;

        for (int i=0; i<xDecos.Count; i++) {
            deco = new Decorator(); //Make a new decorator
            //Copy the attributes of the <decorator> to the Decorator
            deco.type = xDecos[i].att("type");
            //Set the bool flip based on whether the text of the attribute is "1" or
            //something else. This is an atypical but perfectly fine use of the == comparison
            //operator. It will return a true or false, which will be assigned to deco.flip
            deco.flip = (xDecos[i].att ("flip") == "1");
            //floats need to be parsed from the attributes strings
            deco.scale = float.Parse (xDecos[i].att ("scale"));
            //Vector3 loc initalizes to [0,0,0], so we just need to modify it
            deco.loc.x = float.Parse (xDecos[i].att ("x"));
            deco.loc.y = float.Parse (xDecos[i].att ("y"));
            deco.loc.z = float.Parse (xDecos[i].att ("z"));
            //add the temp deco to the List decorators
            decorators.Add (deco);
        }

        //Read pip locations for each card number
        cardDefs = new List<CardDefinition>(); //init the list of cards
        //grab a PT_XMLHashList of all the <cards>s in the XML file
        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];

        for (int i=0; i<xCardDefs.Count; i++){
            //For each of the <card>s
            //Create a new CArdDefinition
            CardDefinition cDef = new CardDefinition();
            //Parse the attribute values and add them to cDef
            cDef.rank = int.Parse(xCardDefs[i].att ("rank"));
            //Grab a PT_XMLHashList of all the <pip>s on this <card>
            PT_XMLHashList xPips = xCardDefs[i]["pip"];
            if (xPips != null) {
                for (int j=0; j<xPips.Count; j++) {
                    //Iterate through all the <pip>s
                    deco = new Decorator();
                    //<pip>s on the card> are handled via the DEcorator Class
                    deco.type = "pip";
                    deco.flip = (xPips[j].att ("flip") == "1");
                    deco.loc.x = float.Parse(xPips[j].att ("x"));
                    deco.loc.y = float.Parse(xPips[j].att ("y"));
                    deco.loc.z = float.Parse(xPips[j].att ("z"));
                    if (xPips[j].HasAtt("scale")){
                        deco.scale = float.Parse(xPips[j].att ("scale"));
                    }
                    cDef.pips.Add(deco);
                }
            }
            //FAce cards have a face attribute
            //cDef.face is the base name of the face card Sprite
            //e.g. FAceCard_11 is the base name for the Jack face Sprites
            //the Jack of Clubs is FaceCard_11C, hearts is FaceCard_11H, etc.
            if (xCardDefs[i].HasAtt("face")) {
                cDef.face = xCardDefs[i].att ("face");
            }
            cardDefs.Add(cDef);
        }
    }
Ejemplo n.º 37
0
 void Start()
 {
     S = this; // Set the Singleton for LayoutTiles
     // Make a new GameObject to be the TileAnchor (the parent transform of
     // all Tiles). This keeps Tiles tidy in the Hierarchy pane.
     GameObject tAnc = new GameObject("TileAnchor");
     tileAnchor = tAnc.transform;
     Utils.tr("..........",tileAnchor);
     // Read the XML
     levelsXMLR = new PT_XMLReader(); // Create a PT_XMLReader
     levelsXMLR.Parse(levelText.text); // Parse the Rooms.xml file
     levelsXML = levelsXMLR.xml["xml"][0]["level"]; // Pull all the <room>s
     BuildLevel (ApplicationModel.XMLlevel);
 }
Ejemplo n.º 38
0
    public void ReadDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(deckXMLText);

        string s = "xml[0] decorator[0] ";
        s += "type="+xmlr.xml["xml"][0]["decorator"][0].att ("type");
        s += " x="+xmlr.xml["xml"][0]["decorator"][0].att ("x");
        s += " y="+xmlr.xml["xml"][0]["decorator"][0].att ("y");
        s += " scale="+xmlr.xml["xml"][0]["decorator"][0].att ("scale");

        decorators = new List<Decorator>();
        PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"];
        Decorator deco;

        for (int i=0; i<xDecos.Count; i++) {
            deco = new Decorator();
            deco.type = xDecos[i].att("type");
            deco.flip = (xDecos[i].att ("flip") == "1");
            deco.scale = float.Parse (xDecos[i].att ("scale"));
            deco.loc.x = float.Parse (xDecos[i].att ("x"));
            deco.loc.y = float.Parse (xDecos[i].att ("y"));
            deco.loc.z = float.Parse (xDecos[i].att ("z"));
            decorators.Add (deco);
        }

        cardDefs = new List<CardDefinition>();
        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];

        for (int i=0; i<xCardDefs.Count; i++){

            CardDefinition cDef = new CardDefinition();
            cDef.rank = int.Parse(xCardDefs[i].att ("rank"));
            PT_XMLHashList xPips = xCardDefs[i]["pip"];
            if (xPips != null) {
                for (int j=0; j<xPips.Count; j++) {
                    deco = new Decorator();
                    deco.type = "pip";
                    deco.flip = (xPips[j].att ("flip") == "1");
                    deco.loc.x = float.Parse(xPips[j].att ("x"));
                    deco.loc.y = float.Parse(xPips[j].att ("y"));
                    deco.loc.z = float.Parse(xPips[j].att ("z"));
                    if (xPips[j].HasAtt("scale")){
                        deco.scale = float.Parse(xPips[j].att ("scale"));
                    }
                    cDef.pips.Add(deco);
                }
            }
            if (xCardDefs[i].HasAtt("face")) {
                cDef.face = xCardDefs[i].att ("face");
            }
            cardDefs.Add(cDef);
        }
    }
Ejemplo n.º 39
0
Archivo: Deck.cs Proyecto: 9/Prospector
    // ReadDeck parses the XML file passed to it into Card Definitions
    public void ReadDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader ();
        xmlr.Parse (deckXMLText);

        // print a test line
        string s = "xml[0] decorator [0] ";
        s += "type=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("type");
        s += " x=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("x");
        s += " y=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("y");
        s += " scale=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att ("scale");
        print (s);

        //Read decorators for all cards
        // these are the small numbers/suits in the corners
        decorators = new List<Decorator>();
        // grab all decorators from the XML file
        PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"];
        Decorator deco;
        for (int i=0; i<xDecos.Count; i++) {
            // for each decorator in the XML, copy attributes and set up location and flip if needed
            deco = new Decorator();
            deco.type = xDecos[i].att ("type");
            deco.flip = (xDecos[i].att ("flip") == "1");   // too cute by half - if it's 1, set to 1, else set to 0
            deco.scale = float.Parse (xDecos[i].att("scale"));
            deco.loc.x = float.Parse (xDecos[i].att("x"));
            deco.loc.y = float.Parse (xDecos[i].att("y"));
            deco.loc.z = float.Parse (xDecos[i].att("z"));
            decorators.Add (deco);
        }

        // read pip locations for each card rank
        // read the card definitions, parse attribute values for pips
        cardDefs = new List<CardDefinition>();
        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];

        for (int i=0; i<xCardDefs.Count; i++) {
            // for each carddef in the XML, copy attributes and set up in cDef
            CardDefinition cDef = new CardDefinition();
            cDef.rank = int.Parse(xCardDefs[i].att("rank"));

            PT_XMLHashList xPips = xCardDefs[i]["pip"];
            if (xPips != null) {
                for (int j = 0; j < xPips.Count; j++) {
                    deco = new Decorator();
                    deco.type = "pip";
                    deco.flip = (xPips[j].att ("flip") == "1");   // too cute by half - if it's 1, set to 1, else set to 0

                    deco.loc.x = float.Parse (xPips[j].att("x"));
                    deco.loc.y = float.Parse (xPips[j].att("y"));
                    deco.loc.z = float.Parse (xPips[j].att("z"));
                    if(xPips[j].HasAtt("scale") ) {
                        deco.scale = float.Parse (xPips[j].att("scale"));
                    }
                    cDef.pips.Add (deco);
                } // for j
            }// if xPips

            // if it's a face card, map the proper sprite
            // foramt is ##A, where ## in 11, 12, 13 and A is letter indicating suit
            if (xCardDefs[i].HasAtt("face")){
                cDef.face = xCardDefs[i].att ("face");
            }
            cardDefs.Add (cDef);
        } // for i < xCardDefs.Count
    }
Ejemplo n.º 40
0
    // ReadDeck parses the XML file passed to it into CardDefinitions
    public void ReadDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader();         // Create a new PT_XMLReader
        xmlr.Parse(deckXMLText);           // Use that PT_XMLReader to parse DeckXML

        // The following prints a test line to show you how xmlr can be used.
        // For more information read about XML in the Useful Concepts Appendix
        string s = "xml[0] decorator[0] ";

        s += "type=" + xmlr.xml["xml"][0]["decorator"][0].att("type");
        s += " x=" + xmlr.xml["xml"][0]["decorator"][0].att("x");
        s += " y=" + xmlr.xml["xml"][0]["decorator"][0].att("y");
        s += " scale=" + xmlr.xml["xml"][0]["decorator"][0].att("scale");
        //print(s); // Comment out this line, since we're done with the test

        // Read decorators for all Cards
        decorators = new List <Decorator>();        // Init the List of Decorators
        // Grab an PT_XMLHashList of all <decorator>s in the XML file
        PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"];
        Decorator      deco;

        for (int i = 0; i < xDecos.Count; i++)
        {
            // For each <decorator> in the XML
            deco = new Decorator();             // Make a new Decorator
            // Copy the attributes of the <decorator> to the Decorator
            deco.type = xDecos[i].att("type");
            // bool deco.flip is true if the text of the flip attribute is "1"
            deco.flip = (xDecos[i].att("flip") == "1");                                              // a
            // floats need to be parsed from the attribute strings
            deco.scale = float.Parse(xDecos[i].att("scale"));
            // Vector3 loc initializes to [0,0,0], so we just need to modify it
            deco.loc.x = float.Parse(xDecos[i].att("x"));
            deco.loc.y = float.Parse(xDecos[i].att("y"));
            deco.loc.z = float.Parse(xDecos[i].att("z"));
            // Add the temporary deco to the List decorators
            decorators.Add(deco);
        }

        // Read pip locations for each card number
        cardDefs = new List <CardDefinition>();        // Init the List of Cards
        // Grab an PT_XMLHashList of all the <card>s in the XML file
        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];

        for (int i = 0; i < xCardDefs.Count; i++)
        {
            // For each of the <card>s
            // Create a new CardDefinition
            CardDefinition cDef = new CardDefinition();
            // Parse the attribute values and add them to cDef
            cDef.rank = int.Parse(xCardDefs[i].att("rank"));
            // Grab an PT_XMLHashList of all the <pip>s on this <card>
            PT_XMLHashList xPips = xCardDefs[i]["pip"];
            if (xPips != null)
            {
                for (int j = 0; j < xPips.Count; j++)
                {
                    // Iterate through all the <pip>s
                    deco = new Decorator();
                    // <pip>s on the <card> are handled via the Decorator Class
                    deco.type  = "pip";
                    deco.flip  = (xPips[j].att("flip") == "1");
                    deco.loc.x = float.Parse(xPips[j].att("x"));
                    deco.loc.y = float.Parse(xPips[j].att("y"));
                    deco.loc.z = float.Parse(xPips[j].att("z"));
                    if (xPips[j].HasAtt("scale"))
                    {
                        deco.scale = float.Parse(xPips[j].att("scale"));
                    }
                    cDef.pips.Add(deco);
                }
            }
            // Face cards (Jack, Queen, & King) have a face attribute
            if (xCardDefs[i].HasAtt("face"))
            {
                cDef.face = xCardDefs[i].att("face");                                         // b
            }
            cardDefs.Add(cDef);
        }
    }
Ejemplo n.º 41
0
    // ReadDeck parses the XML file passed to it into Card Definitions
    public void ReadDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(deckXMLText);

        // print a test line
        string s = "xml[0] decorator [0] ";

        s += "type=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att("type");
        s += " x=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att("x");
        s += " y=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att("y");
        s += " scale=" + xmlr.xml ["xml"] [0] ["decorator"] [0].att("scale");
        print(s);

        //Read decorators for all cards
        // these are the small numbers/suits in the corners
        decorators = new List <Decorator>();
        // grab all decorators from the XML file
        PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"];
        Decorator      deco;

        for (int i = 0; i < xDecos.Count; i++)
        {
            // for each decorator in the XML, copy attributes and set up location and flip if needed
            deco       = new Decorator();
            deco.type  = xDecos[i].att("type");
            deco.flip  = (xDecos[i].att("flip") == "1");               // too cute by half - if it's 1, set to 1, else set to 0
            deco.scale = float.Parse(xDecos[i].att("scale"));
            deco.loc.x = float.Parse(xDecos[i].att("x"));
            deco.loc.y = float.Parse(xDecos[i].att("y"));
            deco.loc.z = float.Parse(xDecos[i].att("z"));
            decorators.Add(deco);
        }

        // read pip locations for each card rank
        // read the card definitions, parse attribute values for pips
        cardDefs = new List <CardDefinition>();
        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];

        for (int i = 0; i < xCardDefs.Count; i++)
        {
            // for each carddef in the XML, copy attributes and set up in cDef
            CardDefinition cDef = new CardDefinition();
            cDef.rank = int.Parse(xCardDefs[i].att("rank"));

            PT_XMLHashList xPips = xCardDefs[i]["pip"];
            if (xPips != null)
            {
                for (int j = 0; j < xPips.Count; j++)
                {
                    deco      = new Decorator();
                    deco.type = "pip";
                    deco.flip = (xPips[j].att("flip") == "1");                        // too cute by half - if it's 1, set to 1, else set to 0

                    deco.loc.x = float.Parse(xPips[j].att("x"));
                    deco.loc.y = float.Parse(xPips[j].att("y"));
                    deco.loc.z = float.Parse(xPips[j].att("z"));
                    if (xPips[j].HasAtt("scale"))
                    {
                        deco.scale = float.Parse(xPips[j].att("scale"));
                    }
                    cDef.pips.Add(deco);
                }        // for j
            }            // if xPips

            // if it's a face card, map the proper sprite
            // foramt is ##A, where ## in 11, 12, 13 and A is letter indicating suit
            if (xCardDefs[i].HasAtt("face"))
            {
                cDef.face = xCardDefs[i].att("face");
            }
            cardDefs.Add(cDef);
        } // for i < xCardDefs.Count
    }     // ReadDeck
Ejemplo n.º 42
0
    // ReadDeck parses the XML file passed to it into CardDefinitions
    public void ReadDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader(); // Create a new PT_XMLReader
        xmlr.Parse(deckXMLText);   // Use that PT_XMLReader to parse DeckXML

        // This prints a test line to show you how xmlr can be used.
        // For more information read about XML in the Useful Concepts Appendix
        string s = "xml[0] decorator[0] ";
        s += "type=" + xmlr.xml["xml"][0]["decorator"][0].att("type");
        s += " x=" + xmlr.xml["xml"][0]["decorator"][0].att("x");
        s += " y=" + xmlr.xml["xml"][0]["decorator"][0].att("y");
        s += " scale=" + xmlr.xml["xml"][0]["decorator"][0].att("scale");
        //print(s); // Comment out this line, since we're done with the test

        // Read decorators for all Cards
        decorators = new List<Decorator>(); // Init the List of Decorators
        // Grab a PT_XMLHashList of all <decorator>s in the XML file
        PT_XMLHashList xDecos = xmlr.xml["xml"][0]["decorator"];
        Decorator deco;
        for (int i = 0; i < xDecos.Count; i++)
        {
            // For each <decorator> in the XML
            deco = new Decorator(); // Make a new Decorator
            // Copy the attributes of the <decorator> to the Decorator
            deco.type = xDecos[i].att("type");
            // Set the bool flip based on whether the text of the attribute is
            //   "1" or something else. This is an atypical but perfectly fine
            //   use of the == comparison operator. It will return a true or
            //   false, which will be assigned to deco.flip.
            deco.flip = (xDecos[i].att("flip") == "1");
            // floats need to be parsed from the attribute strings
            deco.scale = float.Parse(xDecos[i].att("scale"));
            // Vector3 loc initializes to [0,0,0], so we just need to modify it
            deco.loc.x = float.Parse(xDecos[i].att("x"));
            deco.loc.y = float.Parse(xDecos[i].att("y"));
            deco.loc.z = float.Parse(xDecos[i].att("z"));
            // Add the temporary deco to the List decorators
            decorators.Add(deco);
        }

        // Read pip locations for each card number
        cardDefs = new List<CardDefinition>(); // Init the List of Cards
        // Grab a PT_XMLHashList of all the <card>s in the XML file
        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["card"];
        for (int i = 0; i < xCardDefs.Count; i++)
        {
            // For each of the <card>s
            // Create a new CardDefinition
            CardDefinition cDef = new CardDefinition();
            // Parse the attribute values and add them to cDef
            cDef.rank = int.Parse(xCardDefs[i].att("rank"));
            // Grab a PT_XMLHashList of all the <pip>s on this <card>
            PT_XMLHashList xPips = xCardDefs[i]["pip"];
            if (xPips != null)
            {
                for (int j = 0; j < xPips.Count; j++)
                {
                    // Iterate through all the <pip>s
                    deco = new Decorator();
                    // <pip>s on the <card> are handled via the Decorator Class
                    deco.type = "pip";
                    deco.flip = (xPips[j].att("flip") == "1");
                    deco.loc.x = float.Parse(xPips[j].att("x"));
                    deco.loc.y = float.Parse(xPips[j].att("y"));
                    deco.loc.z = float.Parse(xPips[j].att("z"));
                    if (xPips[j].HasAtt("scale"))
                    {
                        deco.scale = float.Parse(xPips[j].att("scale"));
                    }
                    cDef.pips.Add(deco);
                }
            }
            // Face cards (Jack, Queen, & King) have a face attribute
            // cDef.face is the base name of the face card Sprite
            // e.g., FaceCard_11 is the base name for the Jack face Sprites
            // the Jack of Clubs is FaceCard_11C, hearts is FaceCard_11H, etc.
            if (xCardDefs[i].HasAtt("face"))
            {
                cDef.face = xCardDefs[i].att("face");
            }
            cardDefs.Add(cDef);
        }

    }