1
1
package flixel .input .touch ;
2
2
3
3
#if FLX_TOUCH
4
+ import flixel .util .FlxDestroyUtil ;
4
5
import openfl .Lib ;
5
6
import openfl .events .TouchEvent ;
6
7
import openfl .ui .Multitouch ;
@@ -9,6 +10,7 @@ import openfl.ui.MultitouchInputMode;
9
10
/**
10
11
* @author Zaphod
11
12
*/
13
+ @:nullSafety (Strict )
12
14
class FlxTouchManager implements IFlxInputManager
13
15
{
14
16
/**
@@ -34,24 +36,17 @@ class FlxTouchManager implements IFlxInputManager
34
36
/**
35
37
* WARNING: can be null if no active touch with the provided ID could be found
36
38
*/
37
- public inline function getByID (TouchPointID : Int ): FlxTouch
39
+ public inline function getByID (TouchPointID : Int ): Null < FlxTouch >
38
40
{
39
41
return _touchesCache .get (TouchPointID );
40
42
}
41
43
42
44
/**
43
45
* Return the first touch if there is one, beware of null
44
46
*/
45
- public function getFirst (): FlxTouch
47
+ public function getFirst (): Null < FlxTouch >
46
48
{
47
- if (list [0 ] != null )
48
- {
49
- return list [0 ];
50
- }
51
- else
52
- {
53
- return null ;
54
- }
49
+ return list [0 ];
55
50
}
56
51
57
52
/**
@@ -60,19 +55,8 @@ class FlxTouchManager implements IFlxInputManager
60
55
@:noCompletion
61
56
public function destroy (): Void
62
57
{
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
+ FlxDestroyUtil .destroyArray (list );
59
+ FlxDestroyUtil .destroyArray (_inactiveTouches );
76
60
}
77
61
78
62
/**
@@ -88,7 +72,7 @@ class FlxTouchManager implements IFlxInputManager
88
72
TouchArray = new Array <FlxTouch >();
89
73
}
90
74
91
- var touchLen : Int = TouchArray .length ;
75
+ final touchLen : Int = TouchArray .length ;
92
76
93
77
if (touchLen > 0 )
94
78
{
@@ -119,7 +103,7 @@ class FlxTouchManager implements IFlxInputManager
119
103
TouchArray = new Array <FlxTouch >();
120
104
}
121
105
122
- var touchLen : Int = TouchArray .length ;
106
+ final touchLen : Int = TouchArray .length ;
123
107
if (touchLen > 0 )
124
108
{
125
109
TouchArray .splice (0 , touchLen );
@@ -141,10 +125,7 @@ class FlxTouchManager implements IFlxInputManager
141
125
*/
142
126
public function reset (): Void
143
127
{
144
- for (key in _touchesCache .keys ())
145
- {
146
- _touchesCache .remove (key );
147
- }
128
+ _touchesCache .clear ();
148
129
149
130
for (touch in list )
150
131
{
@@ -174,7 +155,7 @@ class FlxTouchManager implements IFlxInputManager
174
155
*/
175
156
function handleTouchBegin (FlashEvent : TouchEvent ): Void
176
157
{
177
- var touch : FlxTouch = _touchesCache .get (FlashEvent .touchPointID );
158
+ var touch : Null < FlxTouch > = _touchesCache .get (FlashEvent .touchPointID );
178
159
if (touch != null )
179
160
{
180
161
touch .setXY (Std .int (FlashEvent .stageX ), Std .int (FlashEvent .stageY ));
@@ -192,7 +173,7 @@ class FlxTouchManager implements IFlxInputManager
192
173
*/
193
174
function handleTouchEnd (FlashEvent : TouchEvent ): Void
194
175
{
195
- var touch : FlxTouch = _touchesCache .get (FlashEvent .touchPointID );
176
+ var touch : Null < FlxTouch > = _touchesCache .get (FlashEvent .touchPointID );
196
177
197
178
if (touch != null )
198
179
{
@@ -205,7 +186,7 @@ class FlxTouchManager implements IFlxInputManager
205
186
*/
206
187
function handleTouchMove (FlashEvent : TouchEvent ): Void
207
188
{
208
- var touch : FlxTouch = _touchesCache .get (FlashEvent .touchPointID );
189
+ var touch : Null < FlxTouch > = _touchesCache .get (FlashEvent .touchPointID );
209
190
210
191
if (touch != null )
211
192
{
@@ -239,6 +220,7 @@ class FlxTouchManager implements IFlxInputManager
239
220
{
240
221
if (_inactiveTouches .length > 0 )
241
222
{
223
+ @:nullSafety (Off )
242
224
var touch : FlxTouch = _inactiveTouches .pop ();
243
225
touch .recycle (X , Y , PointID , pressure );
244
226
return add (touch );
0 commit comments