Esempio n. 1
0
 public Type GetActionType(ActionIdentifier actionId)
 {
     if (!TryGetActionType(actionId, out var type))
     {
         throw new Exception("Unknown action");
     }
     return(type);
 }
Esempio n. 2
0
 public virtual void AddHandler(ActionIdentifier actionId, ActionEventHandler handler)
 {
     if (!Handlers.TryGetValue(actionId, out var handlersList))
     {
         handlersList = new List <ActionEventHandler>();
         Handlers.Add(actionId, handlersList);
     }
     handlersList.Add(handler);
 }
Esempio n. 3
0
 public void Register(Type type, ActionIdentifier actionId)
 {
     if (!IAction.IsAction(type))
     {
         return;
     }
     IAction.ActionRegistry = this;
     _actions[actionId]     = type;
 }
Esempio n. 4
0
 public void HandleAction(Session session, ActionIdentifier actionId, IAction action)
 {
     if (Handlers.TryGetValue(actionId, out var handlersList))
     {
         var eventArgs = new ActionEventArgs(actionId, action);
         foreach (var handler in handlersList)
         {
             handler?.Invoke(this, eventArgs);
         }
     }
 }
Esempio n. 5
0
        public bool TryGetAction(ActionIdentifier actionId, out IAction action)
        {
            if (TryGetActionType(actionId, out var type))
            {
                action = type.GetConstructor(_emptyTypes).Invoke(_emptyObjects) as IAction;
                return(true);
            }

            action = null;
            return(false);
        }
Esempio n. 6
0
        public static ActionIdentifier[] GetActionIdentifiers(Type type)
        {
            ValidateGameAction(type);
            var attributes = type.GetCustomAttributes(typeof(ActionIdentifier), false);

            if (ActionRegistry != null)
            {
                ActionIdentifier[] result = new ActionIdentifier[1];
                foreach (var att in (ActionIdentifier[])attributes)
                {
                    if (ActionRegistry.Contains(att))
                    {
                        result[0] = att;
                        return(result);
                    }
                }
            }
            return(attributes as ActionIdentifier[]);
        }
Esempio n. 7
0
 public virtual bool ContainsHandler(ActionIdentifier actionId)
 {
     return(Handlers.ContainsKey(actionId));
 }
Esempio n. 8
0
 public void Remove(ActionIdentifier actionId)
 {
     _actions.Remove(actionId);
 }
Esempio n. 9
0
 public bool Contains(ActionIdentifier actionId)
 {
     return(_actions.ContainsKey(actionId));
 }
Esempio n. 10
0
 public bool TryGetActionType(ActionIdentifier actionId, out Type type)
 {
     return(_actions.TryGetValue(actionId, out type));
 }
Esempio n. 11
0
 public IAction GetAction(ActionIdentifier actionId)
 {
     return(GetActionType(actionId).GetConstructor(_emptyTypes).Invoke(_emptyObjects) as IAction);
 }
Esempio n. 12
0
 public ActionEventArgs(ActionIdentifier actionId, IAction action)
 {
     ActionId = actionId;
     Action   = action;
 }