ソースを参照

Use `match` case instead of `if else` in Audio Mic Record demo (#1053)

* Use match case instead of if else

This is my first pull request.

* Apply suggestions from code review

---------

Co-authored-by: Hugo Locurcio <[email protected]>
Sectonidse 1 年間 前
コミット
8e9c180278
1 ファイル変更20 行追加18 行削除
  1. 20 18
      audio/mic_record/MicRecord.gd

+ 20 - 18
audio/mic_record/MicRecord.gd

@@ -59,29 +59,31 @@ func _on_SaveButton_pressed():
 
 
 
 
 func _on_MixRateOptionButton_item_selected(index: int) -> void:
 func _on_MixRateOptionButton_item_selected(index: int) -> void:
-	if index == 0:
-		mix_rate = 11025
-	elif index == 1:
-		mix_rate = 16000
-	elif index == 2:
-		mix_rate = 22050
-	elif index == 3:
-		mix_rate = 32000
-	elif index == 4:
-		mix_rate = 44100
-	elif index == 5:
-		mix_rate = 48000
+	match index:
+		0:
+			mix_rate = 11025
+		1:
+			mix_rate = 16000
+		2:
+			mix_rate = 22050
+		3:
+			mix_rate = 32000
+		4:
+			mix_rate = 44100
+		5:
+			mix_rate = 48000
 	if recording != null:
 	if recording != null:
 		recording.set_mix_rate(mix_rate)
 		recording.set_mix_rate(mix_rate)
 
 
 
 
 func _on_FormatOptionButton_item_selected(index: int) -> void:
 func _on_FormatOptionButton_item_selected(index: int) -> void:
-	if index == 0:
-		format = AudioStreamWAV.FORMAT_8_BITS
-	elif index == 1:
-		format = AudioStreamWAV.FORMAT_16_BITS
-	elif index == 2:
-		format = AudioStreamWAV.FORMAT_IMA_ADPCM
+	match index:
+		0:
+			format = AudioStreamWAV.FORMAT_8_BITS
+		1:
+			format = AudioStreamWAV.FORMAT_16_BITS
+		2:
+			format = AudioStreamWAV.FORMAT_IMA_ADPCM
 	if recording != null:
 	if recording != null:
 		recording.set_format(format)
 		recording.set_format(format)