Example #1
0
        //------------------------------------------------------------



        //------------------------------------------------------------
        /// <summary>
        /// Loads the state machine.
        /// </summary>
        /// <param name="sm">Sm.</param>
        public void loadStateMachine(string sm)
        {
            states     = new List <State>();
            events     = new List <FSMEvent>();
            attributes = new List <Attribute>();
            //states|attributes|events
            string[] one = sm.Split('|');

            //states
            //name,id,event1:event2...;name,id,act1....
            string[] stateStrings = one[0].Split(';');    //states
            foreach (string s in stateStrings)
            {
                State newState = new State(s);
                states.Add(newState);
            }

            //attributes
            //name,val;name,val...
            definition = one[1];
            string[] attributeStrings = one[1].Split(';');    //attributes
            foreach (string a in attributeStrings)
            {
                if (a.Length > 0)
                {
                    Attribute newAttribute = new Attribute(a);
                    attributes.Add(newAttribute);
                }
            }


            //events
            //name,id,source,destination;name,id,source,dest...
            string[] eventStrings = one[2].Split(';');    //events
            foreach (string e in eventStrings)
            {
                if (e.Length > 0)
                {
                    FSMEvent newEvent = new FSMEvent(e, attributes);
                    events.Add(newEvent);
                }
            }

            //load events to states
            foreach (State theState in states)
            {
                foreach (int eventID in theState.events)
                {
                    FSMEvent e = getEvent(eventID);
                    if (e != null)
                    {
                        theState.eventBucket.Add(e);
                    }
                }
            }
            //load target state to event
            foreach (FSMEvent e in events)
            {
                e.toState = getState(e.toStateID);
            }
        }//------------------------------------------------------------