Пример #1
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));
                    }
                }
                slotDefs.Add(tSD);
                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"));

        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);

            // Sorting Layers
            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;
            }
        }
    }
Пример #3
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;
            }
        }
    }
Пример #4
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)
Пример #5
0
    private void Awake()
    {
        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);
    }
Пример #6
0
    public void ReadLayout(string xmlText)
    {
        this.XmlReader = new PT_XMLReader();
        this.XmlReader.Parse(xmlText);
        this.Xml = this.XmlReader.xml["xml"][0];

        this.Multiplier.x = float.Parse(this.Xml["multiplier"][0].att("x"));
        this.Multiplier.y = float.Parse(this.Xml["multiplier"][0].att("y"));

        SlotDef tSlotDef;

        PT_XMLHashList slotsX = this.Xml["slot"];

        for (var i = 0; i < slotsX.Count; i++)
        {
            tSlotDef = new SlotDef
            {
                Type    = slotsX[i].HasAtt("type") ? slotsX[i].att("type") : "slot",
                X       = float.Parse(slotsX[i].att("x")),
                Y       = float.Parse(slotsX[i].att("y")),
                LayerId = int.Parse(slotsX[i].att("layer"))
            };

            tSlotDef.LayerName = this.SortingLayerNames[tSlotDef.LayerId];

            switch (tSlotDef.Type)
            {
            case "slot":
                tSlotDef.FaceUp = (slotsX[i].att("faceup") == "1");
                tSlotDef.Id     = int.Parse(slotsX[i].att("id"));
                if (slotsX[i].HasAtt("hiddenby"))
                {
                    string[] hiding = slotsX[i].att("hiddenby").Split(',');
                    foreach (var s in hiding)
                    {
                        tSlotDef.HiddenBy.Add(int.Parse(s));
                    }
                }
                this.SlotDefs.Add(tSlotDef);
                break;

            case "drawpile":
                tSlotDef.Stagger.x = float.Parse(slotsX[i].att("xstagger"));
                this.DrawPile      = tSlotDef;
                break;

            case "discardpile":
                this.DiscardPile = tSlotDef;
                break;
            }
        }
    }
Пример #7
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);
	}
Пример #8
0
    public void Set(string key, PT_XMLHashList val)
    {
        int ndx = Index(key);

        if (ndx != -1)
        {
            nodesList[ndx] = val;
        }
        else
        {
            keys.Add(key);
            nodesList.Add(val);
        }
    }
Пример #9
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);
    }
Пример #10
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"]; // Достаём все комнаты
    }
    // Set the hashtable value of a certain key, the value is a hashlist
    public void Set(string key, PT_XMLHashList val)
    {
        int ndx = Index(key);

        if (ndx != -1)
        {
            nodesList[ndx] = val;             // If there is an index as the key, set the value of the nodesList[idx] as the value
        }
        else
        {
            keys.Add(key);             // If there is no such index, add this key as the index
            nodesList.Add(val);        // And add this value into the List. since it is the last value and the last key,
            //so there are corresponded with each other too.
        }
    }
Пример #12
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")){
Пример #13
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);
    }
Пример #14
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);
    }
Пример #15
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);
    }
Пример #16
0
    public void ReadDeck(string deckXMLText)
    {
        xmlr = new PT_XMLReader();
        xmlr.Parse(deckXMLText);
        PrintDebugMsg(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");
        PrintDebugMsg(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");
            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 (xCardDefs[i].HasAtt("face"))
            {
                cDef.face = xCardDefs[i].att("face");
            }
            cardDefs.Add(cDef);
        }
    }
Пример #17
0
    public void NewPips(Decorator deco)
    {
        //read pip locations for the card
        cardDefs = new List <CardDefinition>();

        PT_XMLHashList xCardDefs = xmlr.xml["xml"][0]["style"][1]["card"];

        //     Debug.Log("xCardDefs count: " + xCardDefs.Count);
        for (int i = 0; i < xCardDefs.Count; i++)
        {
            //create new card def
            CardDefinition cDef = new CardDefinition();



            //parse
            cDef.rank = int.Parse(xCardDefs[i].att("rank"));
            //grab
            PT_XMLHashList xPips = xCardDefs[i]["pip"];
            if (xPips != null)
            {
                for (int j = 0; j < xPips.Count; j++)
                {
                    deco = new Decorator();
                    //pips on the card are handled via the 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);
        }
    }
Пример #18
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"));
        }
    }
Пример #19
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);
    }
Пример #20
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);
        }
    }
Пример #21
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
Пример #22
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);
        }
    }
Пример #23
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);
        }
    }
Пример #24
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);
        }
    }
Пример #25
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;
            }
        }
    }
    // 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"];

        print(sortingLayerNames.Length);
        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];

            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;
            }
        }
    }
    // 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);
        }
    }
Пример #28
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
Пример #29
0
    // Loot calls this method to read in the LootLayoutXML.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 "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;

            case "merchant":
                merchant = tSD;
                break;

            case "pirate":
                tSD.player = int.Parse(slotsX[i].att("player"));
                break;
            }
        }
    }
Пример #30
0
    // This function parses a single tag and calls Parse() if it encounters subtags
    string ParseTag(string eS, PT_XMLHashtable eH)
    {
        // search for "<"
        int ndx = eS.IndexOf("<");
        int end, end1, end2, end3;

        if (ndx == -1)
        {
            // It's possible that this is just a string (e.g. <someTagTheStringIsInside>string</someTagTheStringIsInside>)
            end3 = eS.IndexOf(">");             // This closes a standard tag; look for the closing tag
            if (end3 == -1)
            {
                // In that case, we just need to add an @ key/value to the hashtable
                eS = eS.Trim();                 // I think this is redundant
                //eH["@"] = eS;
                eH.text = eS;
            }
            return("");             // We're done with this tag
        }
        // Ignore this if it is just an XML header (e.g. <?xml version="1.0"?>)
        if (eS[ndx + 1] == '?')
        {
            // search for the closing tag of this header
            int    ndx2   = eS.IndexOf("?>");
            string header = eS.Substring(ndx, ndx2 - ndx + 2);
            //eH["@XML_Header"] = header;
            eH.header = header;
            return(eS.Substring(ndx2 + 2));
        }
        // Ignore this if it is an XML comment (e.g. <!-- Comment text -->)
        if (eS[ndx + 1] == '!')
        {
            // search for the closing tag of this header
            int    ndx2    = eS.IndexOf("-->");
            string comment = eS.Substring(ndx, ndx2 - ndx + 3);
            if (SHOW_COMMENTS)
            {
                Debug.Log("XMl Comment: " + comment);
            }
            //eH["@XML_Header"] = header;
            return(eS.Substring(ndx2 + 3));
        }

        // Find the end of the tag name
        // For the next few comments, this is what happens when this character is the first one found after the beginning of the tag
        end1 = eS.IndexOf(" ", ndx);            // This means that we'll have attributes
        end2 = eS.IndexOf("/", ndx);            // Immediately closes the tag,
        end3 = eS.IndexOf(">", ndx);            // This closes a standard tag; look for the closing tag
        if (end1 == -1)
        {
            end1 = int.MaxValue;
        }
        if (end2 == -1)
        {
            end2 = int.MaxValue;
        }
        if (end3 == -1)
        {
            end3 = int.MaxValue;
        }


        end = Mathf.Min(end1, end2, end3);
        string tag = eS.Substring(ndx + 1, end - ndx - 1);

        // search for this tag in eH. If it's not there, make it
        if (!eH.ContainsKey(tag))
        {
            eH[tag] = new PT_XMLHashList();
        }
        // Create a hashtable to contain this tag's information
        PT_XMLHashList arrL = eH[tag] as PT_XMLHashList;
        //int thisHashIndex = arrL.Count;
        PT_XMLHashtable thisHash = new PT_XMLHashtable();

        arrL.Add(thisHash);

        // Pull the attributes string
        string atts = "";

        if (end1 < end3)
        {
            try {
                atts = eS.Substring(end1, end3 - end1);
            }
            catch (System.Exception ex) {
                Debug.LogException(ex);
                Debug.Log("break");
            }
        }
        // Parse the attributes, which are all guaranteed to be strings
        string att, val;
        int    eqNdx, spNdx;

        while (atts.Length > 0)
        {
            atts  = atts.Trim();
            eqNdx = atts.IndexOf("=");
            if (eqNdx == -1)
            {
                break;
            }
            //att = "@"+atts.Substring(0,eqNdx);
            att   = atts.Substring(0, eqNdx);
            spNdx = atts.IndexOf(" ", eqNdx);
            if (spNdx == -1)               // This is the last attribute and doesn't have a space after it
            {
                val = atts.Substring(eqNdx + 1);
                if (val[val.Length - 1] == '/')                 // If the trailing / from /> was caught, remove it
                {
                    val = val.Substring(0, val.Length - 1);
                }
                atts = "";
            }
            else                 // This attribute has a space after it
            {
                val  = atts.Substring(eqNdx + 1, spNdx - eqNdx - 2);
                atts = atts.Substring(spNdx);
            }
            val = val.Trim('\"');
            //thisHash[att] = val; // All attributes have to be unique, so this should be okay.
            thisHash.attSet(att, val);
        }


        // Pull the subs, which is everything contained by this tag but exclusing the tags on either side (e.g. <tag att="hi">.....subs.....</tag>)
        string subs           = "";
        string leftoverString = "";
        // singleLine means this doesn't have a separate closing tag (e.g. <tag att="hi" />)
        bool singleLine = (end2 == end3 - 1); // ? true : false;

        if (!singleLine)                      // This is a multiline tag (e.g. <tag> ....  </tag>)
        // find the closing tag
        {
            int close = eS.IndexOf("</" + tag + ">");
            // TODO: Should this do something more if there is no closing tag?
            if (close == -1)
            {
                Debug.Log("XMLReader ERROR: XML not well formed. Closing tag </" + tag + "> missing.");
                return("");
            }
            subs           = eS.Substring(end3 + 1, close - end3 - 1);
            leftoverString = eS.Substring(eS.IndexOf(">", close) + 1);
        }
        else
        {
            leftoverString = eS.Substring(end3 + 1);
        }

        subs = subs.Trim();
        // Call Parse if this contains subs
        if (subs.Length > 0)
        {
            Parse(subs, thisHash);
        }

        // Trim and return the leftover string
        leftoverString = leftoverString.Trim();
        return(leftoverString);
    }
Пример #31
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);
 }
Пример #32
0
 public void Set(string key, PT_XMLHashList val)
 {
     int ndx = Index(key);
     if (ndx != -1) {
         nodesList[ndx] = val;
     } else {
         keys.Add(key);
         nodesList.Add(val);
     }
 }
Пример #33
0
    // This function parses a single tag and calls Parse() if it encounters subtags
    string ParseTag(string eS, PT_XMLHashtable eH)
    {
        // search for "<"
        int ndx = eS.IndexOf("<");
        int end, end1, end2, end3;
        if (ndx == -1) {
            // It's possible that this is just a string (e.g. <someTagTheStringIsInside>string</someTagTheStringIsInside>)
            end3 = eS.IndexOf(">"); // This closes a standard tag; look for the closing tag
            if (end3 == -1) {
                // In that case, we just need to add an @ key/value to the hashtable
                eS = eS.Trim(); // I think this is redundant
                //eH["@"] = eS;
                eH.text = eS;
            }
            return(""); // We're done with this tag
        }
        // Ignore this if it is just an XML header (e.g. <?xml version="1.0"?>)
        if (eS[ndx+1] == '?') {
            // search for the closing tag of this header
            int ndx2 = eS.IndexOf("?>");
            string header = eS.Substring(ndx, ndx2-ndx+2);
            //eH["@XML_Header"] = header;
            eH.header = header;
            return(eS.Substring(ndx2+2));
        }
        // Ignore this if it is an XML comment (e.g. <!-- Comment text -->)
        if (eS[ndx+1] == '!') {
            // search for the closing tag of this header
            int ndx2 = eS.IndexOf("-->");
            string comment = eS.Substring(ndx, ndx2-ndx+3);
            if (SHOW_COMMENTS) Debug.Log("XMl Comment: "+comment);
            //eH["@XML_Header"] = header;
            return(eS.Substring(ndx2+3));
        }

        // Find the end of the tag name
                                        // For the next few comments, this is what happens when this character is the first one found after the beginning of the tag
        end1 = eS.IndexOf(" ", ndx);	// This means that we'll have attributes
        end2 = eS.IndexOf("/", ndx);	// Immediately closes the tag,
        end3 = eS.IndexOf(">", ndx);	// This closes a standard tag; look for the closing tag
        if (end1 == -1) end1 = int.MaxValue;
        if (end2 == -1) end2 = int.MaxValue;
        if (end3 == -1) end3 = int.MaxValue;

        end = Mathf.Min(end1, end2, end3);
        string tag = eS.Substring(ndx+1, end-ndx-1);

        // search for this tag in eH. If it's not there, make it
        if (!eH.ContainsKey(tag)) {
            eH[tag] = new PT_XMLHashList();
        }
        // Create a hashtable to contain this tag's information
        PT_XMLHashList arrL = eH[tag] as PT_XMLHashList;
        //int thisHashIndex = arrL.Count;
        PT_XMLHashtable thisHash = new PT_XMLHashtable();
        arrL.Add(thisHash);

        // Pull the attributes string
        string atts = "";
        if (end1 < end3) {
            try {
                atts = eS.Substring(end1, end3-end1);
            }
            catch(System.Exception ex) {
                Debug.LogException(ex);
                Debug.Log("break");
            }
        }
        // Parse the attributes, which are all guaranteed to be strings
        string att, val;
        int eqNdx, spNdx;
        while (atts.Length > 0) {
            atts = atts.Trim();
            eqNdx = atts.IndexOf("=");
            if (eqNdx == -1) break;
            //att = "@"+atts.Substring(0,eqNdx);
            att = atts.Substring(0,eqNdx);
            spNdx = atts.IndexOf(" ",eqNdx);
            if (spNdx == -1) { // This is the last attribute and doesn't have a space after it
                val = atts.Substring(eqNdx+1);
                if (val[val.Length-1] == '/') { // If the trailing / from /> was caught, remove it
                    val = val.Substring(0,val.Length-1);
                }
                atts = "";
            } else { // This attribute has a space after it
                val = atts.Substring(eqNdx+1, spNdx - eqNdx - 2);
                atts = atts.Substring(spNdx);
            }
            val = val.Trim('\"');
            //thisHash[att] = val; // All attributes have to be unique, so this should be okay.
            thisHash.attSet(att, val);
        }

        // Pull the subs, which is everything contained by this tag but exclusing the tags on either side (e.g. <tag att="hi">.....subs.....</tag>)
        string subs = "";
        string leftoverString = "";
        // singleLine means this doesn't have a separate closing tag (e.g. <tag att="hi" />)
        bool singleLine = (end2 == end3-1);// ? true : false;
        if (!singleLine) { // This is a multiline tag (e.g. <tag> ....  </tag>)
            // find the closing tag
            int close = eS.IndexOf("</"+tag+">");
        // TODO: Should this do something more if there is no closing tag?
            if (close == -1) {
                Debug.Log("XMLReader ERROR: XML not well formed. Closing tag </"+tag+"> missing.");
                return("");
            }
            subs = eS.Substring(end3+1, close-end3-1);
            leftoverString = eS.Substring( eS.IndexOf(">",close)+1 );
        } else {
            leftoverString = eS.Substring(end3+1);
        }

        subs = subs.Trim();
        // Call Parse if this contains subs
        if (subs.Length > 0) {
            Parse(subs, thisHash);
        }

        // Trim and return the leftover string
        leftoverString = leftoverString.Trim();
        return(leftoverString);
    }
    public void ReadDeck(string deckXMLText)
    {
        xlmr = new PT_XMLReader();
        xlmr.Parse(deckXMLText);

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

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


        decorators = new List <Decorator>();
        PT_XMLHashList xDecos = xlmr.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 = xlmr.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)//if not face card
            {
                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"))//face cards
            {
                cDef.face = xCardDefs[i].att("face");
            }
            cardDefs.Add(cDef);
        }
    }//end of read deck