@@ -7,7 +7,7 @@ import flixel.math.FlxAngle;
7
7
* many `FlxObject` features like `allowCollisions` and `touching`.
8
8
* @since 4.10.0
9
9
*/
10
- enum abstract FlxDirectionFlags (Int ) from Int from FlxDirection to Int
10
+ enum abstract FlxDirectionFlags (Int )
11
11
{
12
12
var LEFT = 0x0001 ; // FlxDirection.LEFT;
13
13
var RIGHT = 0x0010 ; // FlxDirection.RIGHT;
@@ -32,7 +32,18 @@ enum abstract FlxDirectionFlags(Int) from Int from FlxDirection to Int
32
32
33
33
/** Special-case constant meaning any, or all directions. */
34
34
var ANY = 0x1111 ; // LEFT | RIGHT | UP | DOWN;
35
-
35
+
36
+ var self (get , never ): FlxDirectionFlags ;
37
+
38
+ inline function get_self (): FlxDirectionFlags
39
+ {
40
+ #if (haxe >= version("4.3.0"))
41
+ return abstract ;
42
+ #else
43
+ return cast this ;
44
+ #end
45
+ }
46
+
36
47
/**
37
48
* Calculates the angle (in degrees) of the facing flags.
38
49
* Returns 0 if two opposing flags are true.
@@ -41,7 +52,7 @@ enum abstract FlxDirectionFlags(Int) from Int from FlxDirection to Int
41
52
public var degrees (get , never ): Float ;
42
53
function get_degrees (): Float
43
54
{
44
- return switch ( this )
55
+ return switch self
45
56
{
46
57
case RIGHT : 0 ;
47
58
case DOWN : 90 ;
@@ -82,42 +93,63 @@ enum abstract FlxDirectionFlags(Int) from Int from FlxDirection to Int
82
93
public var right (get , never ): Bool ;
83
94
inline function get_right () return has (RIGHT );
84
95
85
-
96
+ inline function new (value : Int )
97
+ {
98
+ this = value ;
99
+ }
100
+
86
101
/**
87
102
* Returns true if this contains **all** of the supplied flags.
88
103
*/
89
104
public inline function has (dir : FlxDirectionFlags ): Bool
90
105
{
91
- return this & dir == dir ;
106
+ return this & dir . toInt () == dir . toInt () ;
92
107
}
93
108
94
109
/**
95
110
* Returns true if this contains **any** of the supplied flags.
96
111
*/
97
112
public inline function hasAny (dir : FlxDirectionFlags ): Bool
98
113
{
99
- return this & dir > 0 ;
114
+ return this & dir . toInt () > 0 ;
100
115
}
101
116
102
117
/**
103
118
* Creates a new `FlxDirections` that includes the supplied directions.
104
119
*/
105
120
public inline function with (dir : FlxDirectionFlags ): FlxDirectionFlags
106
121
{
107
- return this | dir ;
122
+ return fromInt ( this | dir . toInt ()) ;
108
123
}
109
124
110
125
/**
111
126
* Creates a new `FlxDirections` that excludes the supplied directions.
112
127
*/
113
128
public inline function without (dir : FlxDirectionFlags ): FlxDirectionFlags
114
129
{
115
- return this & ~ dir ;
130
+ return fromInt (this & ~ dir .toInt ());
131
+ }
132
+
133
+ public inline function not (): FlxDirectionFlags
134
+ {
135
+ return fromInt ((~ this & ANY .toInt ()));
116
136
}
117
137
138
+ @:deprecated (" implicit cast from FlxDirectionFlags to Int is deprecated, use toInt" )
139
+ @:to
140
+ inline function toIntImplicit ()
141
+ {
142
+ return toInt ();
143
+ }
144
+
145
+ public inline function toInt (): Int
146
+ {
147
+ return this ;
148
+ }
149
+
118
150
public function toString ()
119
151
{
120
- if (this == NONE )
152
+ if (self == NONE )
121
153
return " NONE" ;
122
154
123
155
var str = " " ;
@@ -146,16 +178,34 @@ enum abstract FlxDirectionFlags(Int) from Int from FlxDirection to Int
146
178
| (down ? DOWN : NONE );
147
179
}
148
180
149
- // Expose int operators
150
- @:op (A & B ) static function and (a : FlxDirectionFlags , b : FlxDirectionFlags ): FlxDirectionFlags ;
181
+ @:deprecated (" implicit cast from Int to FlxDirectionFlags is deprecated, use FlxDirectionFlags.fromInt" )
182
+ @:from
183
+ inline static function fromIntImplicit (value : Int ): FlxDirectionFlags
184
+ {
185
+ return fromInt (value );
186
+ }
187
+
188
+ public inline static function fromInt (value : Int ): FlxDirectionFlags
189
+ {
190
+ return new FlxDirectionFlags (value );
191
+ }
192
+
193
+ @:from
194
+ inline static function fromDir (dir : FlxDirection ): FlxDirectionFlags
195
+ {
196
+ return fromInt (dir .toInt ());
197
+ }
151
198
199
+ @:deprecated (" FlxDirectionFlags operators are deprecated, use has(), instead" )// Expose int operators
200
+ @:op (A & B ) static function and (a : FlxDirectionFlags , b : FlxDirectionFlags ): FlxDirectionFlags ;
201
+ @:deprecated (" FlxDirectionFlags operators are deprecated, use has(), instead" )
152
202
@:op (A | B ) static function or (a : FlxDirectionFlags , b : FlxDirectionFlags ): FlxDirectionFlags ;
153
-
203
+ @ :deprecated ( " FlxDirectionFlags operators are deprecated, use has(), instead " )
154
204
@:op (A > B ) static function gt (a : FlxDirectionFlags , b : FlxDirectionFlags ): Bool ;
155
-
205
+ @ :deprecated ( " FlxDirectionFlags operators are deprecated, use has(), instead " )
156
206
@:op (A < B ) static function lt (a : FlxDirectionFlags , b : FlxDirectionFlags ): Bool ;
157
-
207
+ @ :deprecated ( " FlxDirectionFlags operators are deprecated, use has(), instead " )
158
208
@:op (A >= B ) static function gte (a : FlxDirectionFlags , b : FlxDirectionFlags ): Bool ;
159
-
209
+ @ :deprecated ( " FlxDirectionFlags operators are deprecated, use has(), instead " )
160
210
@:op (A <= B ) static function lte (a : FlxDirectionFlags , b : FlxDirectionFlags ): Bool ;
161
211
}
0 commit comments