diff --git a/sources/BaseAPI/API/Unflect/Tests/TEST_Unflect.uc b/sources/BaseAPI/API/Unflect/Tests/TEST_Unflect.uc index 0d0e674..ccb5206 100644 --- a/sources/BaseAPI/API/Unflect/Tests/TEST_Unflect.uc +++ b/sources/BaseAPI/API/Unflect/Tests/TEST_Unflect.uc @@ -1,6 +1,6 @@ /** * Set of tests for `Command` class. - * Copyright 2021 - 2022 Anton Tarasenko + * Copyright 2023 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * diff --git a/sources/Chat/ChatAPI.uc b/sources/Chat/ChatAPI.uc index 4a885c8..fbe7cbe 100644 --- a/sources/Chat/ChatAPI.uc +++ b/sources/Chat/ChatAPI.uc @@ -21,6 +21,88 @@ */ class ChatApi extends AcediaObject; +var private const int VOICE_MESSAGES_BEFORE_ACKNOWLEDGEMENTS; +var private const int VOICE_MESSAGES_BEFORE_ALERTS; +var private const int VOICE_MESSAGES_BEFORE_DIRECTIONS; +var private const int VOICE_MESSAGES_BEFORE_INSULTS; +var private const int VOICE_MESSAGES_BEFORE_TRADER; +var private const int VOICE_MESSAGES_BEFORE_AUTO; +var private const int VOICE_MESSAGES_TOTAL; + +enum BuiltInVoiceMessage { + // Support + BIVM_SupportMedic, + BIVM_SupportHelp, + BIVM_SupportAskForMoney, + BIVM_SupportAskForWeapon, + // Acknowledgements + BIVM_AckYes, + BIVM_AckNo, + BIVM_AckThanks, + BIVM_AckSorry, + // Alert + BIVM_AlretLookOut, + BIVM_AlretRun, + BIVM_AlretWaitForMe, + BIVM_AlretWeldTheDoors, + BIVM_AlretLetsHoleUpHere, + BIVM_AlretFollowMe, + // Direction + BIVM_DirectionGetToTheTrader, + BIVM_DirectionGoUpstairs, + BIVM_DirectionGoDownstairs, + BIVM_DirectionGetOutside, + BIVM_DirectionGetInside, + // Insult + BIVM_InsultSpecimens, + BIVM_InsultPlayers, + // Trader + BIVM_TraderCheckWhereTheShopIs, + BIVM_TraderGetClose, + BIVM_TraderShopOpen, + BIVM_TraderShopOpenFinal, + BIVM_Trader30SecondsUntilShopCloses, + BIVM_TraderShopClosed, + BIVM_TraderCompliment, + BIVM_TraderNotEnoughMoney, + BIVM_TraderCannotCarry, + BIVM_TraderHurryUp1, + BIVM_TraderHurryUp2, + // Auto + BIVM_AutoWelding, + BIVM_AutoUnwelding, + BIVM_AutoReload, + BIVM_AutoOutOfAmmo, + BIVM_AutoDosh, + BIVM_AutoStandStillTryingToHealYou, + BIVM_AutoLowOnHealth, + BIVM_AutoBloatAcid, + BIVM_AutoPatriarchCloack, + BIVM_AutoPatriarchMinigun, + BIVM_AutoPatriarchRocketLauncher, + BIVM_AutoGrabbedByClot, + BIVM_AutoFleashpoundSpotted, + BIVM_AutoGorefastSpotted, + BIVM_AutoScrakeSpotted, + BIVM_AutoSirenSpotten, + BIVM_AutoSirenScream, + BIVM_AutoStalkerSpotted, + BIVM_AutoCrawlertSpotted, + BIVM_AutoMeleeKilledAStalker, + BIVM_AutoUsingFlamethrower, + BIVM_AutoEquipHuntingShotgun, + BIVM_AutoEquipHandcannons, + BIVM_AutoEquipLAW, + BIVM_AutoEquipFireaxe, + // Fallback + BIVM_Unknown +}; + +struct NativeVoiceMessage { + var name type; + var byte index; +}; + var protected bool connectedToBroadcastAPI; var protected ChatAPI_OnMessage_Signal onMessageSignal; @@ -107,6 +189,93 @@ public /*signal*/ function ChatAPI_OnMessageFor_Slot OnMessageFor(AcediaObject r return ChatAPI_OnMessageFor_Slot(onMessageForSignal.NewSlot(receiver)); } +public /*internal*/ function NativeVoiceMessage _enumIntoNativeVoiceMessage( + BuiltInVoiceMessage voiceMessage +) { + local int enumValue; + local NativeVoiceMessage result; + + enumValue = int(voiceMessage); + if (enumValue < VOICE_MESSAGES_BEFORE_ACKNOWLEDGEMENTS) { + result.type = 'SUPPORT'; + result.index = enumValue; + } else if (enumValue < VOICE_MESSAGES_BEFORE_ALERTS) { + result.type = 'ACK'; + result.index = enumValue - VOICE_MESSAGES_BEFORE_ACKNOWLEDGEMENTS; + } else if (enumValue < VOICE_MESSAGES_BEFORE_DIRECTIONS) { + result.type = 'ALERT'; + result.index = enumValue - VOICE_MESSAGES_BEFORE_ALERTS; + } else if (enumValue < VOICE_MESSAGES_BEFORE_INSULTS) { + result.type = 'DIRECTION'; + result.index = enumValue - VOICE_MESSAGES_BEFORE_DIRECTIONS; + } else if (enumValue < VOICE_MESSAGES_BEFORE_TRADER) { + result.type = 'INSULT'; + result.index = enumValue - VOICE_MESSAGES_BEFORE_INSULTS; + } else if (enumValue < VOICE_MESSAGES_BEFORE_AUTO) { + result.type = 'TRADER'; + result.index = enumValue - VOICE_MESSAGES_BEFORE_TRADER; + if (result.index >= 5) { + result.index += 1; + } + } else if (enumValue < VOICE_MESSAGES_TOTAL) { + result.type = 'AUTO'; + result.index = enumValue - VOICE_MESSAGES_BEFORE_AUTO; + } + return result; +} + +public /*internal*/ function BuiltInVoiceMessage _nativeVoiceMessageIntoEnum( + NativeVoiceMessage voiceMessage +) { + switch (voiceMessage.type) { + case 'SUPPORT': + if (voiceMessage.index < 4) { + return BuiltInVoiceMessage(voiceMessage.index); + } + break; + case 'ACK': + if (voiceMessage.index < 4) { + return BuiltInVoiceMessage( + VOICE_MESSAGES_BEFORE_ACKNOWLEDGEMENTS + voiceMessage.index); + } + break; + case 'ALERT': + if (voiceMessage.index < 6) { + return BuiltInVoiceMessage(VOICE_MESSAGES_BEFORE_ALERTS + voiceMessage.index); + } + break; + case 'DIRECTION': + if (voiceMessage.index < 5) { + return BuiltInVoiceMessage(VOICE_MESSAGES_BEFORE_DIRECTIONS + voiceMessage.index); + } + break; + case 'INSULT': + if (voiceMessage.index < 2) { + return BuiltInVoiceMessage(VOICE_MESSAGES_BEFORE_INSULTS + voiceMessage.index); + } + break; + case 'TRADER': + if (voiceMessage.index < 12) { + if (voiceMessage.index < 5) { + return BuiltInVoiceMessage(VOICE_MESSAGES_BEFORE_TRADER + voiceMessage.index); + } else if (voiceMessage.index > 5) { + return BuiltInVoiceMessage( + VOICE_MESSAGES_BEFORE_TRADER + voiceMessage.index - 1); + } + } + break; + case 'AUTO': + if (voiceMessage.index < 25) { + return BuiltInVoiceMessage(VOICE_MESSAGES_BEFORE_AUTO + voiceMessage.index); + } + break; + default: + return BIVM_Unknown; + } + return BIVM_Unknown; +} + + private function bool HandleText( Actor sender, out string message, @@ -168,4 +337,11 @@ private function bool HandleTextFor( } defaultproperties { + VOICE_MESSAGES_BEFORE_ACKNOWLEDGEMENTS = 4 + VOICE_MESSAGES_BEFORE_ALERTS = 8 + VOICE_MESSAGES_BEFORE_DIRECTIONS = 14 + VOICE_MESSAGES_BEFORE_INSULTS = 19 + VOICE_MESSAGES_BEFORE_TRADER = 21 + VOICE_MESSAGES_BEFORE_AUTO = 32 + VOICE_MESSAGES_TOTAL = 57 } \ No newline at end of file diff --git a/sources/Chat/Tests/TEST_VoiceMessages.uc b/sources/Chat/Tests/TEST_VoiceMessages.uc new file mode 100644 index 0000000..45eb051 --- /dev/null +++ b/sources/Chat/Tests/TEST_VoiceMessages.uc @@ -0,0 +1,81 @@ +/** + * Set of tests for `Command` class. + * Copyright 2023 Anton Tarasenko + *------------------------------------------------------------------------------ + * This file is part of Acedia. + * + * Acedia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License, or + * (at your option) any later version. + * + * Acedia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Acedia. If not, see . + */ +class TEST_VoiceMessages extends TestCase + abstract + dependsOn(ChatApi); + +private static function ChatApi.NativeVoiceMessage Make(name type, int index) { + local ChatApi.NativeVoiceMessage result; + + result.type = type; + result.index = index; + return result; +} + +private static function TestEquality(name type, int index, ChatApi.BuiltInVoiceMessage builtIn) { + local ChatApi.NativeVoiceMessage nativeMessage; + + nativeMessage.type = type; + nativeMessage.index = index; + + Issue("Native voice messages are incorrectly converted into `BuiltInVoiceMessage`."); + TEST_ExpectTrue(__().chat._nativeVoiceMessageIntoEnum(nativeMessage) == builtIn); + + Issue("`BuiltInVoiceMessage`s are incorrectly converted into native voice messages."); + TEST_ExpectTrue(__().chat._enumIntoNativeVoiceMessage(builtIn).type == type); + TEST_ExpectTrue(__().chat._enumIntoNativeVoiceMessage(builtIn).index == index); +} + +protected static function TESTS() { + Context("Testing internal conversion methods between voice messages."); + Test_VoiceMessageConversion(); +} +protected static function Test_VoiceMessageConversion() { + local ChatApi.NativeVoiceMessage nothingMessage; + + nothingMessage.type = 'TRADER'; + nothingMessage.index = 5; + + TestEquality('SUPPORT', 2, BIVM_SupportAskForMoney); + TestEquality('ACK', 0, BIVM_AckYes); + TestEquality('ALERT', 5, BIVM_AlretFollowMe); + TestEquality('DIRECTION', 2, BIVM_DirectionGoDownstairs); + TestEquality('INSULT', 1, BIVM_InsultPlayers); + TestEquality('TRADER', 2, BIVM_TraderShopOpen); + TestEquality('TRADER', 4, BIVM_Trader30SecondsUntilShopCloses); + TestEquality('TRADER', 6, BIVM_TraderShopClosed); + TestEquality('TRADER', 7, BIVM_TraderCompliment); + TestEquality('TRADER', 11, BIVM_TraderHurryUp2); + TestEquality('AUTO', 0, BIVM_AutoWelding); + TestEquality('AUTO', 16, BIVM_AutoSirenScream); + TestEquality('AUTO', 24, BIVM_AutoEquipFireaxe); + + // Test unknown separately + Issue("Native voice messages are incorrectly converted into `BuiltInVoiceMessage`."); + TEST_ExpectTrue(__().chat._nativeVoiceMessageIntoEnum(nothingMessage) == BIVM_Unknown); + + Issue("`BuiltInVoiceMessage`s are incorrectly converted into native voice messages."); + TEST_ExpectTrue(__().chat._enumIntoNativeVoiceMessage(BIVM_Unknown).type == ''); + TEST_ExpectTrue(__().chat._enumIntoNativeVoiceMessage(BIVM_Unknown).index == 0); +} +defaultproperties { + caseName = "Voice messages" + caseGroup = "ChatAPI" +} \ No newline at end of file diff --git a/sources/Manifest.uc b/sources/Manifest.uc index ce9bd9c..760968f 100644 --- a/sources/Manifest.uc +++ b/sources/Manifest.uc @@ -60,4 +60,5 @@ defaultproperties testCases(31) = class'TEST_UTF8EncoderDecoder' testCases(32) = class'TEST_AvariceStreamReader' testCases(33) = class'TEST_Unflect' + testCases(34) = class'TEST_VoiceMessages' } \ No newline at end of file