예제 #1
0
 /// <summary>
 /// Gets a generic type class instance given a certain MTA element
 /// </summary>
 public T GetElement <T>(MtaElement element) where T : Element
 {
     if (element == null)
     {
         return(null);
     }
     if (!MtaShared.IsElement(element))
     {
         return(null);
     }
     if (!elements.ContainsKey(element))
     {
         string mtaElementType = MtaShared.GetElementType(element);
         Type   elementType;
         try
         {
             elementType = defaultElementTypes[mtaElementType];
         } catch (KeyNotFoundException)
         {
             elementType = typeof(Element);
         }
         try
         {
             object instance = Activator.CreateInstance(elementType, element);
             return((T)instance);
         } catch (Exception)
         {
             return(null);
         }
     }
     return((T)elements[element]);
 }
예제 #2
0
 /// <summary>
 /// Gets an element class instance given a certain MTA element
 /// </summary>
 public Element GetElement(MtaElement element)
 {
     if (element == null)
     {
         return(null);
     }
     if (!MtaShared.IsElement(element))
     {
         return(null);
     }
     if (!elements.ContainsKey(element))
     {
         try
         {
             string  mtaElementType = MtaShared.GetElementType(element);
             Element wrapperElement = elementHelper.InstantiateElement(mtaElementType, element);
             return(wrapperElement);
         }
         catch (Exception)
         {
             return(null);
         }
     }
     return(elements[element]);
 }
예제 #3
0
        /// <summary>
        /// Creates the ElementManager given an IElementHelper class that maps MTA elements to classes
        /// </summary>
        public ElementManager(IElementHelper helper)
        {
            elementHelper = helper;
            instance      = this;
            elements      = new Dictionary <object, Element>();
            MtaElement mtaRoot = MtaShared.GetRootElement();

            root = elementHelper.InstantiateElement(MtaShared.GetElementType(mtaRoot), mtaRoot);
        }
예제 #4
0
 private void CommandHandlerCallback(MtaElement element, string command, string[] parameters)
 {
     if (MtaShared.GetElementType(element) == "console")
     {
         this.consoleCallback?.Invoke(command, parameters);
     }
     else
     {
         this.callback?.Invoke(element == null ? null : (Player)ElementManager.Instance.GetElement(element), command, parameters);
     }
 }