Exemplo n.º 1
0
    private Sprite GetZoneSprite(UnitCard.Sections section)
    {
        if (ZoneImages == null)
        {
            ZoneImages = Resources.LoadAll <Sprite>("Images/zone");
        }

        if (section == UnitCard.Sections.Melee)
        {
            return(ZoneImages[0]);
        }
        else if (section == UnitCard.Sections.Ranged)
        {
            return(ZoneImages[1]);
        }
        else if (section == UnitCard.Sections.Siege)
        {
            return(ZoneImages[2]);
        }
        else if (section == UnitCard.Sections.Agile)
        {
            return(ZoneImages[3]);
        }
        else
        {
            return(null);
        }
    }
Exemplo n.º 2
0
    public static List <GameObject> ParseText(string text)
    {
        List <GameObject> factions = new List <GameObject>();
        //Match m = Regex.Match(text, @"(faction)\s*(=)\s*({)(?s).*");
        string factionName        = null;
        bool   factionExclusivity = false;


        List <Card> cardList = new List <Card>();


        List <Match> regexMatches = new List <Match>();// = Regex.Matches(text, @"(faction)\s*(=)\s*({)(?s).*");
        string       regexInput   = text;

        //match:    'faction' + (0+ spaces) + '=' + (0+ spaces) + '{' +
        //          (everything until the end of file)
        Match ma = Regex.Match(regexInput, @"(faction)\s*=\s*{(?'data'[\s|\S]*)");

        while (ma.Success)
        {
            if (!regexMatches.Contains(ma))
            {
                regexMatches.Add(ma);
                ma = Regex.Match(ma.Groups["data"].Value, @"(faction)\s*=\s*{(?'data'[\s|\S]*)");
            }
        }
        foreach (Match factionMatch in regexMatches)
        {
            List <string> matches = new List <string>();
            //matches.Add(m.Value);
            int   OpenBracketCount  = 0;
            int   CloseBracketCount = 0;
            Match factionValues     = Regex.Match(factionMatch.Value, @"{([^{]+){");

            #region Get faction Name & Exclusivity

            factionName = GetStringProperty("Name", factionValues.Value);
            if (factionValues == null)
            {
                throw new GwantExceptions.MissingFactionName();
            }
            factionExclusivity = GetBoolProperty("Exclusive", factionValues.Value);

            #endregion

            #region Brackets
            for (int i = 0; i < factionMatch.Value.Length; i++)
            {
                char ch = factionMatch.Value[i];
                if (ch == '{')
                {
                    OpenBracketCount++;
                }
                else if (ch == '}')
                {
                    CloseBracketCount++;
                }

                if (OpenBracketCount == CloseBracketCount && OpenBracketCount > 1)
                {
                    matches.Add(factionMatch.Value.Substring(0, i));
                    break;
                }
            }

            #endregion

            foreach (string s in matches)
            {
                //List<GameObject> cardGameObjects = new List<GameObject>();

                #region Unit matches
                MatchCollection matchCollection = Regex.Matches(s, @"(unit)\s*=\s{[^{]+}");
                foreach (Match unitMatch in matchCollection)
                {
                    //get id
                    int id = GetIntProperty("ID", unitMatch.Value);
                    if (idList.Contains(id))
                    {
                        throw new GwantExceptions.DuplicateIDException(id);
                    }
                    else
                    {
                        idList.Add(id);
                    }

                    //get name
                    string name = GetStringProperty("Name", unitMatch.Value);

                    //get art
                    string art = GetStringProperty("Art", unitMatch.Value);
                    if (art == null)
                    {
                        art = name.Replace(" ", string.Empty);
                    }
                    //art = art.Replace(@"(\P{L})*", string.Empty);
                    //DO REGEX TO REPLACE INVALID FILE NAME CHARACTERS
                    art = art.Replace(":", "").Replace("'", "");
                    art = "art/" + art.ToLower() + ".jpg";

                    //get strength
                    int strength = GetIntProperty("Strength", unitMatch.Value);
                    if (strength == DEFAULT_INT_VALUE)
                    {
                        throw new GwantExceptions.InvalidStrengthException(id);
                    }

                    //get hero
                    bool hero = GetBoolProperty("Hero", unitMatch.Value); //invalid result defaults to false


                    //get ability
                    Enum           ab      = GetEnumProperty(EnumProperties.Ability, unitMatch.Value);
                    Card.Abilities ability = (ab != null) ? (Card.Abilities)ab : Card.Abilities.None;

                    //get section
                    UnitCard.Sections section = (UnitCard.Sections)GetEnumProperty(EnumProperties.Section, unitMatch.Value);


                    //if ability = muster
                    //get muster name
                    string muster = (ability == Card.Abilities.Muster) ? GetStringProperty("Muster", unitMatch.Value) : null;
                    if (muster == null && ability == Card.Abilities.Muster)
                    {
                        muster = name;
                    }

                    //if ability = scorch
                    //get scorch threshold
                    int scorch = INACTIVE_INT;
                    if (ability == Card.Abilities.Scorch)
                    {
                        scorch = GetIntProperty("Scorch", unitMatch.Value);
                        scorch = (scorch == DEFAULT_INT_VALUE) ? 10 : scorch;
                    }

                    //if ability = avenger
                    //get avenger id
                    int avenger = INACTIVE_INT;
                    if (ability == Card.Abilities.Avenger)
                    {
                        avenger = GetIntProperty("Avenger", unitMatch.Value);
                        if (avenger == DEFAULT_INT_VALUE)
                        {
                            throw new GwantExceptions.InvalidAvengerException(id);
                        }
                    }

                    //get count
                    int count = GetIntProperty("Count", unitMatch.Value);
                    count = (count == DEFAULT_INT_VALUE) ? 1 : count;

                    //Create the cards
                    for (int i = 0; i < count; i++)
                    {
                        /*
                         * GameObject go = new GameObject();
                         * UnitCard.AddComponentTo(go, id, name, art, section, strength, hero, ability, avenger, muster, scorch);
                         * go.name = name;
                         * cardGameObjects.Add(go);
                         */
                        //GameObject go = new GameObject();
                        UnitCard c = new UnitCard(id, name, art, section, strength, hero, ability, avenger, muster, scorch);
                        cardList.Add(c);
                    }
                }
                #endregion

                #region Special matches
                matchCollection = Regex.Matches(s, @"(special)\s*=\s{[^{]+}");
                foreach (Match specialMatch in matchCollection)
                {
                    //get id
                    int id = GetIntProperty("ID", specialMatch.Value);
                    if (idList.Contains(id))
                    {
                        throw new GwantExceptions.DuplicateIDException(id);
                    }
                    else
                    {
                        idList.Add(id);
                    }

                    //get name
                    string name = GetStringProperty("Name", specialMatch.Value);

                    //get art
                    string art = GetStringProperty("Art", specialMatch.Value);
                    if (art == null)
                    {
                        art = name.Replace(" ", string.Empty);
                    }
                    art = "art/" + art.ToLower() + ".jpg";


                    //get ability
                    Enum           ab      = GetEnumProperty(EnumProperties.Ability, specialMatch.Value);
                    Card.Abilities ability = (ab != null) ? (Card.Abilities)ab : Card.Abilities.None;

                    //get weather type
                    SpecialCard.WeatherTypes weatherType;
                    if (ability == Card.Abilities.Weather)
                    {
                        Enum w = GetEnumProperty(EnumProperties.Ability, specialMatch.Value);
                        weatherType = (w != null) ? (SpecialCard.WeatherTypes)w :
                                      SpecialCard.WeatherTypes.None;
                    }
                    else
                    {
                        weatherType = SpecialCard.WeatherTypes.None;
                    }


                    //get count
                    int count = GetIntProperty("Count", specialMatch.Value);
                    count = (count == DEFAULT_INT_VALUE) ? 1 : count;

                    //Create the cards
                    for (int i = 0; i < count; i++)
                    {
                        /*
                         * GameObject go = new GameObject();
                         * SpecialCard.AddComponentTo(go, id, name, art, ability, weatherType);
                         * go.name = name;
                         * cardGameObjects.Add(go);
                         */
                        SpecialCard c = new SpecialCard(id, name, art, ability, weatherType);
                        cardList.Add(c);
                    }
                }
                #endregion

                //List<Card> cardList = new List<Card>();
                //foreach (GameObject go in cardGameObjects)
                //{
                //cardList.Add(go.GetComponent<Card>());
                //}
                //GameObject go = Faction.CreateFaction(factionName, cardList, factionExclusivity);
                factions.Add(Faction.CreateFaction(factionName, cardList, factionExclusivity));
                //factions.Add(go.GetComponent<Faction>());
                //factions.Add(new Faction(factionName, cardList, factionExclusivity));
            }
        }
        //strings = matches;


        //string name = "";

        //strings = matches;
        //strings.Add(name);
        //return cards;
        return(factions);
    }