Exemplo n.º 1
0
        public static void HideAll(System.Predicate <WindowBase> predicate, TransitionParameters parameters = default)
        {
            var currentList   = WindowSystem.instance.currentWindows;
            var count         = currentList.Count;
            var filteredCount = 0;

            for (int i = 0; i < count; ++i)
            {
                var instance = currentList[i].instance;
                if (predicate == null || predicate.Invoke(instance) == true)
                {
                    ++filteredCount;
                }
            }

            var ptr = 0;
            var instanceParameters = parameters.ReplaceCallback(() => {
                ++ptr;
                if (ptr == filteredCount)
                {
                    parameters.RaiseCallback();
                }
            });

            for (int i = 0; i < count; ++i)
            {
                var instance = currentList[i].instance;
                if (predicate == null || predicate.Invoke(instance) == true)
                {
                    instance.Hide(instanceParameters);
                }
            }
        }
Exemplo n.º 2
0
        public static void DestroyIf(GStylizedTerrain terrain, System.Predicate <GameObject> condition)
        {
            List <Transform> parents = new List <Transform>();

            foreach (Transform t in terrain.transform)
            {
                if (t.name.StartsWith("~Root"))
                {
                    parents.Add(t);
                }
            }

            for (int i = 0; i < parents.Count; ++i)
            {
                GameObject[] children = GUtilities.GetChildrenGameObjects(parents[i]);
                for (int j = 0; j < children.Length; ++j)
                {
                    if (condition.Invoke(children[j]))
                    {
#if UNITY_EDITOR
                        Undo.DestroyObjectImmediate(children[j]);
#else
                        GUtilities.DestroyGameobject(children[j]);
#endif
                    }
                }
            }
        }
        public static int Count <T>(this System.Collections.Generic.IEnumerable <T> e, System.Predicate <T> m = null)
        {
            if (e.IsNull())
            {
                throw new System.NullReferenceException();
            }
            var result = 0;
            var list   = new System.Collections.Generic.List <T>(e);

            if (m.IsNull())
            {
                result = list.Count;
            }
            else
            {
                for (var i = 0; i < list.Count; i++)
                {
                    if (m.Invoke(list[i]))
                    {
                        result++;
                    }
                }
            }
            list.Clear();
            return(result);
        }
Exemplo n.º 4
0
        ///// <summary>
        ///// 当集合中不存在指定的对象时,将对象添加到集合的结尾处。
        ///// </summary>
        ///// <param name="item">待添加对象。</param>
        ///// <returns>添加成功返回 true;否则返回 false。</returns>
        ///// <remarks>
        ///// 此方法在执行时,首先在集合中查找与待添加对象匹配的元素,如果已经存在则结束过程(对于已经存在的情况认为添加成功,返回 true),否则执行添加操作。
        ///// </remarks>
        //public bool AddOnly(Task<T> item)
        //{
        //    this.datasRWLock.AcquireWriterLock(System.Threading.Timeout.Infinite);
        //    try
        //    {
        //        bool r = this.datas.ContainsValue(item.RunTime, item);
        //        if (r)
        //        {
        //            return true;
        //        }
        //        if ((this.MaxSize == -1 || this.datas.Count < MaxSize))
        //        {
        //            item.OwnerSortedTaskQueue = this;
        //            this.datas.Add(item.RunTime, item);
        //            Event.Set();
        //            return true;
        //        }
        //    }
        //    finally
        //    {
        //        this.datasRWLock.ReleaseWriterLock();
        //    }
        //    return false;
        //}

        /// <summary>
        /// 当集合中不存在指定的对象时,将对象添加到集合的结尾处。
        /// </summary>
        /// <param name="item">待添加对象。</param>
        /// <param name="match">用于确定对象是否已经在集合中的匹配器。</param>
        /// <returns>添加成功返回 true;否则返回 false。</returns>
        /// <remarks>
        /// 此方法在执行时,首先在集合中查找与待添加对象匹配的元素(通过执行比较器来确定是否匹配),对于已经存在匹配项的情况认为添加成功,返回 true,否则执行添加操作。
        /// </remarks>
        public bool AddOnly(Task <T> item, System.Predicate <Task <T> > match)
        {
            this.datasRWLock.AcquireWriterLock(System.Threading.Timeout.Infinite);
            try
            {
                foreach (var tmp in this.datas.Values)
                {
                    if (match.Invoke(tmp))
                    {
                        return(true);
                    }
                }
                if ((this.MaxSize == -1 || this.datas.Count < MaxSize))
                {
                    item.OwnerSortedTaskQueue = this;
                    this.datas.Add(item.RunTime, item);
                    Event.Set();
                    return(true);
                }
            }
            finally
            {
                this.datasRWLock.ReleaseWriterLock();
            }
            return(false);
        }
Exemplo n.º 5
0
        public static MapObject GetClosest(MapObject source, MapObject[] locations, System.Predicate <MapObject> predicate)
        {
            if (locations.Length == 0 || source == null)
            {
                return(null);
            }
            else
            {
                MapObject closest = null;

                foreach (MapObject location in locations)
                {
                    int distanceToSource = location.Distance(source);

                    if (location.Equals(source))
                    {
                        continue;
                    }

                    if (!predicate.Invoke(location))
                    {
                        continue;
                    }

                    if (closest == null || distanceToSource < closest.Distance(source))
                    {
                        closest = location;
                    }
                }

                return(closest);
            }
        }
 /// <summary>
 /// 当集合中不存在指定的对象时,将对象添加到集合的结尾处。
 /// </summary>
 /// <param name="item">待添加对象。</param>
 /// <param name="match">用于确定对象是否已经在集合中的匹配器。</param>
 /// <returns>添加成功返回 true;否则返回 false。</returns>
 /// <remarks>
 /// 此方法在执行时,首先在集合中查找与待添加对象匹配的元素(通过执行比较器来确定是否匹配),对于已经存在匹配项的情况认为添加成功,返回 true,否则执行添加操作。
 /// </remarks>
 public bool AddOnly(T item, System.Predicate <T> match)
 {
     this.datasRWLock.AcquireWriterLock(System.Threading.Timeout.Infinite);
     try
     {
         foreach (var tmp in this.datas)
         {
             if (match.Invoke(tmp))
             {
                 return(true);
             }
         }
         if ((this.MaxSize == -1 || this.datas.Count < MaxSize))
         {
             this.datas.AddLast(item);
             Event.Set();
             return(true);
         }
     }
     finally
     {
         this.datasRWLock.ReleaseWriterLock();
     }
     return(false);
 }
Exemplo n.º 7
0
    public XmlNode Find(System.Predicate <XmlNode> match)
    {
        foreach (XmlNode node in root.ChildNodes)
        {
            if (match.Invoke(node))
            {
                return(node);
            }
        }

        return(null);
    }
Exemplo n.º 8
0
        public static Location GetClosestBuildableLocation(this MapObject location, System.Predicate <Location> isLocationValid, bool checkForPortal = true, MapObject towards = null, List <Building> uncheckedBuildings = null)
        {
            if (CanBuildInLocation(location, checkForPortal) && uncheckedBuildings == null)
            {
                //if we can build here and we are not checking a building, we can just return the current location
                return(location.GetLocation());
            }
            else //we can't build here, time to look for an available spot
            {
                if (uncheckedBuildings == null) //if the list of checked buildings is null (meaning we were given an arbitrery location)
                {
                    uncheckedBuildings = Constants.Game.GetAllBuildings().ToList(); //we create a new list with all buildings
                    //System.Console.WriteLine("All unchecked buildings:");
                    //Utilities.DebugArray(uncheckedBuildings.ToArray());
                    //System.Console.WriteLine($"location: {location}");
                    //System.Console.WriteLine($"closest unchecked building to location: {uncheckedBuildings.ToArray().GetClosest(location)}");
                    //start recursion on the closest building to the arbitrery location
                    return(uncheckedBuildings.ToArray().GetClosest(location, true).GetClosestBuildableLocation(isLocationValid, checkForPortal, towards, uncheckedBuildings));
                }

                int startAngle = 0;
                if (towards != null)
                {
                    startAngle = Mathf.RoundToInt(location.GetAngle(towards));
                }

                for (int i = startAngle; i < startAngle + 360; i++)                                                                    //check all angles, this can probably be optimized but it's not a problem so f**k it
                {
                    Location newLocation = location.GetNewLocation(i, ((Building)location).Size + Constants.Game.PortalSize + 10 * 3); //get the new location

                    if (newLocation == null)
                    {
                        continue;
                    }

                    if (isLocationValid != null && !isLocationValid.Invoke(newLocation))
                    {
                        continue;                                        //if the delegate/predicate/lambda however you want to call it returns false, this newlocation is invalid and we move on
                    }
                    if (CanBuildInLocation(newLocation, checkForPortal)) //if this location is suitable to build at
                    {
                        return(newLocation);                             //return this location
                    }
                }

                //remove this building since we just checked it and we don't want to check it again
                uncheckedBuildings.Remove((Building)location);

                return(uncheckedBuildings.ToArray().GetClosest(location).GetClosestBuildableLocation(isLocationValid, checkForPortal, towards, uncheckedBuildings)); //we didn't find an available location near our given building, start recursion on next closest building
            }
        }
    private static List <Cards> FilterCards(System.Predicate <Cards> filter)
    {
        List <Cards> cards = new List <Cards>();

        foreach (Cards card in (Cards[])System.Enum.GetValues(typeof(Cards)))
        {
            if (filter.Invoke(card))
            {
                cards.Add(card);
            }
        }

        return(cards);
    }
Exemplo n.º 10
0
    public static T Find <T>(this T[] array, System.Predicate <T> condition)
    {
        T result = default(T);

        for (int i = 0; i < array.Length; i++)
        {
            if (condition.Invoke(array[i]))
            {
                result = array[i];
                break;
            }
        }
        return(result);
    }
Exemplo n.º 11
0
 public static bool Any <T>(this T[] a, System.Predicate <T> m)
 {
     if (!a.IsNull() && !m.IsNull())
     {
         for (var i = 0; i < a.Length; i++)
         {
             if (m.Invoke(a[i]))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 12
0
    public static List <int> FindAllIndexes(this List <string> strings, System.Predicate <string> predicate)
    {
        List <int> indexes = new List <int>();

        for (int i = 0; i < strings.Count; i++)
        {
            if (predicate.Invoke(strings[i]))
            {
                indexes.Add(i);
            }
        }

        return(indexes);
    }
Exemplo n.º 13
0
        /// <summary>
        /// Returns all gameObjects of the player which can cause damage to
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public static List <GameObject> GetCustomGameObjects(this Player player, System.Predicate <GameObject> shouldGetGameObject)
        {
            List <GameObject> gameObjects = new List <GameObject>();

            foreach (GameObject gameObject in player.GetAllGameObjects())
            {
                if (shouldGetGameObject.Invoke(gameObject))
                {
                    gameObjects.Add(gameObject);
                }
            }

            return(gameObjects);
        }
Exemplo n.º 14
0
 public bool Exists(System.Predicate <T> match)
 {
     if (match.IsNull())
     {
         throw new System.NullReferenceException();
     }
     for (var i = 0; i < array.Length; i++)
     {
         if (match.Invoke(array[i]))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 15
0
 public static void DoFor <T>(this T[] a, System.Predicate <T> m, System.Action <T> action, bool forwardOrder = true)
 {
     if (!a.IsNull() && !action.IsNull() && !m.IsNull())
     {
         var start  = forwardOrder ? 0 : (a.Length - 1);
         var offset = forwardOrder ? 1 : -1;
         for (var i = start; (i >= 0) && (i < a.Length); i += offset)
         {
             if (m.Invoke(a[i]))
             {
                 action.Invoke(a[i]);
             }
         }
     }
 }
Exemplo n.º 16
0
        public static bool Contains <T>(this System.Collections.Generic.IEnumerable <T> e, System.Predicate <T> m = null)
        {
            if (e.IsNull())
            {
                throw new System.NullReferenceException();
            }
            var list   = new System.Collections.Generic.List <T>(e);
            var result = false;

            for (var i = 0; (i < list.Count) && !result; i++)
            {
                result = m.Invoke(list[i]);
            }
            list.Clear();
            return(result);
        }
Exemplo n.º 17
0
        public void DebugPrint(System.Predicate <Data> filter)
        {
            int width  = values.GetLength(0);
            int height = values.GetLength(1);

            Data[] result = new Data[width * height];
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (filter.Invoke(values[i, j]))
                    {
                        Debug.Log(i + " " + j + " " + values[i, j]);
                    }
                }
            }
        }
Exemplo n.º 18
0
        public static void DestroyIf(GStylizedTerrain terrain, GameObject prototype, System.Predicate <GameObject> condition)
        {
            Transform parent = GetRoot(terrain, prototype).transform;

            GameObject[] children = GUtilities.GetChildrenGameObjects(parent);
            for (int i = 0; i < children.Length; ++i)
            {
                if (condition.Invoke(children[i]))
                {
#if UNITY_EDITOR
                    Undo.DestroyObjectImmediate(children[i]);
#else
                    GUtilities.DestroyGameobject(children[i]);
#endif
                }
            }
        }
Exemplo n.º 19
0
 public void RemoveAll(System.Predicate <T> predicate)
 {
     swapBuffer.Clear();
     swapBuffer.Capacity = globalList.Capacity;
     foreach (T model in globalList)
     {
         if (!predicate.Invoke(model))
         {
             swapBuffer.Add(model);
         }
         else
         {
             RemoveFromBucket(model);
         }
     }
     globalList.Clear();
     globalList.AddRange(swapBuffer);
 }
Exemplo n.º 20
0
        public int RemoveAll(System.Predicate <T> match)
        {
            if (match.IsNull())
            {
                throw new System.NullReferenceException();
            }
            var result = 0;

            for (var i = 0; i < array.Length; i++)
            {
                if (match.Invoke(array[i]))
                {
                    RemoveAt(i);
                    result++;
                    i--;
                }
            }
            return(result);
        }
Exemplo n.º 21
0
 /// <summary>
 /// 搜索与指定谓词所定义的条件相匹配的元素,并返回整个集合中的相匹配的第一个元素。
 /// </summary>
 /// <param name="match">用于定义要搜索的元素的条件。</param>
 /// <returns>如果找到与指定谓词定义的条件匹配的第一个元素,则为该元素;否则为类型 T 的默认值。</returns>
 public Task <T> Find(System.Predicate <Task <T> > match)
 {
     this.datasRWLock.AcquireReaderLock(System.Threading.Timeout.Infinite);
     try
     {
         foreach (var tmp in this.datas.Values)
         {
             if (match.Invoke(tmp))
             {
                 return(tmp);
             }
         }
     }
     finally
     {
         this.datasRWLock.ReleaseReaderLock();
     }
     return(null);
 }
Exemplo n.º 22
0
 public static void RemoveAll <T>(ref T[] a, System.Predicate <T> m)
 {
     if (a.IsNull())
     {
         throw new System.NullReferenceException();
     }
     if (m.IsNull())
     {
         throw new System.NullReferenceException();
     }
     for (var i = 0; i < a.Length; i++)
     {
         if (m.Invoke(a[i]))
         {
             RemoveAt(ref a, i);
             i--;
         }
     }
 }
Exemplo n.º 23
0
        public void FillRectRoadReverse(int left, int top, int right, int bottom, System.Predicate <TileData> predicate = null)
        {
            for (int y = bottom - 1; y >= top; --y)
            {
                for (int x = right - 1; x >= left; --x)
                {
                    var tileData = this.GetTile(x, y);
                    if (!predicate?.Invoke(tileData) ?? false)
                    {
                        continue;
                    }

                    // 部屋の場所は書き換えない
                    //	if (tileData.HasFlag(TileFlag.Floor)) continue;

                    // 部屋と隣接していたらtrueをいれる
                    tileData.SetFlag(TileFlag.Road);
                }
            }
        }
Exemplo n.º 24
0
        static StackObject *Invoke_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Collections.IDictionary @obj = (System.Collections.IDictionary) typeof(System.Collections.IDictionary).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Predicate <System.Collections.IDictionary> instance_of_this_method = (System.Predicate <System.Collections.IDictionary>) typeof(System.Predicate <System.Collections.IDictionary>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.Invoke(@obj);

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method ? 1 : 0;
            return(__ret + 1);
        }
 /// <summary>
 /// 搜索与指定谓词所定义的条件相匹配的元素,并返回整个集合中的相匹配的第一个元素。
 /// </summary>
 /// <param name="match">用于定义要搜索的元素的条件。</param>
 /// <param name="result">返回找到的项目。</param>
 /// <returns>如果找到与指定谓词定义的条件匹配的第一个元素,则为 true;否则为 false。</returns>
 public bool Find(System.Predicate <T> match, out T result)
 {
     this.datasRWLock.AcquireReaderLock(System.Threading.Timeout.Infinite);
     try
     {
         foreach (var tmp in this.datas)
         {
             if (match.Invoke(tmp))
             {
                 result = tmp;
                 return(true);
             }
         }
         //return this.datas.Find(match);
     }
     finally
     {
         this.datasRWLock.ReleaseReaderLock();
     }
     result = default(T);
     return(false);
 }
Exemplo n.º 26
0
        protected void DisplayList <TGame>(System.Collections.Generic.IEnumerable <TGame> gameElements, System.Predicate <TGame> displayPredicate, System.Action <TGame, TUI> updateElement)
        {
            int index = 0;

            if (gameElements != null)
            {
                foreach (var element in gameElements)
                {
                    if (displayPredicate != null && !displayPredicate.Invoke(element))
                    {
                        continue;
                    }

                    TUI line = default(TUI);
                    if (index < uiElements.Count)
                    {
                        line = this.uiElements[index];
                    }
                    else
                    {
                        var gameObject = UnityEngine.GameObject.Instantiate(prefab);
                        gameObject.transform.SetParent(this.listHolder, false);
                        line = gameObject.GetComponent <TUI>();
                        uiElements.Add(line);
                    }

                    updateElement.Invoke(element, line);
                    index++;
                }
            }

            for (int remainingIndex = uiElements.Count - 1; remainingIndex >= index; remainingIndex--)
            {
                UnityEngine.GameObject.Destroy(uiElements[remainingIndex].gameObject);
                uiElements.RemoveAt(remainingIndex);
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// Removes all tags that match the given predicate.
 /// </summary>
 /// <param name="predicate"></param>
 public override void RemoveAll(System.Predicate <Tag> predicate)
 {
     _tagsList.RemoveAll(x => predicate.Invoke(new Tag(_stringTable.Get(x.Key), _stringTable.Get(x.Value))));
 }
Exemplo n.º 28
0
 /// <summary>
 /// Removes all tags that match the given predicate.
 /// </summary>
 /// <param name="predicate"></param>
 public override void RemoveAll(System.Predicate <Tag> predicate)
 {
     _tags.RemoveAll(x => predicate.Invoke(_tagsTable.Get(x)));
 }