@@ -22,7 +22,7 @@ use ruffle_core::tag_utils::SwfMovie;
2222use ruffle_core:: { Player , PlayerEvent , StaticCallstack , ViewportDimensions } ;
2323use ruffle_web_common:: JsResult ;
2424use serde:: Serialize ;
25- use slotmap:: { new_key_type , SlotMap } ;
25+ use slotmap:: { SlotMap , new_key_type } ;
2626use std:: any:: Any ;
2727use std:: rc:: Rc ;
2828use std:: str:: FromStr ;
@@ -147,7 +147,7 @@ struct RuffleInstance {
147147}
148148
149149#[ wasm_bindgen( raw_module = "./internal/player/inner" ) ]
150- extern "C" {
150+ unsafe extern "C" {
151151 #[ derive( Clone ) ]
152152 pub type JavascriptPlayer ;
153153
@@ -159,7 +159,7 @@ extern "C" {
159159
160160 #[ wasm_bindgen( method, catch, js_name = "callFSCommand" ) ]
161161 fn call_fs_command ( this : & JavascriptPlayer , command : & str , args : & str )
162- -> Result < bool , JsValue > ;
162+ -> Result < bool , JsValue > ;
163163
164164 #[ wasm_bindgen( method) ]
165165 fn panic ( this : & JavascriptPlayer , error : & JsError ) ;
@@ -1110,57 +1110,54 @@ impl RuffleHandle {
11101110 ) ) ;
11111111 }
11121112
1113- if let Ok ( gamepads) = instance. window . navigator ( ) . get_gamepads ( ) {
1114- if let Some ( gamepad) = gamepads
1115- . into_iter ( )
1116- . next ( )
1117- . and_then ( |gamepad| gamepad. dyn_into :: < WebGamepad > ( ) . ok ( ) )
1118- {
1119- let mut pressed_buttons = Vec :: new ( ) ;
1120-
1121- let buttons = gamepad. buttons ( ) ;
1122- for ( index, button) in buttons. into_iter ( ) . enumerate ( ) {
1123- let Ok ( button) = button. dyn_into :: < WebGamepadButton > ( ) else {
1124- continue ;
1125- } ;
1113+ if let Ok ( gamepads) = instance. window . navigator ( ) . get_gamepads ( )
1114+ && let Some ( gamepad) = gamepads. into_iter ( ) . next ( )
1115+ && let Ok ( gamepad) = gamepad. dyn_into :: < WebGamepad > ( )
1116+ {
1117+ let mut pressed_buttons = Vec :: new ( ) ;
11261118
1127- if !button. pressed ( ) {
1128- continue ;
1129- }
1119+ let buttons = gamepad. buttons ( ) ;
1120+ for ( index, button) in buttons. into_iter ( ) . enumerate ( ) {
1121+ let Ok ( button) = button. dyn_into :: < WebGamepadButton > ( ) else {
1122+ continue ;
1123+ } ;
11301124
1131- // See https://w3c.github.io/gamepad/#remapping
1132- let gamepad_button = match index {
1133- 0 => GamepadButton :: South ,
1134- 1 => GamepadButton :: East ,
1135- 2 => GamepadButton :: West ,
1136- 3 => GamepadButton :: North ,
1137- 12 => GamepadButton :: DPadUp ,
1138- 13 => GamepadButton :: DPadDown ,
1139- 14 => GamepadButton :: DPadLeft ,
1140- 15 => GamepadButton :: DPadRight ,
1141- _ => continue ,
1142- } ;
1143-
1144- pressed_buttons. push ( gamepad_button) ;
1125+ if !button. pressed ( ) {
1126+ continue ;
11451127 }
11461128
1147- if pressed_buttons != instance. pressed_buttons {
1148- for button in pressed_buttons. iter ( ) {
1149- if !instance. pressed_buttons . contains ( button) {
1150- gamepad_button_events
1151- . push ( PlayerEvent :: GamepadButtonDown { button : * button } ) ;
1152- }
1153- }
1129+ // See https://w3c.github.io/gamepad/#remapping
1130+ let gamepad_button = match index {
1131+ 0 => GamepadButton :: South ,
1132+ 1 => GamepadButton :: East ,
1133+ 2 => GamepadButton :: West ,
1134+ 3 => GamepadButton :: North ,
1135+ 12 => GamepadButton :: DPadUp ,
1136+ 13 => GamepadButton :: DPadDown ,
1137+ 14 => GamepadButton :: DPadLeft ,
1138+ 15 => GamepadButton :: DPadRight ,
1139+ _ => continue ,
1140+ } ;
1141+
1142+ pressed_buttons. push ( gamepad_button) ;
1143+ }
11541144
1155- for button in instance. pressed_buttons . iter ( ) {
1156- if ! pressed_buttons. contains ( button ) {
1157- gamepad_button_events
1158- . push ( PlayerEvent :: GamepadButtonUp { button : * button } ) ;
1159- }
1145+ if pressed_buttons != instance. pressed_buttons {
1146+ for button in pressed_buttons. iter ( ) {
1147+ if !instance . pressed_buttons . contains ( button ) {
1148+ gamepad_button_events
1149+ . push ( PlayerEvent :: GamepadButtonDown { button : * button } ) ;
11601150 }
1151+ }
11611152
1162- instance. pressed_buttons = pressed_buttons;
1153+ for button in instance. pressed_buttons . iter ( ) {
1154+ if !pressed_buttons. contains ( button) {
1155+ gamepad_button_events
1156+ . push ( PlayerEvent :: GamepadButtonUp { button : * button } ) ;
1157+ }
11631158 }
1159+
1160+ instance. pressed_buttons = pressed_buttons;
11641161 }
11651162 }
11661163
@@ -1306,10 +1303,10 @@ fn parse_movie_parameters(input: &JsValue) -> Vec<(String, String)> {
13061303 let mut params = Vec :: new ( ) ;
13071304 if let Ok ( keys) = js_sys:: Reflect :: own_keys ( input) {
13081305 for key in keys. values ( ) . into_iter ( ) . flatten ( ) {
1309- if let Ok ( value) = js_sys:: Reflect :: get ( input, & key) {
1310- if let ( Some ( key) , Some ( value) ) = ( key. as_string ( ) , value. as_string ( ) ) {
1311- params . push ( ( key , value ) )
1312- }
1306+ if let Ok ( value) = js_sys:: Reflect :: get ( input, & key)
1307+ && let ( Some ( key) , Some ( value) ) = ( key. as_string ( ) , value. as_string ( ) )
1308+ {
1309+ params . push ( ( key , value ) )
13131310 }
13141311 }
13151312 }
0 commit comments