Exemplo n.º 1
0
 /// <summary>
 /// Gets effect data from the dicronary if it exists.
 /// </summary>
 /// <param name="effect">The effect to get.</param>
 /// <param name="effectData">The effect data ssociated with the effect.</param>
 /// <returns><see langword="true"/> when the effect exists; otherwise <see langword="false"/>.</returns>
 protected bool GetKnownEffect(ICellEffect effect, out ColoredGlyphEffectData effectData)
 {
     if (_effects.ContainsKey(effect))
     {
         effectData = _effects[effect];
         return(true);
     }
     else
     {
         effectData = new ColoredGlyphEffectData(effect);
         return(false);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Changes the effect of a specific cell.
        /// </summary>
        /// <param name="cellIndex">Cell index to set the effect for.</param>
        /// <param name="effect">The effect to associate with the cell.</param>
        public void SetEffect(int cellIndex, ICellEffect effect)
        {
            ColoredGlyph cell = _backingSurface[cellIndex];

            if (effect != null)
            {
                ColoredGlyphEffectData workingEffect;

                if (effect.CloneOnAdd)
                {
                    effect        = effect.Clone();
                    workingEffect = new ColoredGlyphEffectData(effect);
                    _effects.Add(workingEffect.Effect, workingEffect);
                }
                else
                {
                    // Is the effect unknown? Add it.
                    if (GetKnownEffect(effect, out workingEffect) == false)
                    {
                        _effects.Add(workingEffect.Effect, workingEffect);
                    }
                    else
                    {
                        if (workingEffect.ContainsCell(cellIndex))
                        {
                            // Make sure the effect is attached to the cell.
                            return;
                        }
                    }
                }

                // Remove the targeted cell from the known cells list if it is already there (associated with another effect)
                ClearCellEffect(cellIndex);

                // Add the cell to the effects by cell key and to list of known cells for the effect
                _effectCells.Add(cellIndex, workingEffect);
                workingEffect.CellsStates.Add(new ColoredGlyphWithState(cell, cellIndex));
            }
            else
            {
                ClearCellEffect(cellIndex);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Changes the effect of the <paramref name="cellIndicies"/> provided.
        /// </summary>
        /// <param name="cellIndicies">A list of cell indicies to change the effect on.</param>
        /// <param name="effect">The effect to associate with the cell.</param>
        public void SetEffect(IEnumerable <int> cellIndicies, ICellEffect effect)
        {
            if (effect != null)
            {
                ColoredGlyphEffectData workingEffect;

                if (effect.CloneOnAdd)
                {
                    effect        = effect.Clone();
                    workingEffect = new ColoredGlyphEffectData(effect);
                    _effects.Add(workingEffect.Effect, workingEffect);
                }
                else
                {
                    // Is the effect unknown? Add it.
                    if (GetKnownEffect(effect, out workingEffect) == false)
                    {
                        _effects.Add(workingEffect.Effect, workingEffect);
                    }
                }

                foreach (int index in cellIndicies)
                {
                    if (!workingEffect.ContainsCell(index))
                    {
                        // Remove the targeted cell from the known cells list if it is already there (associated with another effect)
                        ClearCellEffect(index);

                        // Add the cell to the effects by cell key and to list of known cells for the effect
                        _effectCells.Add(index, workingEffect);
                        workingEffect.CellsStates.Add(new ColoredGlyphWithState(_backingSurface[index], index));
                    }
                }
            }
            else
            {
                foreach (int index in cellIndicies)
                {
                    ClearCellEffect(index);
                }
            }
        }