コード例 #1
0
 /// <summary>Removes a value.</summary>
 /// <typeparam name="T">The type of value.</typeparam>
 /// <param name="structure">The structure to remove the value from.</param>
 /// <param name="value">The value to be removed.</param>
 public static void Remove <T>(this IRemovable <T> structure, T value)
 {
     if (!structure.TryRemove(value, out Exception exception))
     {
         throw exception;
     }
 }
コード例 #2
0
        public override void OnPlayerControlTick()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                if (this.prop.IsValid())
                {
                    this.prop.Delete();
                    this.prop = null;

                    return;
                }

                if (this.removable != null)
                {
                    this.removable.Remove();
                    this.removable = null;

                    return;
                }

                var input = Owner.Input;

                if (!input.Pressed(InputButton.Attack1))
                {
                    return;
                }

                var startPos = Owner.EyePos;
                var dir      = Owner.EyeRot.Forward;

                var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance)
                         .Ignore(Owner)
                         .Run();

                if (!tr.Hit || !tr.Entity.IsValid() || tr.Entity.IsWorld)
                {
                    return;
                }

                if (tr.Entity is IRemovable removable)
                {
                    this.removable = removable;

                    return;
                }

                if (tr.Entity is Prop prop)
                {
                    prop.PhysicsGroup?.Wake();
                    this.prop = prop;

                    return;
                }
            }
        }
コード例 #3
0
ファイル: DataStructure.cs プロジェクト: inktan/Towel
 /// <summary>Removes a value.</summary>
 /// <typeparam name="T">The type of value.</typeparam>
 /// <param name="structure">The structure to remove the value from.</param>
 /// <param name="value">The value to be removed.</param>
 public static void Remove <T>(this IRemovable <T> structure, T value)
 {
     if (!structure.TryRemove(value, out Exception? exception))
     {
         throw exception ?? new ArgumentException(nameof(exception), $"{nameof(Remove)} failed but the {nameof(exception)} is null");;
     }
 }
コード例 #4
0
 /// <summary>Removes a value from a data structure.</summary>
 /// <typeparam name="T">The type of values stored in this data structure.</typeparam>
 /// <param name="removable">The data structure to removable the value from.</param>
 /// <param name="value">The value to remove from the data structure.</param>
 public static void Remove <T>(this IRemovable <T> removable, T value)
 {
     var(success, exception) = removable.TryRemove(value);
     if (!success)
     {
         throw exception ?? new ArgumentException($"{nameof(Remove)} failed but the {nameof(exception)} is null");
     }
 }
コード例 #5
0
 private static void RemoveItemsMethod(IRemovable collection, int numberToRemove)
 {
     for (int i = 0; i < numberToRemove; i++)
     {
         Console.Write(collection.RemoveItem() + " ");
     }
     Console.WriteLine();
 }
コード例 #6
0
    private static void RemoveElementsFromCollection(StringBuilder sBuilder, IRemovable collection, int numberOfRemoves)
    {
        for (int i = 0; i < numberOfRemoves; i++)
        {
            sBuilder.Append(collection.Remove());
            sBuilder.Append(" ");
        }

        sBuilder.AppendLine();
    }
コード例 #7
0
    private static void RemoveElementsFromCollection(IRemovable addRemoveCollection, int countRemoveElements)
    {
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < countRemoveElements; i++)
        {
            sb.Append(addRemoveCollection.Remove())
            .Append(' ');
        }
        Console.WriteLine(sb.ToString().Trim());
    }
コード例 #8
0
 /// <summary>Wrapper for the "Remove" method to help with exceptions.</summary>
 /// <typeparam name="T">The generic type of the structure.</typeparam>
 /// <param name="structure">The structure.</param>
 /// <param name="removal">The item to be removed.</param>
 /// <returns>True if successful, False if not.</returns>
 public static bool TryRemove <T>(this IRemovable <T> structure, T removal)
 {
     try
     {
         structure.Remove(removal);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #9
0
        /// <summary>
        /// Remove an item from the <see cref="IPagedDataSet"/> with the specified position
        /// </summary>
        /// <param name="dataSet">The dataset to modify</param>
        /// <param name="offset">The position to remove relative to the dataset's caret</param>
        /// <returns></returns>
        public static async Task RemoveAtOffset(this IRemovable removable, IPagedDataSet dataSet, int offset)
        {
            var pi = await dataSet.GetCurrentPageIndex();

            var ps = await dataSet.GetPageSize();

            var sel = await dataSet.GetSelector();

            if (sel == null)
            {
                throw new InvalidOperationException("The paged data set does not support selecting items that is required for this method to work");
            }

            await removable.RemoveAt(dataSet, pi *ps + offset + await sel.GetCaretPosition());
        }
コード例 #10
0
        public linkFactory2(IRemovable owner)
        {
            init_Identity();
            init_StorageLinks();

            owner.event_ObjectDeleted += handler_ownerDelete;

            unsubscribeOwner = () =>
            {
                if (owner != null)
                {
                    owner.event_ObjectDeleted -= handler_ownerDelete;
                }
                unsubscribeOwner = null;
            };
        }
コード例 #11
0
        /// <summary>Wrapper for the "Remove" method to help with exceptions.</summary>
        /// <typeparam name="T">The generic type of the structure.</typeparam>
        /// <param name="structure">The data structure.</param>
        /// <param name="removal">The item to be removed.</param>
        /// <returns>True if successful, False if not.</returns>
        public static bool TryRemove <T>(this IRemovable <T> structure, T removal)
        {
            // Note: This is most likely a bad practice. try-catch-ing should
            // not be used for control flow like this. I will likely be moving this
            // method into the "IRemovable<T>" interface in the future.

            try
            {
                structure.Remove(removal);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #12
0
ファイル: God.cs プロジェクト: JulianRijken/WaterMuseum
 private void Update()
 {
     if (Input.touchCount > 0)
     {
         Touch touch = Input.GetTouch(0);
         if (!EventSystem.current.IsPointerOverGameObject(touch.fingerId))
         {
             if (touch.phase == TouchPhase.Began)
             {
                 if (m_selectedTool == Tool.place)
                 {
                     if (Stats.Sheet.m_rockCount < m_maxStones)
                     {
                         Ray        ray = m_mainCamera.ScreenPointToRay(touch.position);
                         RaycastHit hit;
                         if (Physics.Raycast(ray, out hit, m_terrainLayer))
                         {
                             if (m_placeAllowed)
                             {
                                 if (hit.point.y < m_maxRockHeight)
                                 {
                                     StartCoroutine(DelayRock());
                                     Vector3 spawnPoint = hit.point + m_placeOffset;
                                     ObjectPooler.SpawnObject(m_rockName, spawnPoint + m_placeOffset, Quaternion.identity, true);
                                     Stats.Sheet.m_rockCount++;
                                 }
                             }
                         }
                     }
                 }
                 else
                 {
                     Ray        ray = m_mainCamera.ScreenPointToRay(touch.position);
                     RaycastHit hit;
                     if (Physics.Raycast(ray, out hit, m_removeLayer))
                     {
                         IRemovable removable = hit.collider.GetComponent <IRemovable>();
                         if (removable != null)
                         {
                             removable.OnRemove();
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #13
0
        public void CheckRemovables()
        {
            for (int i = _gameobjects.Count - 1; i >= 0; i--)
            {
                GameObject go = _gameobjects[i];

                // remove
                if (go is IRemovable)
                {
                    IRemovable rmv = go as IRemovable;

                    if (rmv.RemoveMe == true)
                    {
                        _gameobjects.Remove(go);
                    }
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Add midi signal
        /// </summary>
        /// <param name="midiType">type of midi signal</param>
        private void AddMidi(MidiSignalTypes midiType, BaseMidiSignal midiSignal)
        {
            IRemovable midiVM = null;

            switch (midiType)
            {
            case MidiSignalTypes.MidiCC:
                if (midiSignal == null)
                {
                    midiSignal = new MidiCC();
                    m_conditionsBlock.MidiSignals.Add(midiSignal);
                }
                midiVM = new MidiCCViewModel((MidiCC)midiSignal);
                break;

            case MidiSignalTypes.MidiNote:
                if (midiSignal == null)
                {
                    midiSignal = new MidiNote();
                    m_conditionsBlock.MidiSignals.Add(midiSignal);
                }
                midiVM = new MidiNoteViewModel((MidiNote)midiSignal);
                break;
            }

            if (midiVM != null)
            {
                MidiSignals.Add(midiVM);

                //add remove delegate
                midiVM.DelegateToRemove = () =>
                {
                    m_conditionsBlock.MidiSignals.Remove(midiSignal);
                    MidiSignals.Remove(midiVM);
                };
            }
        }
コード例 #15
0
        /// <summary>
        /// Add condition
        /// </summary>
        /// <param name="conditionType">type of condition</param>
        private void AddCondition(ConditionTypes conditionType, BaseCondition condition)
        {
            IRemovable conditionVM = null;

            switch (conditionType)
            {
            case ConditionTypes.SkeletonPointToCordinate:
                if (condition == null)
                {
                    condition = new CuboidCondition();
                    m_conditionsBlock.Conditions.Add(condition);
                }
                conditionVM = new SkeletonPointToCubeViewModel((CuboidCondition)condition);
                break;

            case ConditionTypes.SkeletonPointToSkeletonPoint:
                if (condition == null)
                {
                    condition = new RelatedSphereCondition();
                    m_conditionsBlock.Conditions.Add(condition);
                }
                conditionVM = new SkeletonPointToSkeletonPointViewModel((RelatedSphereCondition)condition);
                break;
            }

            if (conditionVM != null)
            {
                Conditions.Add(conditionVM);

                //add remove delegate
                conditionVM.DelegateToRemove = () =>
                {
                    m_conditionsBlock.Conditions.Remove(condition);
                    Conditions.Remove(conditionVM);
                };
            }
        }
コード例 #16
0
 private static void RemoveElementsFromCollection(StringBuilder builder, int numberOfRemoveOperations, IRemovable collection)
 {
     for (int i = 0; i < numberOfRemoveOperations; i++)
     {
         builder.Append(collection.Remove())
         .Append(' ');
     }
     builder.AppendLine();
 }
コード例 #17
0
 public TaskExecutionToken(ITask task, IRemovable <ITask> remover)
 {
     _task         = task;
     _remover      = remover;
     _currentState = TokenState.Undefined;
 }
コード例 #18
0
 /// <summary>Tries to removes a value.</summary>
 /// <typeparam name="T">The type of value.</typeparam>
 /// <param name="structure">The structure to remove the value from.</param>
 /// <param name="value">The value to be removed.</param>
 /// <returns>True if the remove was successful or false if not.</returns>
 public static bool TryRemove <T>(this IRemovable <T> structure, T value)
 {
     return(structure.TryRemove(value, out _));
 }
コード例 #19
0
 /// <summary>
 /// Remove an item from the <see cref="IPagedDataSet"/> with the specified position
 /// </summary>
 /// <param name="dataSet">The dataset to modify</param>
 /// <param name="index">The position to remove</param>
 /// <returns></returns>
 public static async Task RemoveAt(this IRemovable removable, IPagedDataSet dataSet, int index)
 => await removable.Remove((await dataSet.GetDataSource()).ElementAtOrDefault(index));
コード例 #20
0
        public override void OnPlayerControlTick()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                if (prop.IsValid())
                {
                    prop.Delete();
                    prop = null;

                    return;
                }

                if (this.removable != null)
                {
                    this.removable.Remove();
                    this.removable = null;

                    return;
                }

                var input = Owner.Input;

                if (!input.Pressed(InputButton.Attack1))
                {
                    return;
                }

                var startPos = Owner.EyePos;
                var dir      = Owner.EyeRot.Forward;

                var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance)
                         .Ignore(Owner)
                         .HitLayer(CollisionLayer.Debris)
                         .Run();

                if (!tr.Hit || !tr.Entity.IsValid())
                {
                    return;
                }

                if (tr.Entity.IsValid())
                {
                    if (Owner != tr.Entity.Owner)
                    {
                        return;
                    }
                }

                CreateHitEffects(tr.EndPos);

                if (tr.Entity.IsWorld)
                {
                    return;
                }

                if (tr.Entity is IRemovable removable)
                {
                    this.removable = removable;
                }
                else if (tr.Entity is Prop prop)
                {
                    prop.PhysicsGroup?.Wake();
                    this.prop = prop;
                }
                else
                {
                    return;
                }

                var particle = Particles.Create("particles/physgun_freeze.vpcf");
                particle.SetPos(0, tr.Entity.WorldPos);
            }
        }
コード例 #21
0
 public Task SetRemover(IRemovable <TItem> remover)
 {
     _remover = remover;
     return(Task.CompletedTask);
 }
コード例 #22
0
 public Engine()
 {
     this.addCollection       = new AddCollection();
     this.addRemoveCollection = new AddRemoveCollection();
     this.myListCollection    = new MyList();
 }
コード例 #23
0
 public AceTableViewSource(IRemovable removableModel,UITableView tableView, Type cellType, string cellIdentifier = null)
     : base(tableView,cellType,cellIdentifier)
 {
     tableView.RegisterClassForCellReuse(cellType, cellType.Name);
     this.RemovableViewModel = removableModel;
 }
コード例 #24
0
 public Delete(IRemovable iRemovableItem)
 {
     InitializeComponent();
     _iRemovableItem = iRemovableItem;
 }
コード例 #25
0
 public static bool IsRemoved(this IRemovable removable)
 {
     return(removable.IsRemoved);
 }
コード例 #26
0
 public UserProfileRepository(ApplicationDbContext dbContext) : base(dbContext)
 {
     removableBehavior = new RemovableBehavior <UserProfile, UserProfileMapper>(this);
 }
コード例 #27
0
 public PagedDataSetBuilder <TItem, TResult> WithRemover(IRemovable <TItem> remover) => WithRemover(x => Task.FromResult(remover));