Ejemplo n.º 1
0
        bool EvaluateUserFriendliness(Dictionary <string, PlayerReference> players)
        {
            if (Status != MapStatus.Available || !Visibility.HasFlag(MapVisibility.Lobby))
            {
                return(false);
            }

            // Other map types may have confusing settings or gameplay
            if (!Categories.Contains("Conquest"))
            {
                return(false);
            }

            // Maps with bots disabled confuse new players
            if (players.Any(x => !x.Value.AllowBots))
            {
                return(false);
            }

            // Large maps expose unfortunate performance problems
            if (Bounds.Width > 128 || Bounds.Height > 128)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        protected override void PopulateObject()
        {
            TypeDescription typeDescription = null;
            object          targetObject;

            try
            {
                targetObject = TargetObjectGetter();
            }
            catch (Exception)
            {
                targetObject = null;
                // Items from property getters that throw exceptions are not added to the object hierarchy
                // Ignore silently
            }
            _targetObject = targetObject;
            if (targetObject != null)
            {
                WoopsaVisibilityAttribute woopsaVisibilityAttribute =
                    WoopsaReflection.GetCustomAttribute <WoopsaVisibilityAttribute>(targetObject.GetType());
                if (woopsaVisibilityAttribute != null)
                {
                    Visibility = woopsaVisibilityAttribute.Visibility;
                }
                else
                {
                    Visibility = DefaultVisibility;
                }
            }
            else
            {
                Visibility = DefaultVisibility;
            }
            Type exposedType;

            if (targetObject != null)
            {
                exposedType = ExposedType(targetObject);
            }
            else
            {
                exposedType = null;
            }
            OnTargetObjectChange(targetObject, exposedType);
            base.PopulateObject();
            if (targetObject != null)
            {
                typeDescription = GetTypeDescription(exposedType);
                PopulateProperties(targetObject, exposedType, typeDescription.Properties);
                PopulateMethods(targetObject, exposedType, typeDescription.Methods);
                PopulateItems(targetObject, exposedType, typeDescription.Items);
                if (targetObject is IEnumerable && Visibility.HasFlag(WoopsaVisibility.IEnumerableObject))
                {
                    IEnumerable enumerable = (IEnumerable)targetObject;
                    PopulateEnumerableItems(enumerable, DeclaredExposedType);
                }
            }
        }
        protected virtual void PopulateProperties(object targetObject, Type exposedType,
                                                  IEnumerable <PropertyDescription> properties)
        {
            HashSet <string> addedElements = new HashSet <string>();

            foreach (var property in properties)
            {
                if (IsMemberWoopsaVisible(targetObject, property.PropertyInfo))
                {
                    if (!addedElements.Contains(property.Name))
                    {
                        AddWoopsaProperty(property);
                        addedElements.Add(property.Name);
                    }
                }
            }
            if (typeof(IEnumerable <object>).IsAssignableFrom(exposedType) && Visibility.HasFlag(WoopsaVisibility.IEnumerableObject))
            {
                new WoopsaProperty(this, nameof(OrderedItemIds), WoopsaValueType.JsonData,
                                   (p) => WoopsaValue.WoopsaJsonData(OrderedItemIds));
            }
        }
        protected virtual bool IsMemberWoopsaVisible(object targetObject, MemberInfo memberInfo)
        {
            var  woopsaVisibleAttribute = WoopsaReflection.GetCustomAttribute <WoopsaVisibleAttribute>(memberInfo);
            bool isVisible;
            Type targetType = targetObject.GetType();

            if (woopsaVisibleAttribute != null)
            {
                isVisible = woopsaVisibleAttribute.Visible;
            }
            else
            {
                isVisible = Visibility.HasFlag(WoopsaVisibility.DefaultIsVisible);
            }
            if (isVisible)
            {
                if (memberInfo.DeclaringType != targetType)
                {
                    isVisible = Visibility.HasFlag(WoopsaVisibility.Inherited);
                }
            }
            if (isVisible)
            {
                if (memberInfo.DeclaringType == typeof(object))
                {
                    isVisible = Visibility.HasFlag(WoopsaVisibility.ObjectClassMembers);
                }
            }
            if (isVisible)
            {
                if (memberInfo.DeclaringType == typeof(ArrayList) ||
                    (memberInfo.DeclaringType.IsGenericType &&
                     (memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(List <>) ||
                      memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(Collection <>) ||
                      memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(ObservableCollection <>)))
                    )
                {
                    isVisible = Visibility.HasFlag(WoopsaVisibility.ListClassMembers);
                }
            }
            if (isVisible)
            {
                if (memberInfo is MethodBase)
                {
                    if ((memberInfo as MethodBase).IsSpecialName)
                    {
                        isVisible = Visibility.HasFlag(WoopsaVisibility.MethodSpecialName);
                    }
                }
            }
            if (isVisible)
            {
                if (memberInfo is PropertyInfo)
                {
                    PropertyInfo property = (PropertyInfo)memberInfo;
                    if (typeof(IEnumerable <object>).IsAssignableFrom(property.PropertyType))
                    {
                        isVisible = Visibility.HasFlag(WoopsaVisibility.IEnumerableObject);
                    }
                }
            }
            EventArgsMemberVisibilityCheck e = new EventArgsMemberVisibilityCheck(memberInfo);

            e.IsVisible = isVisible;
            OnMemberWoopsaVisibilityCheck(e);
            isVisible = e.IsVisible;
            return(isVisible);
        }
Ejemplo n.º 5
0
 private bool FlagIsPresentInBoth(Visibility visibility, Visibility otherVisibility, Visibility flag)
 {
     return (visibility.HasFlag(flag) && otherVisibility.HasFlag(flag));
 }
Ejemplo n.º 6
0
 private bool HasSameVisibility(Visibility visibility, Visibility memberVisibility)
 {
     return(this.VisibilityIs(visibility) && memberVisibility.HasFlag(visibility));
 }
Ejemplo n.º 7
0
 private bool FlagIsPresentInBoth(Visibility visibility, Visibility otherVisibility, Visibility flag)
 {
     return(visibility.HasFlag(flag) && otherVisibility.HasFlag(flag));
 }