From e531998ddfb5b44bddd7415d07a199382222ea38 Mon Sep 17 00:00:00 2001 From: DragonAura Date: Sun, 22 Jan 2023 15:44:20 +0800 Subject: [PATCH] feat(CAPI): :sparkles: add api warn logger --- CAPI/API/src/DebugAPI.cpp | 165 +++++++++++++++++++++++++++----------- 1 file changed, 117 insertions(+), 48 deletions(-) diff --git a/CAPI/API/src/DebugAPI.cpp b/CAPI/API/src/DebugAPI.cpp index 8c22e2d..85a960f 100644 --- a/CAPI/API/src/DebugAPI.cpp +++ b/CAPI/API/src/DebugAPI.cpp @@ -88,9 +88,12 @@ int ButcherDebugAPI::GetFrameCount() const std::future HumanDebugAPI::Move(int64_t timeInMilliseconds, double angleInRadian) { - logger->info("Move: timeInMilliseconds = {}, angleInRadian = {}, at {}ms", timeInMilliseconds, angleInRadian, Time::TimeSinceStart(startPoint)); + logger->info("Move: timeInMilliseconds = {}, angleInRadian = {}, called at {}ms", timeInMilliseconds, angleInRadian, Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.Move(timeInMilliseconds, angleInRadian); }); + { auto result = logic.Move(timeInMilliseconds, angleInRadian); + if (!result) + logger->warn("Move: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future HumanDebugAPI::MoveDown(int64_t timeInMilliseconds) @@ -115,9 +118,12 @@ std::future HumanDebugAPI::MoveLeft(int64_t timeInMilliseconds) std::future ButcherDebugAPI::Move(int64_t timeInMilliseconds, double angleInRadian) { - logger->info("Move: timeInMilliseconds = {}, angleInRadian = {}, at {}ms", timeInMilliseconds, angleInRadian, Time::TimeSinceStart(startPoint)); + logger->info("Move: timeInMilliseconds = {}, angleInRadian = {}, called at {}ms", timeInMilliseconds, angleInRadian, Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.Move(timeInMilliseconds, angleInRadian); }); + { auto result = logic.Move(timeInMilliseconds, angleInRadian); + if (!result) + logger->warn("Move: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future ButcherDebugAPI::MoveDown(int64_t timeInMilliseconds) @@ -142,91 +148,127 @@ std::future ButcherDebugAPI::MoveLeft(int64_t timeInMilliseconds) std::future HumanDebugAPI::PickProp(THUAI6::PropType prop) { - logger->info("PickProp: prop = {}, at {}ms", THUAI6::propDict[prop], Time::TimeSinceStart(startPoint)); + logger->info("PickProp: prop = {}, called at {}ms", THUAI6::propDict[prop], Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.PickProp(prop); }); + { auto result = logic.PickProp(prop); + if (!result) + logger->warn("PickProp: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future HumanDebugAPI::UseProp() { - logger->info("UseProp: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("UseProp: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.UseProp(); }); + { auto result = logic.UseProp(); + if (!result) + logger->warn("UseProp: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future ButcherDebugAPI::PickProp(THUAI6::PropType prop) { - logger->info("PickProp: prop = {}, at {}ms", THUAI6::propDict[prop], Time::TimeSinceStart(startPoint)); + logger->info("PickProp: prop = {}, called at {}ms", THUAI6::propDict[prop], Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.PickProp(prop); }); + { auto result = logic.PickProp(prop); + if (!result) + logger->warn("PickProp: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future ButcherDebugAPI::UseProp() { - logger->info("UseProp: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("UseProp: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.UseProp(); }); + { auto result = logic.UseProp(); + if (!result) + logger->warn("UseProp: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future HumanDebugAPI::UseSkill() { - logger->info("UseSkill: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("UseSkill: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.UseSkill(); }); + { auto result = logic.UseSkill(); + if (!result) + logger->warn("UseSkill: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future ButcherDebugAPI::UseSkill() { - logger->info("UseSkill: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("UseSkill: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.UseSkill(); }); + { auto result = logic.UseSkill(); + if (!result) + logger->warn("UseSkill: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future HumanDebugAPI::SendMessage(int64_t toID, std::string message) { - logger->info("SendMessage: toID = {}, message = {}, at {}ms", toID, message, Time::TimeSinceStart(startPoint)); + logger->info("SendMessage: toID = {}, message = {}, called at {}ms", toID, message, Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.SendMessage(toID, message); }); + { auto result = logic.SendMessage(toID, message); + if (!result) + logger->warn("SendMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future ButcherDebugAPI::SendMessage(int64_t toID, std::string message) { - logger->info("SendMessage: toID = {}, message = {}, at {}ms", toID, message, Time::TimeSinceStart(startPoint)); + logger->info("SendMessage: toID = {}, message = {}, called at {}ms", toID, message, Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.SendMessage(toID, message); }); + { auto result = logic.SendMessage(toID, message); + if (!result) + logger->warn("SendMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future HumanDebugAPI::HaveMessage() { - logger->info("HaveMessage: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("HaveMessage: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.HaveMessage(); }); + { auto result = logic.HaveMessage(); + if (!result) + logger->warn("HaveMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future ButcherDebugAPI::HaveMessage() { - logger->info("HaveMessage: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("HaveMessage: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.HaveMessage(); }); + { auto result = logic.HaveMessage(); + if (!result) + logger->warn("HaveMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future>> HumanDebugAPI::GetMessage() { - logger->info("GetMessage: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("GetMessage: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.GetMessage(); }); + { auto result = logic.GetMessage(); + if (result == std::nullopt) + logger->warn("GetMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future>> ButcherDebugAPI::GetMessage() { - logger->info("GetMessage: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("GetMessage: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.GetMessage(); }); + { auto result = logic.GetMessage(); + if (result == std::nullopt) + logger->warn("GetMessage: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future HumanDebugAPI::Wait() { - logger->info("Wait: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("Wait: called at {}ms", Time::TimeSinceStart(startPoint)); if (logic.GetCounter() == -1) return std::async(std::launch::async, [&]() { return false; }); @@ -237,7 +279,7 @@ std::future HumanDebugAPI::Wait() std::future ButcherDebugAPI::Wait() { - logger->info("Wait: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("Wait: called at {}ms", Time::TimeSinceStart(startPoint)); if (logic.GetCounter() == -1) return std::async(std::launch::async, [&]() { return false; }); @@ -308,37 +350,52 @@ const std::vector ButcherDebugAPI::GetPlayerGUIDs() const std::future HumanDebugAPI::StartFixMachine() { - logger->info("StartFixMachine: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("StartFixMachine: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.StartFixMachine(); }); + { auto result = logic.StartFixMachine(); + if (!result) + logger->warn("StartFixMachine: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future HumanDebugAPI::EndFixMachine() { - logger->info("EndFixMachine: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("EndFixMachine: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.EndFixMachine(); }); + { auto result = logic.EndFixMachine(); + if (!result) + logger->warn("EndFixMachine: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future HumanDebugAPI::StartSaveHuman() { - logger->info("StartSaveHuman: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("StartSaveHuman: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.StartSaveHuman(); }); + { auto result = logic.StartSaveHuman(); + if (!result) + logger->warn("StartSaveHuman: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future HumanDebugAPI::EndSaveHuman() { - logger->info("EndSaveHuman: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("EndSaveHuman: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.EndSaveHuman(); }); + { auto result = logic.EndSaveHuman(); + if (!result) + logger->warn("EndSaveHuman: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future HumanDebugAPI::Escape() { - logger->info("Escape: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("Escape: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.Escape(); }); + { auto result = logic.Escape(); + if (!result) + logger->warn("Escape: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::shared_ptr HumanDebugAPI::GetSelfInfo() const @@ -348,30 +405,42 @@ std::shared_ptr HumanDebugAPI::GetSelfInfo() const std::future ButcherDebugAPI::Attack(double angleInRadian) { - logger->info("Attack: angleInRadian = {}, at {}ms", angleInRadian, Time::TimeSinceStart(startPoint)); + logger->info("Attack: angleInRadian = {}, called at {}ms", angleInRadian, Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.Attack(angleInRadian); }); + { auto result = logic.Attack(angleInRadian); + if (!result) + logger->warn("Attack: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future ButcherDebugAPI::CarryHuman() { - logger->info("CarryHuman: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("CarryHuman: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.CarryHuman(); }); + { auto result = logic.CarryHuman(); + if (!result) + logger->warn("CarryHuman: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future ButcherDebugAPI::ReleaseHuman() { - logger->info("ReleaseHuman: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("ReleaseHuman: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.ReleaseHuman(); }); + { auto result = logic.ReleaseHuman(); + if (!result) + logger->warn("ReleaseHuman: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::future ButcherDebugAPI::HangHuman() { - logger->info("HangHuman: at {}ms", Time::TimeSinceStart(startPoint)); + logger->info("HangHuman: called at {}ms", Time::TimeSinceStart(startPoint)); return std::async(std::launch::async, [&]() - { return logic.HangHuman(); }); + { auto result = logic.HangHuman(); + if (!result) + logger->warn("HangHuman: failed at {}ms", Time::TimeSinceStart(startPoint)); + return result; }); } std::shared_ptr ButcherDebugAPI::GetSelfInfo() const