Esempio 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;
            }
        }
    }
Esempio n. 2
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;
            }
        }
    }
Esempio n. 3
0
 internal static PT_XMLReader GetXMLReader()
 {
     if (XML_READER == null)
     {
         XML_READER = new PT_XMLReader();
     }
     return XML_READER;
 }
Esempio n. 4
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;

            }

        }
    }
Esempio n. 5
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;

            }

        }
    }
Esempio n. 6
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);
	}
Esempio n. 7
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);
		}
	}
Esempio n. 8
0
    //ReadDeck parses the XML file passed to it into CardDefinitions
    public void ReadDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(deckXMLText);

        //this prints a test line to show 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_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 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 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 intializes 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>();
        //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 <cards>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);
        }
    }
Esempio n. 9
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);
        }
    }
Esempio n. 10
0
    // Bartok calls this method to read in the BartokLayoutXML.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.pos = new Vector3(tSD.x * multiplier.x, tSD.y * multiplier.y, 0);

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

            // 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":
                tSD.stagger.x = float.Parse(slotsX[i].att("xstagger"));
                drawPile      = tSD;
                break;

            case "redDiscardpile":
                redDiscardPile = tSD;
                break;

            case "greenDiscardpile":
                greenDiscardPile = tSD;
                break;

            case "whiteDiscardpile":
                whiteDiscardPile = tSD;
                break;

            case "blueDiscardpile":
                blueDiscardPile = tSD;
                break;

            case "yellowDiscardpile":
                yellowDiscardPile = tSD;
                break;

            case "redPlayer1":
                redPlayer1    = tSD;
                tSD.stagger.y = float.Parse(slotsX[i].att("ystagger"));
                break;

            case "redPlayer2":
                redPlayer2    = tSD;
                tSD.stagger.y = float.Parse(slotsX[i].att("ystagger"));
                tSD.rot       = float.Parse(slotsX[i].att("rot"));
                break;

            case "greenPlayer1":
                greenPlayer1  = tSD;
                tSD.stagger.y = float.Parse(slotsX[i].att("ystagger"));
                break;

            case "greenPlayer2":
                greenPlayer2  = tSD;
                tSD.stagger.y = float.Parse(slotsX[i].att("ystagger"));
                tSD.rot       = float.Parse(slotsX[i].att("rot"));
                break;

            case "whitePlayer1":
                whitePlayer1  = tSD;
                tSD.stagger.y = float.Parse(slotsX[i].att("ystagger"));
                break;

            case "whitePlayer2":
                whitePlayer2  = tSD;
                tSD.stagger.y = float.Parse(slotsX[i].att("ystagger"));
                tSD.rot       = float.Parse(slotsX[i].att("rot"));
                break;

            case "bluePlayer1":
                bluePlayer1   = tSD;
                tSD.stagger.y = float.Parse(slotsX[i].att("ystagger"));
                break;

            case "bluePlayer2":
                bluePlayer2   = tSD;
                tSD.stagger.y = float.Parse(slotsX[i].att("ystagger"));
                tSD.rot       = float.Parse(slotsX[i].att("rot"));
                break;

            case "yellowPlayer1":
                yellowPlayer1 = tSD;
                tSD.stagger.y = float.Parse(slotsX[i].att("ystagger"));
                break;

            case "yellowPlayer2":
                yellowPlayer2 = tSD;
                tSD.stagger.y = float.Parse(slotsX[i].att("ystagger"));
                tSD.rot       = float.Parse(slotsX[i].att("rot"));
                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;
            }
        }
    }
Esempio n. 11
0
    public void Start()
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(layoutXML.ToString());

        PT_XMLHashList slots = xmlr.xml["xml"][0]["slot"];

        Vector3 drawPilePos    = new Vector3();
        Vector3 discardPilePos = new Vector3();

        float drawPileStagger = 0f;

        // Read XML Slots to intialize our draw and discard piles
        for (int i = 0; i < slots.Count; i++)
        {
            if (slots[i].att("type").Equals("drawpile"))
            {
                drawPilePos.x   = float.Parse(slots[i].att("x"));
                drawPilePos.y   = float.Parse(slots[i].att("y"));
                drawPileStagger = float.Parse(slots[i].att("xstagger"));
            }

            if (slots[i].att("type").Equals("discardpile"))
            {
                discardPilePos.x = float.Parse(slots[i].att("x"));
                discardPilePos.y = float.Parse(slots[i].att("y"));
            }
        }



        tempDiscardPile.discard.transform.position = discardPilePos;

        // Parse Draw Pile and Stagger It

        transform.position = drawPilePos;

        int tempSorting = playableCards.Count + 5;

        for (int i = 0; i < playableCards.Count; i++)
        {
            playableCards[i].transform.position = drawPilePos;
            playableCards[i].GetComponent <QueensCard>().cardBack.sortingOrder = tempSorting;
            drawPilePos.x += drawPileStagger;
            tempSorting--;
        }

        for (int i = 0; i < playableCards.Count; i++)
        {
            drawStack.Push(playableCards[i]);
        }


        // Create an XMLHashList of our defined Queen Positions
        PT_XMLHashList queenPositions = xmlr.xml["xml"][0]["queenSlot"];

        for (int t = 0; t < queenPositions.Count; t++)
        {
            Vector2 curPos = Vector2.zero;

            float x;
            float y;

            // the x position of our current vector2 = the x position of our current definition.
            x = float.Parse(queenPositions[t].att("x"));
            y = float.Parse(queenPositions[t].att("y"));

            curPos = new Vector2(x, y);

            this.queensPositions.Add(curPos);
        }

        PlaceQueenCards();
    }
Esempio n. 12
0
File: Deck.cs Progetto: 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
    }
Esempio n. 13
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);
		}
	}
Esempio n. 14
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]; //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();

            if (slotsX[i].HasAtt("type"))
            {
                //parse the slot if it has a type attribute
                tSD.type = slotsX[i].att("type");
            }

            else
            {
                //if not, set its type to slot
                tSD.type = "slot";
            }

            //various attributes are parsed into numberical 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 convers the number of layerID ontp a text layerName
            tSD.layerName = sortingLayerNames[tSD.layerID];

            //pull additional attributes based ont the type of <slot>
            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;
            }
        }
    }
Esempio n. 15
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 the layer is used
            //to differentiate between them.
            // pull additional attributes based on the type of this <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;
            }
        }
    }
Esempio n. 16
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

        // 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");
            // 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");
            }
            cardDefs.Add(cDef);
        }
    }
Esempio n. 17
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"), CultureInfo.InvariantCulture);
        multiplier.y = float.Parse(xml["multiplier"][0].att("y"), CultureInfo.InvariantCulture);

        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"), CultureInfo.InvariantCulture);
            tSD.y         = float.Parse(slotsX[i].att("y"), CultureInfo.InvariantCulture);
            tSD.pos       = new Vector3(tSD.x * multiplier.x, tSD.y * multiplier.y, 0);
            tSD.layerID   = int.Parse(slotsX[i].att("layer"), CultureInfo.InvariantCulture);
            tSD.layerName = tSD.layerID.ToString();

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

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

            case "discardpile":
            {
                discardPile = tSD;
                break;
            }

            case "target":
            {
                target = tSD;
                break;
            }

            case "hand":
            {
                tSD.player = int.Parse(slotsX[i].att("player"), CultureInfo.InvariantCulture);
                tSD.rot    = float.Parse(slotsX[i].att("rot"), CultureInfo.InvariantCulture);
                slotDefs.Add(tSD);
                break;
            }
            }
        }
    }
Esempio n. 18
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
Esempio n. 19
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);
        }
    }
Esempio n. 20
0
 //Set the defaults
 void Start()
 {
     reader = new PT_XMLReader();
     //This is the entry point for the dialogue, the first selected
     currentText = "Start";
     //Set background width and calculate the upper left hand corner of the background's coordinates.
     bgWidth = screenwidth;
     upCornery = screenheight - bgHeight;
     upCornerx = 0;
     diaHash = new Hashtable();
 }
Esempio n. 21
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);
        }
    }
Esempio n. 22
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);
 }
Esempio n. 23
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"; 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;
            }
        }
    }
Esempio n. 24
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);
        }
    }
Esempio n. 25
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);
        }

    }