@@ -20,6 +20,7 @@ import core.structures.ALEStageObjectsConfig;
2020import core .structures .ALESong ;
2121import core .structures .ALEHud ;
2222import core .structures .Point ;
23+ import core .plugins .ALEPluginsHandler ;
2324import core .enums .SongType ;
2425import core .enums .Rating ;
2526
@@ -33,6 +34,8 @@ import funkin.visuals.game.*;
3334import funkin .visuals .objects .Bar ;
3435import funkin .visuals .FXCamera ;
3536
37+ import api .MobileAPI ;
38+
3639class PlayState extends ScriptState
3740{
3841 public static var instance : PlayState ;
@@ -122,6 +125,8 @@ class PlayState extends ScriptState
122125 var totalNoteTypes : Array <String > = [];
123126 var totalEvents : Array <String > = [];
124127
128+ @:unreflective var hitboxes : FlxTypedGroup <Hitbox >;
129+
125130 override function create ()
126131 {
127132 instance = this ;
@@ -179,6 +184,44 @@ class PlayState extends ScriptState
179184 }
180185
181186 scriptCallbackCall (POST , ' Create' );
187+
188+ if (CoolVars .mobile )
189+ {
190+ MobileAPI .createButtons (100 , 100 , [{label : ' P' , keys : ClientPrefs .controls .ui .pause }]);
191+
192+ add (hitboxes = new FlxTypedGroup <Hitbox >());
193+
194+ createMobileHitboxes (playersStrumLines .members [0 ] ?? extrasStrumLines .members [0 ] ?? opponentsStrumLines .members [0 ]);
195+ }
196+ }
197+
198+ public function createMobileHitboxes (strumLine : StrumLine )
199+ {
200+ if (! CoolVars .mobile )
201+ return ;
202+
203+ hitboxes .clear ();
204+
205+ for (index => strum in strumLine .data .strums )
206+ {
207+ final keysArray : Array <Null <FlxKey >> = CoolUtil .getControl (strum .keybind [0 ], strum .keybind [1 ]);
208+
209+ final hitbox : Hitbox = new Hitbox (strumLine .data .strums .length , index ,
210+ () -> {
211+ for (key in keysArray )
212+ if (key != null )
213+ justPressedKey (new KeyboardEvent (' keyDown' , false , true , 0 , key ));
214+ },
215+ () -> {
216+ for (key in keysArray )
217+ if (key != null )
218+ justReleasedKey (new KeyboardEvent (' keyUp' , false , true , 0 , key ));
219+ }
220+ );
221+ hitbox .cameras = [ALEPluginsHandler .pluginsCamera ];
222+
223+ hitboxes .add (hitbox );
224+ }
182225 }
183226
184227 override function update (elapsed : Float )
@@ -658,6 +701,10 @@ class PlayState extends ScriptState
658701
659702 var strumLines : FlxTypedGroup <StrumLine >;
660703
704+ var opponentsStrumLines : FlxTypedGroup <StrumLine >;
705+ var playersStrumLines : FlxTypedGroup <StrumLine >;
706+ var extrasStrumLines : FlxTypedGroup <StrumLine >;
707+
661708 var strums : FlxTypedGroup <Strum >;
662709
663710 var characters : FlxTypedGroup <Character >;
@@ -711,6 +758,10 @@ class PlayState extends ScriptState
711758 players = new FlxTypedGroup <Character >();
712759 extras = new FlxTypedGroup <Character >();
713760
761+ opponentsStrumLines = new FlxTypedGroup <StrumLine >();
762+ playersStrumLines = new FlxTypedGroup <StrumLine >();
763+ extrasStrumLines = new FlxTypedGroup <StrumLine >();
764+
714765 strumLines .cameras = [camHUD ];
715766
716767 strums = new FlxTypedGroup <Strum >();
@@ -738,7 +789,7 @@ class PlayState extends ScriptState
738789
739790 strumLine .onMissNote = missNote ;
740791
741- strumLines . add (strumLine );
792+ addStrumLine (strumLine );
742793
743794 for (strum in strumLine .strums )
744795 strums .add (strum );
@@ -1035,6 +1086,30 @@ class PlayState extends ScriptState
10351086 function addBehindGroup (group : FlxTypedGroup <Dynamic >, obj : FlxBasic )
10361087 insert (members .indexOf (group .members [0 ]), obj );
10371088
1089+ function addStrumLine (strumLine : StrumLine )
1090+ {
1091+ if (scriptCallbackCall (ON , ' StrumLineAdd' , null , [strumLine ], []))
1092+ {
1093+ switch (strumLine .type )
1094+ {
1095+ case ' opponent' :
1096+ opponentsStrumLines .add (strumLine );
1097+
1098+ case ' player' :
1099+ playersStrumLines .add (strumLine );
1100+
1101+ case ' extra' :
1102+ extrasStrumLines .add (strumLine );
1103+
1104+ default :
1105+ }
1106+
1107+ strumLines .add (strumLine );
1108+ }
1109+
1110+ scriptCallbackCall (POST , ' StrumLineAdd' , null , [strumLine ], []);
1111+ }
1112+
10381113 function addCharacter (character : Character )
10391114 {
10401115 if (scriptCallbackCall (ON , ' CharacterAdd' , null , [character ], []))
@@ -1204,10 +1279,7 @@ class PlayState extends ScriptState
12041279 function justPressedKey (event : KeyboardEvent )
12051280 {
12061281 if (scriptCallbackCall (ON , ' JustPressedKey' , null , [event ], [event .keyCode ]))
1207- {
1208- if (FlxG .keys .firstJustPressed () > - 1 )
1209- strumLines .forEachAlive (strl -> strl .justPressedKey (event .keyCode ));
1210- }
1282+ strumLines .forEachAlive (strl -> strl .justPressedKey (event .keyCode ));
12111283
12121284 scriptCallbackCall (POST , ' JustPressedKey' , null , [event ], [event .keyCode ]);
12131285 }
0 commit comments