diff --git a/OpenTaiko/src/Common/CConfigIni.cs b/OpenTaiko/src/Common/CConfigIni.cs index 854dda9a..0c30c321 100644 --- a/OpenTaiko/src/Common/CConfigIni.cs +++ b/OpenTaiko/src/Common/CConfigIni.cs @@ -3571,30 +3571,22 @@ namespace OpenTaiko { private void GetJoystickID(string keyDescription) { string[] strArray = keyDescription.Split(new char[] { ',' }); - if (strArray.Length >= 2) { - int result = 0; - if ((int.TryParse(strArray[0], out result) && (result >= 0)) && (result <= 9)) { - if (this.dicJoystick.ContainsKey(result)) { - this.dicJoystick.Remove(result); - } - - this.dicJoystick.Add(result, strArray[1]); - } + if (strArray.Length < 2 || !int.TryParse(strArray[0], out int result) || result < 0 || result > 9) { + return; } + + this.dicJoystick.Remove(result); + this.dicJoystick.Add(result, strArray[1]); } private void GetGamepadID(string keyDescription) { string[] strArray = keyDescription.Split(new char[] { ',' }); - if (strArray.Length >= 2) { - int result = 0; - if ((int.TryParse(strArray[0], out result) && (result >= 0)) && (result <= 9)) { - if (this.dicGamepad.ContainsKey(result)) { - this.dicGamepad.Remove(result); - } - - this.dicGamepad.Add(result, strArray[1]); - } + if (strArray.Length < 2 || !int.TryParse(strArray[0], out int result) || result < 0 || result > 9) { + return; } + + this.dicGamepad.Remove(result); + this.dicGamepad.Add(result, strArray[1]); } private void ClearAllKeyAssignments() { diff --git a/OpenTaiko/src/Common/CConstants.cs b/OpenTaiko/src/Common/CConstants.cs index 7215bdd4..e4f15419 100644 --- a/OpenTaiko/src/Common/CConstants.cs +++ b/OpenTaiko/src/Common/CConstants.cs @@ -345,23 +345,14 @@ namespace OpenTaiko { public T Unknown; public T this[int index] { get { - switch (index) { - case (int)EInstrumentPad.Drums: - return this.Drums; - - case (int)EInstrumentPad.Guitar: - return this.Guitar; - - case (int)EInstrumentPad.Bass: - return this.Bass; - - case (int)EInstrumentPad.Taiko: - return this.Taiko; - - case (int)EInstrumentPad.Unknown: - return this.Unknown; - } - throw new IndexOutOfRangeException(); + return index switch { + (int)EInstrumentPad.Drums => this.Drums, + (int)EInstrumentPad.Guitar => this.Guitar, + (int)EInstrumentPad.Bass => this.Bass, + (int)EInstrumentPad.Taiko => this.Taiko, + (int)EInstrumentPad.Unknown => this.Unknown, + _ => throw new IndexOutOfRangeException() + }; } set { switch (index) { diff --git a/OpenTaiko/src/Common/CHitSounds.cs b/OpenTaiko/src/Common/CHitSounds.cs index 4f542158..5aba9c99 100644 --- a/OpenTaiko/src/Common/CHitSounds.cs +++ b/OpenTaiko/src/Common/CHitSounds.cs @@ -11,12 +11,11 @@ if (id >= names.Length || id >= data.Length) return false; - string ext = ""; - - if (data[id].format == "WAV") - ext = ".wav"; - else if (data[id].format == "OGG") - ext = ".ogg"; + string ext = this.data[id].format switch { + "WAV" => ".wav", + "OGG" => ".ogg", + _ => "" + }; don[player] = data[id].path + "dong" + ext; ka[player] = data[id].path + "ka" + ext; @@ -45,15 +44,12 @@ private void tLoadFile(string path) { data = ConfigManager.GetConfig>(path).ToArray(); - names = new string[data.Length]; - for (int i = 0; i < data.Length; i++) { names[i] = data[i].name; } } #endregion - } } diff --git a/OpenTaiko/src/Common/CPad.cs b/OpenTaiko/src/Common/CPad.cs index 62fa3d80..2bc8d591 100644 --- a/OpenTaiko/src/Common/CPad.cs +++ b/OpenTaiko/src/Common/CPad.cs @@ -35,173 +35,174 @@ namespace OpenTaiko { // すべての入力デバイスについて… foreach (IInputDevice device in this.inputManager.InputDevices) { - if ((device.InputEvents != null) && (device.InputEvents.Count != 0)) { - foreach (STInputEvent event2 in device.InputEvents) { - for (int i = 0; i < stkeyassignArray.Length; i++) { - switch (stkeyassignArray[i].InputDevice) { - case EInputDevice.Keyboard: - if ((device.CurrentType == InputDeviceType.Keyboard) && (event2.nKey == stkeyassignArray[i].Code)) { - list.Add(event2); - this.detectedDevice.Keyboard = true; - } - break; + if (device.InputEvents == null || device.InputEvents.Count == 0) { + continue; + } - case EInputDevice.MIDIInput: - if (((device.CurrentType == InputDeviceType.MidiIn) && (device.ID == stkeyassignArray[i].ID)) && (event2.nKey == stkeyassignArray[i].Code)) { - list.Add(event2); - this.detectedDevice.MIDIIN = true; - } - break; + foreach (STInputEvent event2 in device.InputEvents) { + for (int i = 0; i < stkeyassignArray.Length; i++) { + switch (stkeyassignArray[i].InputDevice) { + case EInputDevice.Keyboard: + if ((device.CurrentType == InputDeviceType.Keyboard) && (event2.nKey == stkeyassignArray[i].Code)) { + list.Add(event2); + this.detectedDevice.Keyboard = true; + } + break; - case EInputDevice.Joypad: - if (((device.CurrentType == InputDeviceType.Joystick) && (device.ID == stkeyassignArray[i].ID)) && (event2.nKey == stkeyassignArray[i].Code)) { - list.Add(event2); - this.detectedDevice.Joypad = true; - } - break; + case EInputDevice.MIDIInput: + if (((device.CurrentType == InputDeviceType.MidiIn) && (device.ID == stkeyassignArray[i].ID)) && (event2.nKey == stkeyassignArray[i].Code)) { + list.Add(event2); + this.detectedDevice.MIDIIN = true; + } + break; - case EInputDevice.Gamepad: - if (((device.CurrentType == InputDeviceType.Gamepad) && (device.ID == stkeyassignArray[i].ID)) && (event2.nKey == stkeyassignArray[i].Code)) { - list.Add(event2); - this.detectedDevice.Gamepad = true; - } - break; + case EInputDevice.Joypad: + if (((device.CurrentType == InputDeviceType.Joystick) && (device.ID == stkeyassignArray[i].ID)) && (event2.nKey == stkeyassignArray[i].Code)) { + list.Add(event2); + this.detectedDevice.Joypad = true; + } + break; - case EInputDevice.Mouse: - if ((device.CurrentType == InputDeviceType.Mouse) && (event2.nKey == stkeyassignArray[i].Code)) { - list.Add(event2); - this.detectedDevice.Mouse = true; - } - break; - } + case EInputDevice.Gamepad: + if (((device.CurrentType == InputDeviceType.Gamepad) && (device.ID == stkeyassignArray[i].ID)) && (event2.nKey == stkeyassignArray[i].Code)) { + list.Add(event2); + this.detectedDevice.Gamepad = true; + } + break; + + case EInputDevice.Mouse: + if ((device.CurrentType == InputDeviceType.Mouse) && (event2.nKey == stkeyassignArray[i].Code)) { + list.Add(event2); + this.detectedDevice.Mouse = true; + } + break; } } } } return list; } + public bool bPressed(EInstrumentPad part, EPad pad) { - if (part != EInstrumentPad.Unknown) { + if (part == EInstrumentPad.Unknown) { + return false; + } - CConfigIni.CKeyAssign.STKEYASSIGN[] stkeyassignArray = this.rConfigIni.KeyAssign[(int)part][(int)pad]; - for (int i = 0; i < stkeyassignArray.Length; i++) { - switch (stkeyassignArray[i].InputDevice) { - case EInputDevice.Keyboard: - if (!this.inputManager.Keyboard.KeyPressed(stkeyassignArray[i].Code)) - break; + CConfigIni.CKeyAssign.STKEYASSIGN[] stkeyassignArray = this.rConfigIni.KeyAssign[(int)part][(int)pad]; + for (int i = 0; i < stkeyassignArray.Length; i++) { + switch (stkeyassignArray[i].InputDevice) { + case EInputDevice.Keyboard: + if (!this.inputManager.Keyboard.KeyPressed(stkeyassignArray[i].Code)) + break; - this.detectedDevice.Keyboard = true; - return true; + this.detectedDevice.Keyboard = true; + return true; - case EInputDevice.MIDIInput: { - IInputDevice device2 = this.inputManager.MidiIn(stkeyassignArray[i].ID); - if ((device2 == null) || !device2.KeyPressed(stkeyassignArray[i].Code)) - break; + case EInputDevice.MIDIInput: { + IInputDevice device2 = this.inputManager.MidiIn(stkeyassignArray[i].ID); + if (device2 == null || !device2.KeyPressed(stkeyassignArray[i].Code)) + break; - this.detectedDevice.MIDIIN = true; - return true; - } - case EInputDevice.Joypad: { - if (!this.rConfigIni.dicJoystick.ContainsKey(stkeyassignArray[i].ID)) - break; - - IInputDevice device = this.inputManager.Joystick(stkeyassignArray[i].ID); - if ((device == null) || !device.KeyPressed(stkeyassignArray[i].Code)) - break; - - this.detectedDevice.Joypad = true; - return true; - } - case EInputDevice.Gamepad: { - if (!this.rConfigIni.dicJoystick.ContainsKey(stkeyassignArray[i].ID)) - break; - - IInputDevice device = this.inputManager.Gamepad(stkeyassignArray[i].ID); - if ((device == null) || !device.KeyPressed(stkeyassignArray[i].Code)) - break; - - this.detectedDevice.Gamepad = true; - return true; - } - case EInputDevice.Mouse: - if (!this.inputManager.Mouse.KeyPressed(stkeyassignArray[i].Code)) - break; - - this.detectedDevice.Mouse = true; - return true; + this.detectedDevice.MIDIIN = true; + return true; } + case EInputDevice.Joypad: { + if (!this.rConfigIni.dicJoystick.ContainsKey(stkeyassignArray[i].ID)) + break; + + IInputDevice device = this.inputManager.Joystick(stkeyassignArray[i].ID); + if (device == null || !device.KeyPressed(stkeyassignArray[i].Code)) + break; + + this.detectedDevice.Joypad = true; + return true; + } + case EInputDevice.Gamepad: { + if (!this.rConfigIni.dicJoystick.ContainsKey(stkeyassignArray[i].ID)) + break; + + IInputDevice device = this.inputManager.Gamepad(stkeyassignArray[i].ID); + if (device == null || !device.KeyPressed(stkeyassignArray[i].Code)) + break; + + this.detectedDevice.Gamepad = true; + return true; + } + case EInputDevice.Mouse: + if (!this.inputManager.Mouse.KeyPressed(stkeyassignArray[i].Code)) + break; + + this.detectedDevice.Mouse = true; + return true; } } return false; } + public bool bPressedDGB(EPad pad) { if (!this.bPressed(EInstrumentPad.Drums, pad) && !this.bPressed(EInstrumentPad.Guitar, pad)) { return this.bPressed(EInstrumentPad.Bass, pad); } return true; } + public bool bPressedGB(EPad pad) { - if (!this.bPressed(EInstrumentPad.Guitar, pad)) { - return this.bPressed(EInstrumentPad.Bass, pad); - } - return true; + return this.bPressed(EInstrumentPad.Guitar, pad) || this.bPressed(EInstrumentPad.Bass, pad); } + public bool IsPressing(EInstrumentPad part, EPad pad) { - if (part != EInstrumentPad.Unknown) { - CConfigIni.CKeyAssign.STKEYASSIGN[] stkeyassignArray = this.rConfigIni.KeyAssign[(int)part][(int)pad]; - for (int i = 0; i < stkeyassignArray.Length; i++) { - switch (stkeyassignArray[i].InputDevice) { - case EInputDevice.Keyboard: - if (!this.inputManager.Keyboard.KeyPressing(stkeyassignArray[i].Code)) { - break; - } - this.detectedDevice.Keyboard = true; - return true; + if (part == EInstrumentPad.Unknown) { + return false; + } - case EInputDevice.Joypad: { - if (!this.rConfigIni.dicJoystick.ContainsKey(stkeyassignArray[i].ID)) { - break; - } - IInputDevice device = this.inputManager.Joystick(stkeyassignArray[i].ID); - if ((device == null) || !device.KeyPressing(stkeyassignArray[i].Code)) { - break; - } - this.detectedDevice.Joypad = true; - return true; - } + CConfigIni.CKeyAssign.STKEYASSIGN[] stkeyassignArray = this.rConfigIni.KeyAssign[(int)part][(int)pad]; + for (int i = 0; i < stkeyassignArray.Length; i++) { + switch (stkeyassignArray[i].InputDevice) { + case EInputDevice.Keyboard: + if (!this.inputManager.Keyboard.KeyPressing(stkeyassignArray[i].Code)) { + break; + } + this.detectedDevice.Keyboard = true; + return true; - case EInputDevice.Gamepad: { - if (!this.rConfigIni.dicJoystick.ContainsKey(stkeyassignArray[i].ID)) { - break; - } - IInputDevice device = this.inputManager.Gamepad(stkeyassignArray[i].ID); - if ((device == null) || !device.KeyPressing(stkeyassignArray[i].Code)) { - break; - } - this.detectedDevice.Gamepad = true; - return true; - } - case EInputDevice.Mouse: - if (!this.inputManager.Mouse.KeyPressing(stkeyassignArray[i].Code)) { - break; - } - this.detectedDevice.Mouse = true; - return true; + case EInputDevice.Joypad: { + if (!this.rConfigIni.dicJoystick.ContainsKey(stkeyassignArray[i].ID)) { + break; + } + IInputDevice device = this.inputManager.Joystick(stkeyassignArray[i].ID); + if (device == null || !device.KeyPressing(stkeyassignArray[i].Code)) { + break; + } + this.detectedDevice.Joypad = true; + return true; } + + case EInputDevice.Gamepad: { + if (!this.rConfigIni.dicJoystick.ContainsKey(stkeyassignArray[i].ID)) { + break; + } + IInputDevice device = this.inputManager.Gamepad(stkeyassignArray[i].ID); + if (device == null || !device.KeyPressing(stkeyassignArray[i].Code)) { + break; + } + this.detectedDevice.Gamepad = true; + return true; + } + case EInputDevice.Mouse: + if (!this.inputManager.Mouse.KeyPressing(stkeyassignArray[i].Code)) { + break; + } + this.detectedDevice.Mouse = true; + return true; } } return false; } + public bool IsPressingGB(EPad pad) { - if (!this.IsPressing(EInstrumentPad.Guitar, pad)) { - return this.IsPressing(EInstrumentPad.Bass, pad); - } - return true; + return this.IsPressing(EInstrumentPad.Guitar, pad) || this.IsPressing(EInstrumentPad.Bass, pad); } - - // その他 - #region [ private ] //----------------- private CConfigIni rConfigIni; diff --git a/OpenTaiko/src/Common/CTextConsole.cs b/OpenTaiko/src/Common/CTextConsole.cs index 0d003fa7..05867c03 100644 --- a/OpenTaiko/src/Common/CTextConsole.cs +++ b/OpenTaiko/src/Common/CTextConsole.cs @@ -13,24 +13,24 @@ namespace OpenTaiko { } public void Print(int x, int y, EFontType font, string alphanumericString) { - if (!base.IsDeActivated && !string.IsNullOrEmpty(alphanumericString)) { - int BOL = x; - for (int i = 0; i < alphanumericString.Length; i++) { - char ch = alphanumericString[i]; - if (ch == '\n') { - x = BOL; - y += this.fontHeight; - } else { - int index = printableCharacters.IndexOf(ch); - if (index < 0) { - x += this.fontWidth; - } else { - if (this.fontTextures[(int)((int)font / (int)EFontType.WhiteSlim)] != null) { - this.fontTextures[(int)((int)font / (int)EFontType.WhiteSlim)].t2D描画(x, y, this.characterRectangles[(int)((int)font % (int)EFontType.WhiteSlim), index]); - } - x += this.fontWidth; + if (base.IsDeActivated || string.IsNullOrEmpty(alphanumericString)) { + return; + } + + int BOL = x; + foreach (var ch in alphanumericString) { + if (ch == '\n') { + x = BOL; + y += this.fontHeight; + } else { + int index = printableCharacters.IndexOf(ch); + if (index >= 0) { + if (this.fontTextures[(int)((int)font / (int)EFontType.WhiteSlim)] != null) { + this.fontTextures[(int)((int)font / (int)EFontType.WhiteSlim)].t2D描画(x, y, this.characterRectangles[(int)((int)font % (int)EFontType.WhiteSlim), index]); } } + + x += this.fontWidth; } } } @@ -43,38 +43,44 @@ namespace OpenTaiko { } public override void CreateManagedResource() { - if (!base.IsDeActivated) { - this.fontTextures[0] = OpenTaiko.Tx.TxC(@"Console_Font.png"); - this.fontTextures[1] = OpenTaiko.Tx.TxC(@"Console_Font_Small.png"); - - this.fontWidth = this.fontTextures[0].szTextureSize.Width / 32; - this.fontHeight = this.fontTextures[0].szTextureSize.Height / 16; - - this.characterRectangles = new Rectangle[3, printableCharacters.Length]; - for (int i = 0; i < 3; i++) { - for (int j = 0; j < printableCharacters.Length; j++) { - int regionX = this.fontWidth * 16, regionY = this.fontHeight * 8; - this.characterRectangles[i, j].X = ((i / 2) * regionX) + ((j % 16) * this.fontWidth); - this.characterRectangles[i, j].Y = ((i % 2) * regionY) + ((j / 16) * this.fontHeight); - this.characterRectangles[i, j].Width = this.fontWidth; - this.characterRectangles[i, j].Height = this.fontHeight; - } - } - - base.CreateManagedResource(); + if (base.IsDeActivated) { + return; } + + this.fontTextures[0] = OpenTaiko.Tx.TxC(@"Console_Font.png"); + this.fontTextures[1] = OpenTaiko.Tx.TxC(@"Console_Font_Small.png"); + + this.fontWidth = this.fontTextures[0].szTextureSize.Width / 32; + this.fontHeight = this.fontTextures[0].szTextureSize.Height / 16; + + this.characterRectangles = new Rectangle[3, printableCharacters.Length]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < printableCharacters.Length; j++) { + int regionX = this.fontWidth * 16, regionY = this.fontHeight * 8; + this.characterRectangles[i, j].X = ((i / 2) * regionX) + ((j % 16) * this.fontWidth); + this.characterRectangles[i, j].Y = ((i % 2) * regionY) + ((j / 16) * this.fontHeight); + this.characterRectangles[i, j].Width = this.fontWidth; + this.characterRectangles[i, j].Height = this.fontHeight; + } + } + + base.CreateManagedResource(); } public override void ReleaseManagedResource() { - if (!base.IsDeActivated) { - for (int i = 0; i < 2; i++) { - if (this.fontTextures[i] != null) { - this.fontTextures[i].Dispose(); - this.fontTextures[i] = null; - } - } - base.ReleaseManagedResource(); + if (base.IsDeActivated) { + return; } + + for (int i = 0; i < 2; i++) { + if (this.fontTextures[i] == null) { + continue; + } + + this.fontTextures[i].Dispose(); + this.fontTextures[i] = null; + } + base.ReleaseManagedResource(); } #region [ private ]