From 39c4117927ad5ddf3a8694509140e67720eda45b Mon Sep 17 00:00:00 2001 From: Axel Cocat Date: Thu, 2 Mar 2023 00:02:33 +0100 Subject: [PATCH] feat: add AchievementEntry:GetName() (#104) --- src/LuaEngine/AchievementMethods.h | 33 +++++++++++++++++++++++++++++- src/LuaEngine/LuaFunctions.cpp | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/LuaEngine/AchievementMethods.h b/src/LuaEngine/AchievementMethods.h index a7d6559..e508f09 100644 --- a/src/LuaEngine/AchievementMethods.h +++ b/src/LuaEngine/AchievementMethods.h @@ -10,7 +10,7 @@ namespace LuaAchievement { /** - * Returns the [Achievement]s ID + * Returns the [Achievement]'s ID. * * @return uint32 id */ @@ -19,5 +19,36 @@ namespace LuaAchievement Eluna::Push(L, achievement->ID); return 1; } + + /** + * Returns the [Achievement]'s name. + * + * enum LocaleConstant + * { + * LOCALE_enUS = 0, + * LOCALE_koKR = 1, + * LOCALE_frFR = 2, + * LOCALE_deDE = 3, + * LOCALE_zhCN = 4, + * LOCALE_zhTW = 5, + * LOCALE_esES = 6, + * LOCALE_esMX = 7, + * LOCALE_ruRU = 8 + * }; + * + * @param [LocaleConstant] locale = DEFAULT_LOCALE : locale to return the [Achievement] name in + * @return string name + */ + int GetName(lua_State* L, AchievementEntry* const achievement) + { + uint8 locale = Eluna::CHECKVAL(L, 2, DEFAULT_LOCALE); + if (locale >= TOTAL_LOCALES) + { + return luaL_argerror(L, 2, "valid LocaleConstant expected"); + } + + Eluna::Push(L, achievement->name[locale]); + return 1; + } }; #endif diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index 1370f7f..de9fc65 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -1355,6 +1355,7 @@ ElunaRegister ChatHandlerMethods[] = ElunaRegister AchievementMethods[] = { { "GetId", &LuaAchievement::GetId }, + { "GetName", &LuaAchievement::GetName }, { NULL, NULL } };