1
0
mirror of synced 2025-01-18 17:14:07 +01:00

Early returns and Switch Expressions (#715)

* refactor: shorten getGamePad- getJoystickId

* refactor: use switch expression

* refactor: CPad early return & shortened bool returns

* refactor: CTextConsole
This commit is contained in:
Julian Holfeld 2024-10-22 17:57:25 +02:00 committed by GitHub
parent a38003bdb2
commit 12eec18ab9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 201 additions and 215 deletions

View File

@ -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() {

View File

@ -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) {

View File

@ -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<List<HitSoundsData>>(path).ToArray();
names = new string[data.Length];
for (int i = 0; i < data.Length; i++) {
names[i] = data[i].name;
}
}
#endregion
}
}

View File

@ -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;

View File

@ -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 ]