コード例 #1
0
ファイル: PostOffice.cs プロジェクト: kaldhu/MyGameEngine
 public Object[] GetMessageObjects(Constant.enumModuleID moduleID, Constant.enumMessage[] msgIDArray)
 {
     IMessage[] result = m_LetterBoxes[moduleID].Where(msg => msgIDArray.Contains(msg.m_MsgType.m_MsgTypeID)).ToArray();
     m_LetterBoxes[moduleID] = m_LetterBoxes[moduleID].Except(result).ToList();
     return result.Select(msg => msg.m_Data).ToArray();
 }
コード例 #2
0
ファイル: PostOffice.cs プロジェクト: kaldhu/MyGameEngine
 public IMessage[] GetMessages(Constant.enumModuleID moduleID, Constant.enumMessage[] msgIDList = null, Boolean? command = null)
 {
     if (!command.HasValue)
     {
         return m_LetterBoxes[moduleID].Where(msg => msgIDList.Contains(msg.m_MsgType.m_MsgTypeID)).ToArray();
     }
     else
     {
         return m_LetterBoxes[moduleID].Where(msg => msgIDList.Contains(msg.m_MsgType.m_MsgTypeID) &&
                                                                                     (command.HasValue ? msg.m_MsgType.m_Command
                                                                                                      : !msg.m_MsgType.m_Command)).ToArray();
     }
 }
コード例 #3
0
ファイル: PostOffice.cs プロジェクト: kaldhu/MyGameEngine
        //TODO find a way to pass a data object containing different data types in one object[] so they can be picked up by helper method currently have to create multiple msgs and send them using
        //SendMessages(IMessage[] msgArray)
        /*
        public void SendMessage(Constant.enumMessage msgTypeID, Boolean command = true, Object[] data =null, Boolean split = false)
        {
            List<Object> typeList = new List<Object>();
            if (data != null)
            {

                if (split)
                {
                    foreach (Object obj in data)
                    {
                        if (!typeList.Any(o => o.GetType() == obj.GetType()))
                        {
                            Object[] objArray = data.Where(o => o.GetType() == obj.GetType()).ToArray();
                            foreach (Object o in objArray)
                            {
                                IMessage msgSplit = new Message(msgTypeID, false,o);
                                m_POBox.Add(msgSplit);
                            }
                            typeList.Add(obj);
                        }
                    }
                }
                else
                {
                    IMessage msg = new Message(msgTypeID, false, data);
                    m_POBox.Add(msg);
                }
            }
            if (command)
            {
                IMessage msg2 = new Message(msgTypeID, true, null);
                m_POBox.Add(msg2);
            }
            if (data == null && !command)
            {
                throw new ApplicationException();
            }
            m_Observer.Notify(true);
            m_POBox.Clear();
            if (command)
                m_Observer.Notify(false);
        }
        */
        //TODO make this generic so data is stored as an array of T and is passed, it is possible to force the game developer to define all data as an array before being passed so uses the
        //sendmessage(Constant.enumMessage msgTypeID, Boolean command = true, Object[] data = null) which bypasses all issues but i believe to be unclean
        /// <summary>
        /// NOTICE: this doesnt work correctly needs Type of data to be passed or will be converted to object[] meaning GetObjectArrayOf can not find by datas actual type
        /// </summary>
        /*
        public void SendMessage(Constant.enumMessage msgTypeID, Boolean command, Object data)
        {
            if (command)
            {
                IMessage msg2 = new Message(msgTypeID, true, null);
                m_POBox.Add(msg2);
            }
            if (data != null)
            {
                IMessage msg = new Message(msgTypeID, false, data);
                m_POBox.Add(msg);
            }
            if (data == null && !command)
            {
                throw new ApplicationException();
            }
            m_Observer.Notify(true);
            m_POBox.Clear();
            if (command)
            m_Observer.Notify(false);
        }
        */
        public void CheckMessages(Constant.enumModuleID moduleID, Constant.enumMessage[] msgIDList)
        {
            m_LetterBoxes[moduleID].AddRange(m_POBox.Where(x => msgIDList.Contains(x.m_MsgType.m_MsgTypeID)).ToArray());
        }