11package flixel .input .touch ;
22
33#if FLX_TOUCH
4+ import flixel .util .FlxDestroyUtil ;
45import openfl .Lib ;
56import openfl .events .TouchEvent ;
67import openfl .ui .Multitouch ;
@@ -9,6 +10,7 @@ import openfl.ui.MultitouchInputMode;
910/**
1011 * @author Zaphod
1112 */
13+ @:nullSafety (Strict )
1214class FlxTouchManager implements IFlxInputManager
1315{
1416 /**
@@ -34,24 +36,17 @@ class FlxTouchManager implements IFlxInputManager
3436 /**
3537 * WARNING: can be null if no active touch with the provided ID could be found
3638 */
37- public inline function getByID (TouchPointID : Int ): FlxTouch
39+ public inline function getByID (TouchPointID : Int ): Null < FlxTouch >
3840 {
3941 return _touchesCache .get (TouchPointID );
4042 }
4143
4244 /**
4345 * Return the first touch if there is one, beware of null
4446 */
45- public function getFirst (): FlxTouch
47+ public function getFirst (): Null < FlxTouch >
4648 {
47- if (list [0 ] != null )
48- {
49- return list [0 ];
50- }
51- else
52- {
53- return null ;
54- }
49+ return list [0 ];
5550 }
5651
5752 /**
@@ -60,19 +55,9 @@ class FlxTouchManager implements IFlxInputManager
6055 @:noCompletion
6156 public function destroy (): Void
6257 {
63- for (touch in list )
64- {
65- touch .destroy ();
66- }
67- list = null ;
68-
69- for (touch in _inactiveTouches )
70- {
71- touch .destroy ();
72- }
73- _inactiveTouches = null ;
74-
75- _touchesCache = null ;
58+ _touchesCache .clear ();
59+ FlxDestroyUtil .destroyArray (list );
60+ FlxDestroyUtil .destroyArray (_inactiveTouches );
7661 }
7762
7863 /**
@@ -119,7 +104,7 @@ class FlxTouchManager implements IFlxInputManager
119104 TouchArray = new Array <FlxTouch >();
120105 }
121106
122- var touchLen : Int = TouchArray .length ;
107+ final touchLen : Int = TouchArray .length ;
123108 if (touchLen > 0 )
124109 {
125110 TouchArray .splice (0 , touchLen );
@@ -141,10 +126,7 @@ class FlxTouchManager implements IFlxInputManager
141126 */
142127 public function reset (): Void
143128 {
144- for (key in _touchesCache .keys ())
145- {
146- _touchesCache .remove (key );
147- }
129+ _touchesCache .clear ();
148130
149131 for (touch in list )
150132 {
@@ -174,7 +156,7 @@ class FlxTouchManager implements IFlxInputManager
174156 */
175157 function handleTouchBegin (FlashEvent : TouchEvent ): Void
176158 {
177- var touch : FlxTouch = _touchesCache .get (FlashEvent .touchPointID );
159+ var touch : Null < FlxTouch > = _touchesCache .get (FlashEvent .touchPointID );
178160 if (touch != null )
179161 {
180162 touch .setXY (Std .int (FlashEvent .stageX ), Std .int (FlashEvent .stageY ));
@@ -192,7 +174,7 @@ class FlxTouchManager implements IFlxInputManager
192174 */
193175 function handleTouchEnd (FlashEvent : TouchEvent ): Void
194176 {
195- var touch : FlxTouch = _touchesCache .get (FlashEvent .touchPointID );
177+ final touch : Null < FlxTouch > = _touchesCache .get (FlashEvent .touchPointID );
196178
197179 if (touch != null )
198180 {
@@ -205,7 +187,7 @@ class FlxTouchManager implements IFlxInputManager
205187 */
206188 function handleTouchMove (FlashEvent : TouchEvent ): Void
207189 {
208- var touch : FlxTouch = _touchesCache .get (FlashEvent .touchPointID );
190+ final touch : Null < FlxTouch > = _touchesCache .get (FlashEvent .touchPointID );
209191
210192 if (touch != null )
211193 {
@@ -239,7 +221,8 @@ class FlxTouchManager implements IFlxInputManager
239221 {
240222 if (_inactiveTouches .length > 0 )
241223 {
242- var touch : FlxTouch = _inactiveTouches .pop ();
224+ @:nullSafety (Off )
225+ final touch : FlxTouch = _inactiveTouches .pop ();
243226 touch .recycle (X , Y , PointID , pressure );
244227 return add (touch );
245228 }
0 commit comments