예제 #1
0
        public static void ParseModuleData(CardData CurrentCardData, XmlReader xmlReader,
                                           bool isInAction, ref BehaviourData PreviousBehaviourData, ref BehaviourData CurrentBehaviourData)
        {
            // Module data: name, type, potentially lifetime, attributes after these are custom data.
            ModuleData moduleData  = new ModuleData(xmlReader["name"], xmlReader["type"]);
            int        startOfData = 2;

            if (xmlReader["lifetime"] != null)
            {
                startOfData = 3;
                bool result = int.TryParse(xmlReader["lifetime"], out moduleData.mLifetime);
                UnityEngine.Debug.Assert(result);
            }
            for (int i = startOfData; i < xmlReader.AttributeCount; i++)
            {
                moduleData.AddData(xmlReader[i]);
            }

            // Keep track of the previous behaviour since we can have nested behaviours (a module in an action)
            // and may want to be able to add other modules etc once we have finished with this module
            PreviousBehaviourData = CurrentBehaviourData;
            CurrentBehaviourData  = moduleData;

            // Modules inside action elements in the xml are added to them.
            if (isInAction)
            {
                ((ActionData)PreviousBehaviourData).AddModule(moduleData);
            }
            else
            {
                CurrentCardData.AddModule(moduleData);
            }
        }
예제 #2
0
        public static void ParseActionData(CardData CurrentCardData, XmlReader xmlReader,
                                           ref BehaviourData PreviousBehaviourData, ref BehaviourData CurrentBehaviourData)
        {
            bool hasCertainCost;
            int  minCost;
            bool isPlacedAction;

            // Action data: name, potentially displayname, placed, selecttype, min, max, hascertaincost, mincost
            // attributes after these are custom data

            bool.TryParse(xmlReader["hascertaincost"], out hasCertainCost);
            int.TryParse(xmlReader["mincost"], out minCost);
            bool.TryParse(xmlReader["placed"], out isPlacedAction);

            ActionData actionData = new ActionData(hasCertainCost, minCost, xmlReader["name"],
                                                   isPlacedAction, xmlReader["selecttype"], xmlReader["min"], xmlReader["max"]);

            int customDataStart = 7;

            if (xmlReader["displayname"] != null)
            {
                customDataStart         = 8;
                actionData.mDisplayName = xmlReader["displayname"];
            }

            if (xmlReader.AttributeCount > customDataStart)
            {
                List <string> customData = new List <string>();
                for (int i = customDataStart; i < xmlReader.AttributeCount; i++)
                {
                    customData.Add(xmlReader[i]);
                }
                actionData.mCustomData = customData;
            }

            CurrentBehaviourData = actionData;
            CurrentCardData.AddAction(actionData);
        }
예제 #3
0
        public static void LoadCardTypes(CardPool CP)
        {
            TextAsset CardTypesXML = Resources.Load("CardPool") as TextAsset;

            System.IO.StringReader CardTypesReader = new System.IO.StringReader(CardTypesXML.text);
            XmlReader xmlReader = XmlReader.Create(CardTypesReader);

            CardData      CurrentCardData       = null;
            bool          isInAction            = false;
            BehaviourData PreviousBehaviourData = null;
            BehaviourData CurrentBehaviourData  = null;

            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.Element)
                {
                    if (xmlReader.Name == "card")
                    {
                        switch (xmlReader["type"])
                        {
                        case "character":
                        case "basicunit":
                            ParseUnitData(ref CurrentCardData, xmlReader);
                            CP.Data.Add(CurrentCardData);
                            break;

                        case "effect":
                            ParseEffectData(ref CurrentCardData, xmlReader);
                            CP.Data.Add(CurrentCardData);
                            break;
                        }
                    }
                    else if (xmlReader.Name == "module")
                    {
                        ParseModuleData(CurrentCardData, xmlReader, isInAction,
                                        ref PreviousBehaviourData, ref CurrentBehaviourData);
                    }
                    else if (xmlReader.Name == "action")
                    {
                        isInAction = true;
                        ParseActionData(CurrentCardData, xmlReader,
                                        ref PreviousBehaviourData, ref CurrentBehaviourData);
                    }
                    // Info tags and conditionals use the first attribute to determine their type
                    // and then take only the second as a piece of custom data.
                    else if (xmlReader.Name == "infotag")
                    {
                        CurrentBehaviourData.AddInfoTag(new InfoTagData(xmlReader[0], xmlReader[1]));
                    }
                    else if (xmlReader.Name == "conditional")
                    {
                        CurrentBehaviourData.AddConditional(new ConditionalData(xmlReader[0], xmlReader[1]));
                    }
                }
                else if (xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    // No longer inside an action element
                    if (xmlReader.Name == "action")
                    {
                        isInAction = false;
                    }
                    // May have just ended a nested module so shuffle
                    // up the behaviour data.
                    else if (xmlReader.Name == "module")
                    {
                        CurrentBehaviourData = PreviousBehaviourData;
                    }
                }
            }
        }