ColorStore

Namespace: Colorful.Console
We found 10 examples in language CSharp for this search. You will see 20 fragments of code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// custom serializable properties so that those data can be saved within a serializable object
/// </summary>
[System.Serializable]
public class SerializableColor
{

    public float[] colorStore = { 1F, 1F, 1F, 1F }; //new float[4]
    public Color Color
    {
        get { return new Color(colorStore[0], colorStore[1], colorStore[2], colorStore[3]); }
        set { colorStore = new float[4] { value.r, value.g, value.b, value.a }; }
    }

    //makes this class usable as Color, Color normalColor = mySerializableColor;
    public static implicit operator Color(SerializableColor instance)
    {
        return instance.Color;
    }

    //makes this class assignable by Color, SerializableColor myColor = Color.white;
    public static implicit operator SerializableColor(Color color)
    {
        return new SerializableColor { Color = color };
    }
}

[System.Serializable]
public class SerializableVector2
{

    public float[] vectorStore = { 1F, 1F }; //new float[2]
    public Vector2 Vector2
    {
        get { return new Vector2(vectorStore[0], vectorStore[1]); }
        set { vectorStore = new float [2] { value.x, value.y }; }
    }

    public static implicit operator Vector2(SerializableVector2 instance)
    {
        return instance.Vector2;
    }

    public static implicit operator SerializableVector2(Vector2 vector2)
    {
        return new SerializableVector2 { Vector2 = vector2 }; //creating instance while invoking the setter
    } 
}


      #endregion

      #region Public Methods and Operators

      /// <summary>Gets the System.Drawing.Color mapped to the ConsoleColor provided as an argument.</summary>
      /// <param name="color">The ConsoleColor alias under which the desired System.Drawing.Color is stored.</param>
      /// <returns>The corresponding System.Drawing.Color.</returns>
      public Color GetColor(ConsoleColor color)
      {
         return colorStore[color];
      }

      private ConsoleColor GetConsoleColorNative(Color color)
      {
         if (!CanChangeColor())
         {
            return colorStore.LastConsoleColor();
         }

         if (!colorStore.ContainsColor(color))
         {
            ConsoleColor oldColor = (ConsoleColor)colorChangeCount;

            colorMapper.MapColor(oldColor, color);
            colorStore.Update(color, oldColor);

            colorChangeCount++;
         }

         return colorStore[color];
      }


		void SyntaxCellRenderer (Gtk.CellLayout cell_layout, Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
		{
			var renderer = (Gtk.CellRendererText)cell;
			var data = (ColorScheme.PropertyDecsription)colorStore.GetValue (iter, 1);
			string markup = GLib.Markup.EscapeText (data.Attribute.Name);
			renderer.Markup = markup;
		}

		void ApplyStyle (ColorScheme sheme)
		{
			sheme.Name = entryName.Text;
			sheme.Description = entryDescription.Text;
			
			Gtk.TreeIter iter;
			if (colorStore.GetIterFirst (out iter)) {
				do {
					var data = (ColorScheme.PropertyDecsription)colorStore.GetValue (iter, 1);
					var style = (ChunkStyle)colorStore.GetValue (iter, 2);
					data.Info.SetValue (sheme, style, null);
				} while (colorStore.IterNext (ref iter));
			}
		}

using UnityEngine;

namespace Models
{
    [System.Serializable]
    public class SerializableColor
    {
        public float[] colorStore = {1F, 1F, 1F, 1F};

        public Color Color
        {
            get => new Color(colorStore[0], colorStore[1], colorStore[2], colorStore[3]);
            set { colorStore = new[] {value.r, value.g, value.b, value.a}; }
        }

        public static implicit operator Color(SerializableColor instance)
        {
            return instance.Color;
        }

        public static implicit operator SerializableColor(Color color)
        {
            return new SerializableColor {Color = color};
        }
    }
}

      #region Public Methods and Operators

      public ColorManager GetManager(ColorStore colorStore, int maxColorChanges, int initialColorChangeCountValue)
      {
         return new ColorManager(colorStore, GetColorMapper(), maxColorChanges, initialColorChangeCountValue);
      }

      public ColorManager GetManager
         (ConcurrentDictionary<Color, ConsoleColor> colorMap, ConcurrentDictionary<ConsoleColor, Color> consoleColorMap, int maxColorChanges, int initialColorChangeCountValue)
      {
         ColorStore colorStore = GetColorStore(colorMap, consoleColorMap);
         ColorMapper colorMapper = GetColorMapper();

         return new ColorManager(colorStore, colorMapper, maxColorChanges, initialColorChangeCountValue);
      }

      private ColorStore GetColorStore(ConcurrentDictionary<Color, ConsoleColor> colorMap, ConcurrentDictionary<ConsoleColor, Color> consoleColorMap)
      {
         return new ColorStore(colorMap, consoleColorMap);
      }


        public static ColorStore GetColorStore()
        {
            ColorStore colorStore = new ColorStore(new ConcurrentDictionary<Color, ConsoleColor>(), new ConcurrentDictionary<ConsoleColor, Color>());
            colorStore.Update(TEST_CONSOLE_COLOR, TEST_COLOR);

            return colorStore;
        }

        [Fact]
        public void RequiresUpdate_ReturnsFalse_IfColorStoreContainsColor()
        {
            ColorStore colorStore = GetColorStore();
            
            bool requiresUpdate = colorStore.RequiresUpdate(TEST_COLOR);

            Assert.False(requiresUpdate);
        }

        [Fact]
        public void RequiresUpdate_ReturnsTrue_IfColorStoreDoesNotContainColor()
        {
            ColorStore colorStore = GetColorStore();

            Color notInStore = Color.Red;
            bool requiresUpdate = colorStore.RequiresUpdate(notInStore);

            Assert.True(requiresUpdate);
        }


		void SyntaxCellRenderer (Gtk.CellLayout cell_layout, Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
		{
			var renderer = (Gtk.CellRendererText)cell;
			var data = (ColorScheme.PropertyDecsription)colorStore.GetValue (iter, 1);
			string markup = GLib.Markup.EscapeText (data.Attribute.Name);
			renderer.Markup = markup;
		}

		void ApplyStyle (ColorScheme sheme)
		{
			sheme.Name = entryName.Text;
			sheme.Description = entryDescription.Text;
			
			Gtk.TreeIter iter;
			if (colorStore.GetIterFirst (out iter)) {
				do {
					var data = (ColorScheme.PropertyDecsription)colorStore.GetValue (iter, 1);
					var style = colorStore.GetValue (iter, 2);
					data.Info.SetValue (sheme, style, null);
				} while (colorStore.IterNext (ref iter));
			}
		}


		void Stylechanged (object sender, EventArgs e)
		{
			Gtk.TreeIter iter;
			if (!this.treeviewColors.Selection.GetSelected (out iter))
				return;

			var o = colorStore.GetValue (iter, 2);

			if (o is ChunkStyle) {
				SetChunkStyle (iter, (ChunkStyle)o);
			} else if (o is AmbientColor) {
				SetAmbientColor (iter, (AmbientColor)o);
			}
		}


      #endregion

      #region Public Methods and Operators

      /// <summary>Gets the System.Drawing.Color mapped to the ConsoleColor provided as an argument.</summary>
      /// <param name="color">The ConsoleColor alias under which the desired System.Drawing.Color is stored.</param>
      /// <returns>The corresponding System.Drawing.Color.</returns>
      public Color GetColor(ConsoleColor color)
      {
         return colorStore[color];
      }


		void SyntaxCellRenderer (Gtk.CellLayout cell_layout, Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
		{
			var renderer = (Gtk.CellRendererText)cell;
			var data = (ColorScheme.PropertyDecsription)colorStore.GetValue (iter, 1);
			string markup = GLib.Markup.EscapeText (data.Attribute.Name);
			renderer.Markup = markup;
		}

		void ApplyStyle (ColorScheme sheme)
		{
			sheme.Name = entryName.Text;
			sheme.Description = entryDescription.Text;
			
			Gtk.TreeIter iter;
			if (colorStore.GetIterFirst (out iter)) {
				do {
					var data = (ColorScheme.PropertyDecsription)colorStore.GetValue (iter, 1);
					var style = colorStore.GetValue (iter, 2);
					data.Info.SetValue (sheme, style, null);
				} while (colorStore.IterNext (ref iter));
			}
		}


		void Stylechanged (object sender, EventArgs e)
		{
			Gtk.TreeIter iter;
			if (!this.treeviewColors.Selection.GetSelected (out iter))
				return;

			var o = colorStore.GetValue (iter, 2);

			if (o is ChunkStyle) {
				SetChunkStyle (iter, (ChunkStyle)o);
			} else if (o is AmbientColor) {
				SetAmbientColor (iter, (AmbientColor)o);
			}
		}

using UnityEngine;
using System.Collections.Generic;

[System.Serializable]
public class SerializableColor  //Clase necesaria para serializar colores :/
{

    public float[] colorStore = new float[4] { 1F, 1F, 1F, 1F };
    public Color Color
    {
        get { return new Color(colorStore[0], colorStore[1], colorStore[2], colorStore[3]); }
        set { colorStore = new float[4] { value.r, value.g, value.b, value.a }; }
    }

    public static implicit operator Color(SerializableColor instance)
    {
        return instance.Color;
    }

    public static implicit operator SerializableColor(Color color)
    {
        return new SerializableColor { Color = color };
    }
}

[System.Serializable]
public class ItemShop
{
    #region EXPOSED_FIELDS
    public string name;
    public SerializableColor hisColor;
    public int costToGet;
    public int idInShop;
    public bool alreadyBought;
    public bool selected;
    #endregion

    public ItemShop(ItemShop item)
    {
        hisColor = item.hisColor;
        costToGet = item.costToGet;
        alreadyBought = item.alreadyBought;
        selected = item.selected;
        name = item.name;
        idInShop = item.idInShop;
    }
}

[System.Serializable]
public class ItemsBoughtData
{
    public ItemShop[] items;

    public ItemsBoughtData(List<ItemShop> allItemsBuyed)
    {
        items = new ItemShop[allItemsBuyed.Count];

        for (int i = 0; i < items.Length; i++)
        {
            items[i] = allItemsBuyed[i];
        }
    }
}

Colorful.ColorStore : Object

Constructors :

public ColorStore(ConcurrentDictionary<Color, ConsoleColor> colorMap = , ConcurrentDictionary<ConsoleColor, Color> consoleColorMap = )

Methods :

public ConcurrentDictionary<Color, ConsoleColor> get_Colors()
public ConcurrentDictionary<ConsoleColor, Color> get_ConsoleColors()
public Void Update(ConsoleColor oldColor = , Color newColor = )
public ConsoleColor Replace(Color oldColor = , Color newColor = )
public Boolean RequiresUpdate(Color color = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()

Other methods