1
+ package ;
2
+
3
+ import flixel .FlxG ;
4
+ import openfl .filters .BitmapFilter ;
5
+ import openfl .filters .ColorMatrixFilter ;
6
+
7
+ class ColorblindFilters {
8
+ // i honesly have no ideas how to make it, so i hope that works
9
+ public static var filterArray : Array <BitmapFilter > = [];
10
+ public static var filterMap : Map <String , {filter : BitmapFilter , ? onUpdate : Void -> Void }> = [
11
+
12
+ /*
13
+ I found these values in official haxe guides :D
14
+ */
15
+
16
+ " Deuteranopia" => {
17
+ var matrix : Array <Float > = [
18
+ 0.43 , 0.72 , - .15 , 0 , 0 ,
19
+ 0.34 , 0.57 , 0.09 , 0 , 0 ,
20
+ - .02 , 0.03 , 1 , 0 , 0 ,
21
+ 0 , 0 , 0 , 1 , 0 ,
22
+ ];
23
+
24
+ {filter : new ColorMatrixFilter (matrix )}
25
+ },
26
+ " Protanopia" => {
27
+ var matrix : Array <Float > = [
28
+ 0.20 , 0.99 , - .19 , 0 , 0 ,
29
+ 0.16 , 0.79 , 0.04 , 0 , 0 ,
30
+ 0.01 , - .01 , 1 , 0 , 0 ,
31
+ 0 , 0 , 0 , 1 , 0 ,
32
+ ];
33
+
34
+ {filter : new ColorMatrixFilter (matrix )}
35
+ },
36
+ " Tritanopia" => {
37
+ var matrix : Array <Float > = [
38
+ 0.97 , 0.11 , - .08 , 0 , 0 ,
39
+ 0.02 , 0.82 , 0.16 , 0 , 0 ,
40
+ 0.06 , 0.88 , 0.18 , 0 , 0 ,
41
+ 0 , 0 , 0 , 1 , 0 ,
42
+ ];
43
+
44
+ {filter : new ColorMatrixFilter (matrix )}
45
+ }
46
+ ];
47
+
48
+ public static function applyFiltersOnGame () {
49
+ filterArray = [];
50
+ FlxG .game .setFilters (filterArray );
51
+ if (ClientPrefs .colorblindMode != " None" ) { // actually self explanatory, isn't it?
52
+ if (filterMap .get (ClientPrefs .colorblindMode ) != null ) { // anticrash system
53
+ var thisF = filterMap .get (ClientPrefs .colorblindMode ).filter ;
54
+ if (thisF != null ) {
55
+ filterArray .push (thisF );
56
+ }
57
+ }
58
+ }
59
+ FlxG .game .setFilters (filterArray );
60
+ }
61
+ }
0 commit comments