Ejemplo n.º 1
0
        public void AddRange_from_array_bigger_than_capacity_then_it_grows_and_add_items()
        {
            int[] expectedValues = Enumerable.Range(0, 1000).ToArray();
            using var sut = new ListPool <int>(128);

            sut.AddRange(expectedValues);

            Assert.Equal(expectedValues.Length, sut.Count);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
        }
Ejemplo n.º 2
0
        public void AddRange_from_array_adds_all_items()
        {
            int[] expectedValues = Enumerable.Range(0, 10).ToArray();
            using var sut = new ListPool <int>(10);

            sut.AddRange(expectedValues);

            Assert.Equal(expectedValues.Length, sut.Count);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
        }
Ejemplo n.º 3
0
        public void AddRange_from_enumerable_as_IEnumerable_bigger_than_capacity_then_it_grows_and_add_items()
        {
            IEnumerable <int> expectedValues = Enumerable.Range(0, 1000);

            using var sut = new ListPool <int>(128);

            sut.AddRange(expectedValues);

            Assert.Equal(expectedValues.Count(), sut.Count);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
        }
Ejemplo n.º 4
0
        public void AddRange_from_enumerable_as_IEnumerable_adds_all_items()
        {
            IEnumerable <int> expectedValues = Enumerable.Range(0, 10);

            using var sut = new ListPool <int>(10);

            sut.AddRange(expectedValues);

            Assert.Equal(expectedValues.Count(), sut.Count);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
        }
Ejemplo n.º 5
0
        public void AddRange_from_span_bigger_than_capacity_then_it_grows_and_add_items()
        {
            Span <int> expectedValues = Enumerable.Range(0, 1000).ToArray();

            using var sut = new ListPool <int>(64);

            sut.AddRange(expectedValues);

            Assert.Equal(expectedValues.Length, sut.Count);
            foreach (int expectedValue in expectedValues)
            {
                Assert.Contains(expectedValue, sut);
            }
        }
Ejemplo n.º 6
0
        public void AddRange_from_span_adds_all_items()
        {
            Span <int> expectedValues = Enumerable.Range(0, 10).ToArray();

            using var sut = new ListPool <int>(10);

            sut.AddRange(expectedValues);

            Assert.Equal(expectedValues.Length, sut.Count);
            foreach (int expectedValue in expectedValues)
            {
                Assert.Contains(expectedValue, sut);
            }
        }
Ejemplo n.º 7
0
        public void AddRange_adds_all_items()
        {
            int[] expectedValues       = Enumerable.Range(0, 10).ToArray();
            int   expectedItem0        = s_fixture.Create <int>();
            int   expectedItem1        = s_fixture.Create <int>();
            int   expectedItem2        = s_fixture.Create <int>();
            int   expectedItemAtTheEnd = s_fixture.Create <int>();
            int   expectedCount        = expectedValues.Length + 4;

            using var sut = new ListPool <int>(20)
                  {
                      expectedItem0, expectedItem1, expectedItem2
                  };

            sut.AddRange(expectedValues);
            sut.Add(expectedItemAtTheEnd);

            Assert.Equal(expectedCount, sut.Count);
            Assert.Equal(expectedItem0, sut[0]);
            Assert.Equal(expectedItem1, sut[1]);
            Assert.Equal(expectedItem2, sut[2]);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
            Assert.Equal(expectedItemAtTheEnd, sut[13]);
        }
    private void AddChoreEntry(Chore chore)
    {
        HierarchyReferences choreEntry = GetChoreEntry(GameUtil.GetChoreName(chore, null), chore.choreType, choreGroup.GetReference <RectTransform>("EntriesContainer"));
        FetchChore          fetchChore = chore as FetchChore;

        ListPool <Chore.Precondition.Context, BuildingChoresPanel> .PooledList pooledList = ListPool <Chore.Precondition.Context, BuildingChoresPanel> .Allocate();

        foreach (MinionIdentity item in Components.LiveMinionIdentities.Items)
        {
            pooledList.Clear();
            ChoreConsumer component = item.GetComponent <ChoreConsumer>();
            Chore.Precondition.Context         context = default(Chore.Precondition.Context);
            ChoreConsumer.PreconditionSnapshot lastPreconditionSnapshot = component.GetLastPreconditionSnapshot();
            if (lastPreconditionSnapshot.doFailedContextsNeedSorting)
            {
                lastPreconditionSnapshot.failedContexts.Sort();
                lastPreconditionSnapshot.doFailedContextsNeedSorting = false;
            }
            pooledList.AddRange(lastPreconditionSnapshot.failedContexts);
            pooledList.AddRange(lastPreconditionSnapshot.succeededContexts);
            int num  = -1;
            int num2 = 0;
            for (int num3 = pooledList.Count - 1; num3 >= 0; num3--)
            {
                Chore.Precondition.Context context2 = pooledList[num3];
                if ((UnityEngine.Object)context2.chore.driver != (UnityEngine.Object)null)
                {
                    Chore.Precondition.Context context3 = pooledList[num3];
                    if ((UnityEngine.Object)context3.chore.driver != (UnityEngine.Object)component.choreDriver)
                    {
                        continue;
                    }
                }
                bool flag = pooledList[num3].IsPotentialSuccess();
                if (flag)
                {
                    num2++;
                }
                Chore.Precondition.Context context4       = pooledList[num3];
                FetchAreaChore             fetchAreaChore = context4.chore as FetchAreaChore;
                Chore.Precondition.Context context5       = pooledList[num3];
                if (context5.chore == chore || (fetchChore != null && fetchAreaChore != null && fetchAreaChore.smi.SameDestination(fetchChore)))
                {
                    num     = ((!flag) ? 2147483647 : num2);
                    context = pooledList[num3];
                    break;
                }
            }
            if (num >= 0)
            {
                DupeEntryDatas.Add(new DupeEntryData
                {
                    consumer         = component,
                    context          = context,
                    personalPriority = component.GetPersonalPriority(chore.choreType),
                    rank             = num
                });
            }
        }
        pooledList.Recycle();
        DupeEntryDatas.Sort();
        foreach (DupeEntryData dupeEntryData in DupeEntryDatas)
        {
            GetDupeEntry(dupeEntryData, choreEntry.GetReference <RectTransform>("DupeContainer"));
        }
        DupeEntryDatas.Clear();
    }
Ejemplo n.º 9
0
    private void PopulateElements(object data = null)
    {
        refreshHandle.ClearScheduler();
        refreshHandle = UIScheduler.Instance.Schedule("RefreshToDoList", 0.1f, PopulateElements, null, null);
        ListPool <Chore.Precondition.Context, BuildingChoresPanel> .PooledList pooledList = ListPool <Chore.Precondition.Context, BuildingChoresPanel> .Allocate();

        ChoreConsumer.PreconditionSnapshot lastPreconditionSnapshot = choreConsumer.GetLastPreconditionSnapshot();
        if (lastPreconditionSnapshot.doFailedContextsNeedSorting)
        {
            lastPreconditionSnapshot.failedContexts.Sort();
            lastPreconditionSnapshot.doFailedContextsNeedSorting = false;
        }
        pooledList.AddRange(lastPreconditionSnapshot.failedContexts);
        pooledList.AddRange(lastPreconditionSnapshot.succeededContexts);
        Chore.Precondition.Context choreB = default(Chore.Precondition.Context);
        MinionTodoChoreEntry       minionTodoChoreEntry = null;
        int         num       = 0;
        Schedulable component = DetailsScreen.Instance.target.GetComponent <Schedulable>();
        string      arg       = string.Empty;
        Schedule    schedule  = component.GetSchedule();

        if (schedule != null)
        {
            ScheduleBlock block = schedule.GetBlock(Schedule.GetBlockIdx());
            arg = block.name;
        }
        currentScheduleBlockLabel.SetText(string.Format(UI.UISIDESCREENS.MINIONTODOSIDESCREEN.CURRENT_SCHEDULE_BLOCK, arg));
        choreTargets.Clear();
        bool flag = false;

        activeChoreEntries = 0;
        for (int num2 = pooledList.Count - 1; num2 >= 0; num2--)
        {
            Chore.Precondition.Context context = pooledList[num2];
            if (context.chore != null)
            {
                Chore.Precondition.Context context2 = pooledList[num2];
                if (!context2.chore.target.isNull)
                {
                    Chore.Precondition.Context context3 = pooledList[num2];
                    if (!((UnityEngine.Object)context3.chore.target.gameObject == (UnityEngine.Object)null) && pooledList[num2].IsPotentialSuccess())
                    {
                        Chore.Precondition.Context context4 = pooledList[num2];
                        if ((UnityEngine.Object)context4.chore.driver == (UnityEngine.Object)choreConsumer.choreDriver)
                        {
                            currentTask.Apply(pooledList[num2]);
                            minionTodoChoreEntry = currentTask;
                            choreB = pooledList[num2];
                            num    = 0;
                            flag   = true;
                        }
                        else if (!flag && activeChoreEntries != 0 && GameUtil.AreChoresUIMergeable(pooledList[num2], choreB))
                        {
                            num++;
                            minionTodoChoreEntry.SetMoreAmount(num);
                        }
                        else
                        {
                            ChoreConsumer obj = choreConsumer;
                            Chore.Precondition.Context context5            = pooledList[num2];
                            HierarchyReferences        hierarchyReferences = PriorityGroupForPriority(obj, context5.chore);
                            MinionTodoChoreEntry       choreEntry          = GetChoreEntry(hierarchyReferences.GetReference <RectTransform>("EntriesContainer"));
                            choreEntry.Apply(pooledList[num2]);
                            minionTodoChoreEntry = choreEntry;
                            choreB = pooledList[num2];
                            num    = 0;
                            flag   = false;
                        }
                    }
                }
            }
        }
        pooledList.Recycle();
        for (int num3 = choreEntries.Count - 1; num3 >= activeChoreEntries; num3--)
        {
            choreEntries[num3].gameObject.SetActive(false);
        }
        foreach (Tuple <PriorityScreen.PriorityClass, int, HierarchyReferences> priorityGroup in priorityGroups)
        {
            RectTransform reference = priorityGroup.third.GetReference <RectTransform>("EntriesContainer");
            priorityGroup.third.gameObject.SetActive(reference.childCount > 0);
        }
    }