1 module caLib.palettes.ColorListPalette;
2 
3 import caLib_util.structs : Color;
4 
5 
6 
7 auto create_ColorListPalette(Ct)(Color[Ct] colors)
8 {
9 	return create_ColorListPalette!(Ct)(colors, Color.init);
10 }
11 
12 
13 
14 auto create_ColorListPalette(Ct)(Color[Ct] colors, Color defaultValue)
15 {
16 	return new ColorListPalette!(Ct)(colors, defaultValue);
17 }
18 
19 
20 
21 struct ColorListPalette(Ct)
22 {
23 
24 private:
25 
26 	Color[Ct] colors;
27 	Color defaultValue;
28 
29 public:
30 
31 	alias CellStateType = Ct;
32 	alias DisplayValueType = Color;
33 
34 	this(Color[Ct] colors, Color defaultValue)
35 	{
36 		this.colors = colors;
37 		this.defaultValue = defaultValue;
38 	}
39 
40 	Color getDisplayValue(string behaviour)(Ct cellState)
41 	{
42 		static if(behaviour == "withDefaultValue")
43 		{
44 			return colors.get(cellState, defaultValue);
45 			//auto ptr = cellState in colors;
46 			//return ptr ? *ptr : defaultValue;
47 		}
48 		else static if(behaviour == "assumeEntryExists")
49 		{
50 			return colors[cellState];
51 		}
52 		else static if(behaviour == "_test")
53 		{
54 			return Color.init;
55 		}
56 		else
57 		{
58 			static assert(0, "ColorListPalette getDisplayValue method dosen't have a \""
59                 ~ behaviour ~"\" behaviour");
60 		}
61 	}
62 
63 	Color getDisplayValue()(Ct cellState)
64 	{
65 		return getDisplayValue!"withDefaultValue"(cellState);
66 	}
67 }
68 
69 version(unittest)
70 {
71 	import caLib_abstract.palette : isColorPalette;
72 }
73 
74 unittest
75 {
76 	static assert( isColorPalette!(ColorListPalette!(int), int));
77 }