Beispiel #1
0
 public void TriggerEvent(IGameEvent _gameEvent)
 {
     if (m_InternalDelegates.TryGetValue(_gameEvent.GetType(), out EventDelegate eventDelegate))
     {
         eventDelegate.Invoke(_gameEvent);
     }
     else
     {
         Debug.Log($"Event of type {_gameEvent.GetType()} fired, but no listeners were found !");
     }
 }
 public void TriggerEvent(IGameEvent e)
 {
     if (delegates.TryGetValue(e.GetType(), out EventDelegate del))
     {
         del.Invoke(e);
     }
     else
     {
         Debug.LogWarning("Event: " + e.GetType() + " has no listeners");
     }
 }
Beispiel #3
0
        private void EditGameEventProperties(IGameEvent gameEvent)
        {
            gameEvent.ClientUtcTime = DateTime.UtcNow;

            var props = gameEvent.GetType().GetProperties();

            foreach (var prop in props)
            {
                var propName = prop.Name;
                if (propName != "ClientUtcTime" && Program.PropertyCache.ContainsKey(propName))
                {
                    prop.SetValue(gameEvent, Program.PropertyCache[propName]);
                }
                var propValue = prop.GetValue(gameEvent);

                if (propName == "Type" || propName == "Version")
                {
                    // Don't ask for input for these properties, just display their
                    // values since they are static and can't be changed
                    Console.WriteLine($"{propName}: {propValue}");
                }
                else
                {
                    var propertyType = prop.PropertyType;
                    var o            = EditProperty(propName, propValue, propertyType);
                    prop.SetValue(gameEvent, o);
                    Program.PropertyCache[propName] = o;
                }
            }
        }
Beispiel #4
0
        public void Broadcast(IGameEvent eventArgs)
        {
            var eventType = eventArgs.GetType();

            if (_eventHandlers.ContainsKey(eventType))
            {
                var subscribers = _eventHandlers[eventType];
                foreach (var subscriber in subscribers)
                {
                    try
                    {
                        subscriber.Invoke(eventArgs);
                    }
                    catch (Exception e)
                    {
                        var actualException = e.InnerException;
                        Logging.Instance.Log(LogLevel.Error,
                                             "An exception has been thrown by an EventBus handler.\n " + actualException.Message + "\n" +
                                             actualException.StackTrace);
                    }
                }
            }
            else
            {
                Console.WriteLine("There are no subscribers for event of type : " + eventType.Name);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Raises the specified event - Resolves the event type at runtime (uses reflection)
        /// </summary>
        public static void DynamicRaise(IGameEvent e)
        {
            var type    = typeof(EventManagerInternal <>);
            var genType = type.MakeGenericType(e.GetType());
            var raise   = genType.GetMethod("Raise", BindingFlags.Public | BindingFlags.Static);

            raise.Invoke(null, new object[] { e });
        }
        private void EditGameEventProperties(IGameEvent gameEvent)
        {
            gameEvent.ClientUtcTime = DateTime.UtcNow;

            foreach (var prop in gameEvent.GetType().GetProperties())
            {
                var propName = prop.Name;
                if (propName != "ClientUtcTime" && Program.PropertyCache.ContainsKey(propName))
                {
                    prop.SetValue(gameEvent, Program.PropertyCache[propName]);
                }
                var propValue = prop.GetValue(gameEvent);

                if (propName == "Type" || propName == "Version")
                {
                    // Don't ask for input for these properties, just display their
                    // values since they are static and can't be changed
                    Console.WriteLine($"{propName}: {propValue}");
                }
                else
                {
                    var propertyType = prop.PropertyType;
                    var o            = EditProperty(propName, propValue, propertyType);
                    prop.SetValue(gameEvent, o);
                    Program.PropertyCache[propName] = o;

                    //Console.Write($"{propName} [{propValue}]:");
                    //var answer = Console.ReadLine();
                    //if (!string.IsNullOrWhiteSpace(answer))
                    //{
                    //    if (prop.PropertyType == typeof(int))
                    //    {
                    //        int i = int.Parse(answer);
                    //        prop.SetValue(gameEvent, i);
                    //        Program.PropertyCache[propName] = i;
                    //    }
                    //    else if (prop.PropertyType == typeof(long))
                    //    {
                    //        long l = long.Parse(answer);
                    //        prop.SetValue(gameEvent, l);
                    //        Program.PropertyCache[propName] = l;
                    //    }
                    //    else if (prop.PropertyType == typeof(DateTime))
                    //    {
                    //        DateTime dt = DateTime.Parse(answer);
                    //        prop.SetValue(gameEvent, dt);
                    //        Program.PropertyCache[propName] = dt;
                    //    }
                    //    else
                    //    {
                    //        // If nothing else, use string directly
                    //        prop.SetValue(gameEvent, answer);
                    //        Program.PropertyCache[propName] = answer;
                    //    }
                    //}
                }
            }
        }
Beispiel #7
0
    /// <summary>
    /// Inserts the event into the current queue.
    /// </summary>
    /// <param name="@event"></param>
    /// <returns></returns>
    public bool QueueEvent(IGameEvent @event)
    {
        if (!_delegates.ContainsKey(@event.GetType()))
        {
            //Debug.LogWarning("EventManager: QueueEvent failed due to no listeners for event: " + @event.GetType());
            return(false);
        }

        _eventQueue.Enqueue(@event);
        return(true);
    }
 public void Raise(IGameEvent e)
 {
     if (!IsLocked)
     {
         EventDelegate del;
         if (delegates.TryGetValue(e.GetType(), out del))
         {
             del.Invoke(e);
         }
     }
 }
Beispiel #9
0
    public void TriggerEventImmediate(IGameEvent gameEventArgs)
    {
        Type eventType = gameEventArgs.GetType();

        if (_eventListeners.ContainsKey(eventType))
        {
            for (int i = 0; i < _eventListeners[eventType].Count; i++)
            {
                _eventListeners[eventType][i].Action.Invoke(gameEventArgs);
            }
        }
    }
Beispiel #10
0
    public void SendEvent(IGameEvent e)
    {
        EventDelegate del;

        if (delegates.TryGetValue(e.GetType(), out del))
        {
            // remove listeners which should only be called once
            foreach (EventDelegate k in delegates[e.GetType()].GetInvocationList())
            {
                k.Invoke(e);

                if (onceLookups.ContainsKey(k))
                {
                    delegates[e.GetType()] -= k;

                    if (delegates[e.GetType()] == null)
                    {
                        delegates.Remove(e.GetType());
                    }

                    delegateLookup.Remove(onceLookups[k]);
                    onceLookups.Remove(k);
                }
            }
        }
        else
        {
            Debug.LogWarning("Event: " + e.GetType() + " has no listeners");
        }
    }
Beispiel #11
0
    /// <summary>
    /// Tell anyone who gives a shit that this happened
    /// </summary>
    public static void broadcastEvent(IGameEvent game_event)
    {
        Type type = game_event.GetType();

        if (handlerMap.ContainsKey(type))
        {
            // Foreach handler associated with this event type, handle this event
            handlerMap[type].ForEach(
                delegate(IEventHandler event_handler)
                { event_handler.handleEvent(game_event); }
                );
        }
    }
Beispiel #12
0
    public void TriggerEventImmediate(IGameEvent gameEventArgs)
    {
        _eventTypeStorage = gameEventArgs.GetType();

        if (_eventListeners.ContainsKey(_eventTypeStorage))
        {
            for (int i = 0; i < _eventListeners[_eventTypeStorage].Count; i++)
            {
                _eventListeners[_eventTypeStorage][i].Action.Invoke(gameEventArgs);
            }
        }

        _eventsLeftToTrigger--;
    }
Beispiel #13
0
        /// <summary>
        /// Causes an event to fire, causing any listening delegates to be run.
        /// </summary>
        /// <param name="evt">The event to fire. This is passed on to the delegates, so this is how to pass information to the delegates.</param>
        public static void FireEvent(IGameEvent evt)
        {
            var evtType = evt.GetType();

            if (eventMap.ContainsKey(evtType))
            {
                eventMap[evtType].DynamicInvoke(evt);
            }
#if SHIKI_DEBUG
            else
            {
                Debug.LogError(String.Format("Event {} fired with no listeners!", evtType));
            }
#endif
        }
Beispiel #14
0
        public static void DispatchEvent(IGameEvent gameEvent)
        {
            Type type = gameEvent.GetType();

            if (!events.ContainsKey(type) || events[type] == null)
            {
                return;
            }

            HashSet <IInvoker> invokeList = events[type];

            foreach (var invoke in invokeList)
            {
                invoke.Invoke(gameEvent);
            }
        }
Beispiel #15
0
    /// <summary>
    /// Trigger events are sent to
    /// its listeners immediately.
    /// NOTE: This should be used
    /// sparingly, as it can result
    /// in FPS drops if a lot of events are triggered
    /// at once.
    /// </summary>
    /// <param name="event"></param>
    /// <param name="_timeToWaitBeforeCallback">an optional parameter, should the event wait some time before we invoke it?s</param>
    public void TriggerEvent(IGameEvent @event, float _timeToWaitBeforeCallback = 0)
    {
        EventDelegate @delegate;

        //We need to check to see if the event has any listeners before proceeding.
        if (_delegates.TryGetValue(@event.GetType(), out @delegate))
        {
            @delegate.Invoke(@event);

            //should we print out the event that happened to the log?
            if (this._debug)
            {
                Debug.Log("Event :\t" + @event + " " + Time.deltaTime);
            }

            if (_delegates.ContainsKey(@event.GetType()))
            {
                // remove listeners which should only be called once
                foreach (EventDelegate key in _delegates[@event.GetType()].GetInvocationList())
                {
                    if (_onceLookups.ContainsKey(key))
                    {
                        _delegates[@event.GetType()] -= key;

                        if (_delegates[@event.GetType()] == null)
                        {
                            _delegates.Remove(@event.GetType());
                        }

                        _delegateLookup.Remove(_onceLookups[key]);
                        _onceLookups.Remove(key);
                    }
                }
            }
        }

        //we couldnt find listeners for this event
        else
        {
            Debug.LogWarning("Event: " + @event.GetType() + " has no listeners");
        }
    }
 public void OnGame(IGameEvent e)
 {
     _logger.LogInformation(e.GetType().Name + " triggered");
 }
Beispiel #17
0
 public void OnGame(IGameEvent e)
 {
     Console.WriteLine(e.GetType().Name + " triggered");
 }