@@ -7,7 +7,7 @@ import flixel.math.FlxAngle;
77 * many `FlxObject` features like `allowCollisions` and `touching`.
88 * @since 4.10.0
99 */
10- enum abstract FlxDirectionFlags (Int ) from Int from FlxDirection to Int
10+ enum abstract FlxDirectionFlags (Int )
1111{
1212 var LEFT = 0x0001 ; // FlxDirection.LEFT;
1313 var RIGHT = 0x0010 ; // FlxDirection.RIGHT;
@@ -32,7 +32,18 @@ enum abstract FlxDirectionFlags(Int) from Int from FlxDirection to Int
3232
3333 /** Special-case constant meaning any, or all directions. */
3434 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+
3647 /**
3748 * Calculates the angle (in degrees) of the facing flags.
3849 * Returns 0 if two opposing flags are true.
@@ -41,7 +52,7 @@ enum abstract FlxDirectionFlags(Int) from Int from FlxDirection to Int
4152 public var degrees (get , never ): Float ;
4253 function get_degrees (): Float
4354 {
44- return switch ( this )
55+ return switch self
4556 {
4657 case RIGHT : 0 ;
4758 case DOWN : 90 ;
@@ -82,42 +93,63 @@ enum abstract FlxDirectionFlags(Int) from Int from FlxDirection to Int
8293 public var right (get , never ): Bool ;
8394 inline function get_right () return has (RIGHT );
8495
85-
96+ inline function new (value : Int )
97+ {
98+ this = value ;
99+ }
100+
86101 /**
87102 * Returns true if this contains **all** of the supplied flags.
88103 */
89104 public inline function has (dir : FlxDirectionFlags ): Bool
90105 {
91- return this & dir == dir ;
106+ return this & dir . toInt () == dir . toInt () ;
92107 }
93108
94109 /**
95110 * Returns true if this contains **any** of the supplied flags.
96111 */
97112 public inline function hasAny (dir : FlxDirectionFlags ): Bool
98113 {
99- return this & dir > 0 ;
114+ return this & dir . toInt () > 0 ;
100115 }
101116
102117 /**
103118 * Creates a new `FlxDirections` that includes the supplied directions.
104119 */
105120 public inline function with (dir : FlxDirectionFlags ): FlxDirectionFlags
106121 {
107- return this | dir ;
122+ return fromInt ( this | dir . toInt ()) ;
108123 }
109124
110125 /**
111126 * Creates a new `FlxDirections` that excludes the supplied directions.
112127 */
113128 public inline function without (dir : FlxDirectionFlags ): FlxDirectionFlags
114129 {
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 ()));
116136 }
117137
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+
118150 public function toString ()
119151 {
120- if (this == NONE )
152+ if (self == NONE )
121153 return " NONE" ;
122154
123155 var str = " " ;
@@ -146,16 +178,34 @@ enum abstract FlxDirectionFlags(Int) from Int from FlxDirection to Int
146178 | (down ? DOWN : NONE );
147179 }
148180
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+ }
151198
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" )
152202 @:op (A | B ) static function or (a : FlxDirectionFlags , b : FlxDirectionFlags ): FlxDirectionFlags ;
153-
203+ @ :deprecated ( " FlxDirectionFlags operators are deprecated, use has(), instead " )
154204 @:op (A > B ) static function gt (a : FlxDirectionFlags , b : FlxDirectionFlags ): Bool ;
155-
205+ @ :deprecated ( " FlxDirectionFlags operators are deprecated, use has(), instead " )
156206 @:op (A < B ) static function lt (a : FlxDirectionFlags , b : FlxDirectionFlags ): Bool ;
157-
207+ @ :deprecated ( " FlxDirectionFlags operators are deprecated, use has(), instead " )
158208 @:op (A >= B ) static function gte (a : FlxDirectionFlags , b : FlxDirectionFlags ): Bool ;
159-
209+ @ :deprecated ( " FlxDirectionFlags operators are deprecated, use has(), instead " )
160210 @:op (A <= B ) static function lte (a : FlxDirectionFlags , b : FlxDirectionFlags ): Bool ;
161211}
0 commit comments