Example #1
0
            public static EffectsManager Load(string file, ISurface surface)
            {
                EffectsManagerSerialized data    = Serializer.Load <EffectsManagerSerialized>(file);
                EffectsManager           manager = new EffectsManager(surface);

                foreach (var effect in data.Effects.Keys)
                {
                    int[] effectCellIndexes = data.Effects[effect];

                    List <Cell> cells = new List <Cell>(effectCellIndexes.Length);

                    foreach (var index in effectCellIndexes)
                    {
                        cells.Add(surface.Cells[index]);
                    }

                    var effectData = new CellEffectData(effect)
                    {
                        Cells = cells
                    };

                    manager._effects.Add(effect, effectData);

                    foreach (var cell in cells)
                    {
                        manager._effectCells.Add(cell, effectData);
                    }
                }

                return(manager);
            }
        /// <summary>
        /// Changes the effect of the <paramref name="cells"/> provided.
        /// </summary>
        /// <param name="cells">Cells to change the effect on.</param>
        /// <param name="effect">The effect to associate with the cell.</param>
        public void SetEffect(IEnumerable <Cell> cells, ICellEffect effect)
        {
            var list = new List <Cell>(backingSurface.Cells);

            foreach (var cell in cells)
            {
                if (!list.Contains(cell))
                {
                    throw new Exception("Cell is not part of the surface used to create this effects manager.");
                }
            }


            if (effect != null)
            {
                CellEffectData workingEffect;

                if (effect.CloneOnApply)
                {
                    effect        = effect.Clone();
                    workingEffect = new CellEffectData(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 (var cell in cells)
                {
                    if (!workingEffect.Cells.Contains(cell))
                    {
                        // Remove the targeted cell from the known cells list if it is already there (associated with another effect)
                        ClearCellEffect(cell);

                        // Add the cell to the effects by cell key and to list of known cells for the effect
                        _effectCells.Add(cell, workingEffect);
                        cell.Effect = workingEffect.Effect;
                        workingEffect.Cells.Add(cell);
                    }
                    else    // Make sure the effect is attached to the cell.
                    {
                        cell.Effect = workingEffect.Effect;
                    }
                }
            }
            else
            {
                foreach (var cell in cells)
                {
                    ClearCellEffect(cell);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Removes an effect and associated cells from the manager.
        /// </summary>
        /// <param name="effect">Effect to remove.</param>
        public void Remove(ICellEffect effect)
        {
            CellEffectData data = _effects[effect];

            foreach (var cell in data.Cells)
            {
                ClearCellEffect(cell);
            }
        }
Example #4
0
 protected bool GetKnownEffect(ICellEffect effect, out CellEffectData effectData)
 {
     if (_effects.ContainsKey(effect))
     {
         effectData = _effects[effect];
         return(true);
     }
     else
     {
         effectData = new CellEffectData(effect);
         return(false);
     }
 }
Example #5
0
            public static EffectsManager Load(string file, ITextSurface surface)
            {
                EffectsManagerSerialized data = Serializer.Load<EffectsManagerSerialized>(file);
                EffectsManager manager = new EffectsManager(surface);

                foreach (var effect in data.Effects.Keys)
                {
                    int[] effectCellIndexes = data.Effects[effect];

                    List<Cell> cells = new List<Cell>(effectCellIndexes.Length);

                    foreach (var index in effectCellIndexes)
                        cells.Add(surface.Cells[index]);

                    var effectData = new CellEffectData(effect) { Cells = cells };

                    manager._effects.Add(effect, effectData);

                    foreach (var cell in cells)
                        manager._effectCells.Add(cell, effectData);
                }

                return manager;
            }
Example #6
0
 protected bool GetKnownEffect(ICellEffect effect, out CellEffectData effectData)
 {
     if (_effects.ContainsKey(effect))
     {
         effectData = _effects[effect];
         return true;
     }
     else
     {
         effectData = new CellEffectData(effect);
         return false;
     }
 }
Example #7
0
        /// <summary>
        /// Changes the effect of the <paramref name="cells"/> provided.
        /// </summary>
        /// <param name="cells">Cells to change the effect on.</param>
        /// <param name="effect">The effect to associate with the cell.</param>
        public void SetEffect(IEnumerable<Cell> cells, ICellEffect effect)
        {
            var list = new List<Cell>(backingSurface.Cells);
            foreach (var cell in cells)
            {
                if (!list.Contains(cell))
                    throw new Exception("Cell is not part of the surface used to create this effects manager.");
            }

            if (effect != null)
            {
                CellEffectData workingEffect;

                if (effect.CloneOnApply)
                {
                    effect = effect.Clone();
                    workingEffect = new CellEffectData(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 (var cell in cells)
                {
                    if (!workingEffect.Cells.Contains(cell))
                    {
                        // Remove the targeted cell from the known cells list if it is already there (associated with another effect)
                        ClearCellEffect(cell);

                        // Add the cell to the effects by cell key and to list of known cells for the effect
                        _effectCells.Add(cell, workingEffect);
                        cell.Effect = workingEffect.Effect;
                        workingEffect.Cells.Add(cell);
                    }
                    else    // Make sure the effect is attached to the cell.
                        cell.Effect = workingEffect.Effect;
                }
            }
            else
            {
                foreach (var cell in cells)
                    ClearCellEffect(cell);
            }
        }