Example #1
0
    private void populate(int direction)
    {
        //populate page with 10 cards from those viable for current player's build
        //load database array from path using Reader
        Debug.Log("Entering Database Initialization Loop");
        if (!loadedDatabase)
        {
            Path           = Application.dataPath + "/scripts/xml/database.xml";
            Book           = new CardBook(Path);
            loadedDatabase = true;
            //TODO: Sort Database Deck by cost and lettering
        }
        Debug.Log("Exited Database Initialization Loop");
        //database loaded, proceed with book compilation
        Card current;

        Book.ChangeCurrentPage(direction);
        //add Cards of new CurrentPage to Displayed Cards
        Debug.Log("Entered GetCardsOfPage");
        DisplayedCards = Book.GetCardsOfPage(Book.CurrentPage);
        Debug.LogError("After page shift, first displayed is " + DisplayedCards[0].CardName);
        //instantiate the objects/visual representation
        for (int i = 1; i <= 10; i++)
        {
            Debug.Log("Entered DisplayLoop");
            GameObject card;
            //If there is another card to display (has next)
            current = DisplayedCards[i - 1];
            // Create the card with creature prefab
            card = (GameObject)Instantiate(displayedCardPrefab, slot1.transform.position, slot1.transform.rotation);
            card.transform.FindChild("Splash").gameObject.GetComponent <Image>().sprite = spriteSheet[UnityEngine.Random.Range(0, 8)];    //TODO: nonrandom sprites
            if (current.Type.Equals("Creature"))
            {
                card.transform.FindChild("Frame_creature").gameObject.SetActive(true);
                card.transform.FindChild("Frame_spell").gameObject.SetActive(false);
            }
            // Or create it using the spell prefab
            else
            {
                card.transform.FindChild("Frame_creature").gameObject.SetActive(false);
                card.transform.FindChild("Frame_spell").gameObject.SetActive(true);
            }
            //quick reference card's script component
            Card cardsScript = card.GetComponent <Card>();
            switch (i)
            { //TODO: Finish conversions
            case 1:
                card.transform.SetParent(slot1.transform.parent);
                card.transform.position = new Vector3(slot1.transform.position.x, slot1.transform.position.y + 6, slot1.transform.position.z);
                break;

            case 2:
                card.transform.SetParent(slot2.transform.parent);
                card.transform.position = new Vector3(slot2.transform.position.x, slot2.transform.position.y + 6, slot2.transform.position.z);
                break;

            case 3:
                card.transform.SetParent(slot3.transform.parent);
                card.transform.position = new Vector3(slot3.transform.position.x, slot3.transform.position.y + 6, slot3.transform.position.z);
                break;

            case 4:
                card.transform.SetParent(slot4.transform.parent);
                card.transform.position = new Vector3(slot4.transform.position.x, slot4.transform.position.y + 6, slot4.transform.position.z);
                break;

            case 5:
                card.transform.SetParent(slot5.transform.parent);
                card.transform.position = new Vector3(slot5.transform.position.x, slot5.transform.position.y + 6, slot5.transform.position.z);
                break;

            case 6:
                card.transform.SetParent(slot6.transform.parent);
                card.transform.position = new Vector3(slot6.transform.position.x, slot6.transform.position.y + 6, slot6.transform.position.z);
                break;

            case 7:
                card.transform.SetParent(slot7.transform.parent);
                card.transform.position = new Vector3(slot7.transform.position.x, slot7.transform.position.y + 6, slot7.transform.position.z);
                break;

            case 8:
                card.transform.SetParent(slot8.transform.parent);
                card.transform.position = new Vector3(slot8.transform.position.x, slot8.transform.position.y + 6, slot8.transform.position.z);
                break;

            case 9:
                card.transform.SetParent(slot9.transform.parent);
                card.transform.position = new Vector3(slot9.transform.position.x, slot9.transform.position.y + 6, slot9.transform.position.z);
                break;

            case 10:
                card.transform.SetParent(slot10.transform.parent);
                card.transform.position = new Vector3(slot10.transform.position.x, slot10.transform.position.y + 6, slot10.transform.position.z);
                break;
            }

            // Initialize the card's current values
            current.SetCurrents();

            // Set the card's name
            card.GetComponentInChildren <Text>().text = current.CardName;

            //TODO: set all values of script to those of current, or just set equal to that of current
            cardsScript.CardName = current.CardName;
            card.name            = current.CardName;

            // Set all of the remaining information for the card
            Debug.Log("ID" + current.ID);
            cardsScript.ID          = current.ID;
            cardsScript.Image       = current.Image;
            cardsScript.Description = current.Description;
            cardsScript.Alliance    = current.Alliance;
            cardsScript.Cost        = current.Cost;
            cardsScript.Attack      = current.Attack;
            cardsScript.Health      = current.Health;
            cardsScript.Defense     = current.Defense;
            cardsScript.Range       = current.Range;
            cardsScript.OwnerTag    = "Player 1";
            cardsScript.EffectName  = current.EffectName;
            Debug.Log("ScriptID" + current.ID);

            card.transform.Find("Title").gameObject.GetComponent <Text>().text       = cardsScript.CardName;
            card.transform.Find("Description").gameObject.GetComponent <Text>().text = cardsScript.Description;
            //display Creature specific traits
            if (current.Type.Equals("Creature"))
            {
                card.transform.Find("Attack").gameObject.GetComponent <Text>().text  = cardsScript.Attack;
                card.transform.Find("Defense").gameObject.GetComponent <Text>().text = cardsScript.Defense;
                card.transform.Find("Health").gameObject.GetComponent <Text>().text  = cardsScript.Health;
                //Display M for range if Melee, R if ranged
                if (cardsScript.Range.Equals("Melee"))
                {
                    card.transform.Find("Range").gameObject.GetComponent <Text>().text = "M";
                }
                else if (cardsScript.Range.Equals("Ranged"))
                {
                    card.transform.Find("Range").gameObject.GetComponent <Text>().text = "R";
                }
                else
                {
                    card.transform.Find("Range").gameObject.GetComponent <Text>().text = "";
                }
            }
            else
            {
                card.transform.Find("Attack").gameObject.SetActive(false);
                card.transform.Find("Defense").gameObject.SetActive(false);
                card.transform.Find("Health").gameObject.SetActive(false);
                card.transform.Find("Range").gameObject.SetActive(false);
            }
            card.transform.Find("Cost").gameObject.GetComponent <Text>().text = cardsScript.Cost;
        }
    }
    private void populate(int direction)
    {
        //populate page with 10 cards from those viable for current player's build
        //load database array from path using Reader
        Debug.Log("Entering Database Initialization Loop");
        if (!loadedDatabase)
        {
            Path = Application.dataPath + "/scripts/xml/database.xml";
                Book = new CardBook(Path);
                loadedDatabase = true;
                //TODO: Sort Database Deck by cost and lettering
        }
        Debug.Log("Exited Database Initialization Loop");
        //database loaded, proceed with book compilation
        Card current;
        Book.ChangeCurrentPage(direction);
        //add Cards of new CurrentPage to Displayed Cards
        Debug.Log("Entered GetCardsOfPage");
        DisplayedCards = Book.GetCardsOfPage(Book.CurrentPage);
        Debug.LogError("After page shift, first displayed is " + DisplayedCards[0].CardName);
        //instantiate the objects/visual representation
        for (int i = 1; i <= 10; i++)
        {
            Debug.Log("Entered DisplayLoop");
            GameObject card;
            //If there is another card to display (has next)
                current = DisplayedCards[i-1];
                // Create the card with creature prefab
                card = (GameObject)Instantiate(displayedCardPrefab, slot1.transform.position, slot1.transform.rotation);
                card.transform.FindChild("Splash").gameObject.GetComponent<Image>().sprite = spriteSheet[UnityEngine.Random.Range(0, 8)]; //TODO: nonrandom sprites
                if (current.Type.Equals("Creature"))
                {
                    card.transform.FindChild("Frame_creature").gameObject.SetActive(true);
                    card.transform.FindChild("Frame_spell").gameObject.SetActive(false);
                }
                // Or create it using the spell prefab
                else
                {
                    card.transform.FindChild("Frame_creature").gameObject.SetActive(false);
                    card.transform.FindChild("Frame_spell").gameObject.SetActive(true);
                }
                //quick reference card's script component
                Card cardsScript = card.GetComponent<Card>();
            switch (i)
            { //TODO: Finish conversions

                case 1:
                    card.transform.SetParent(slot1.transform.parent);
                    card.transform.position = new Vector3(slot1.transform.position.x, slot1.transform.position.y + 6, slot1.transform.position.z);
                    break;
                case 2:
                    card.transform.SetParent(slot2.transform.parent);
                    card.transform.position = new Vector3(slot2.transform.position.x, slot2.transform.position.y + 6, slot2.transform.position.z);
                    break;
                case 3:
                    card.transform.SetParent(slot3.transform.parent);
                    card.transform.position = new Vector3(slot3.transform.position.x, slot3.transform.position.y + 6, slot3.transform.position.z);
                    break;
                case 4:
                    card.transform.SetParent(slot4.transform.parent);
                    card.transform.position = new Vector3(slot4.transform.position.x, slot4.transform.position.y + 6, slot4.transform.position.z);
                    break;
                case 5:
                    card.transform.SetParent(slot5.transform.parent);
                    card.transform.position = new Vector3(slot5.transform.position.x, slot5.transform.position.y + 6, slot5.transform.position.z);
                    break;
                case 6:
                    card.transform.SetParent(slot6.transform.parent);
                    card.transform.position = new Vector3(slot6.transform.position.x, slot6.transform.position.y + 6, slot6.transform.position.z);
                    break;
                case 7:
                    card.transform.SetParent(slot7.transform.parent);
                    card.transform.position = new Vector3(slot7.transform.position.x, slot7.transform.position.y + 6, slot7.transform.position.z);
                    break;
                case 8:
                    card.transform.SetParent(slot8.transform.parent);
                    card.transform.position = new Vector3(slot8.transform.position.x, slot8.transform.position.y + 6, slot8.transform.position.z);
                    break;
                case 9:
                    card.transform.SetParent(slot9.transform.parent);
                    card.transform.position = new Vector3(slot9.transform.position.x, slot9.transform.position.y + 6, slot9.transform.position.z);
                    break;
                case 10:
                    card.transform.SetParent(slot10.transform.parent);
                    card.transform.position = new Vector3(slot10.transform.position.x, slot10.transform.position.y + 6, slot10.transform.position.z);
                    break;
            }

                // Initialize the card's current values
                current.SetCurrents();

                // Set the card's name
                card.GetComponentInChildren<Text>().text = current.CardName;

                //TODO: set all values of script to those of current, or just set equal to that of current
                cardsScript.CardName = current.CardName;
                card.name = current.CardName;

                // Set all of the remaining information for the card
                Debug.Log("ID" + current.ID);
                cardsScript.ID = current.ID;
                cardsScript.Image = current.Image;
                cardsScript.Description = current.Description;
                cardsScript.Alliance = current.Alliance;
                cardsScript.Cost = current.Cost;
                cardsScript.Attack = current.Attack;
                cardsScript.Health = current.Health;
                cardsScript.Defense = current.Defense;
                cardsScript.Range = current.Range;
                cardsScript.OwnerTag = "Player 1";
                cardsScript.EffectName = current.EffectName;
                Debug.Log("ScriptID" + current.ID);

                card.transform.Find("Title").gameObject.GetComponent<Text>().text = cardsScript.CardName;
                card.transform.Find("Description").gameObject.GetComponent<Text>().text = cardsScript.Description;
                //display Creature specific traits
                if (current.Type.Equals("Creature"))
                {
                card.transform.Find("Attack").gameObject.GetComponent<Text>().text = cardsScript.Attack;
                card.transform.Find("Defense").gameObject.GetComponent<Text>().text = cardsScript.Defense;
                card.transform.Find("Health").gameObject.GetComponent<Text>().text = cardsScript.Health;
                //Display M for range if Melee, R if ranged
                    if (cardsScript.Range.Equals("Melee"))
                    {
                        card.transform.Find("Range").gameObject.GetComponent<Text>().text = "M";
                    }
                    else if (cardsScript.Range.Equals("Ranged"))
                    {
                        card.transform.Find("Range").gameObject.GetComponent<Text>().text = "R";
                    }
                    else
                    {
                        card.transform.Find("Range").gameObject.GetComponent<Text>().text = "";
                    }
                }
                else
                {
                    card.transform.Find("Attack").gameObject.SetActive(false);
                    card.transform.Find("Defense").gameObject.SetActive(false);
                    card.transform.Find("Health").gameObject.SetActive(false);
                    card.transform.Find("Range").gameObject.SetActive(false);
                }
                card.transform.Find("Cost").gameObject.GetComponent<Text>().text = cardsScript.Cost;
        }
    }