perf: 迁移肉鸽主题、肉鸽主题检查

This commit is contained in:
status102
2023-11-14 21:00:05 +08:00
parent 9e6ceab9a6
commit a9b00f77f3
3 changed files with 15 additions and 10 deletions

View File

@@ -421,7 +421,4 @@ namespace asst
};
inline static const std::string UploadDataSource = "MeoAssistant";
inline static constexpr std::string_view RoguelikePhantomThemeName = "Phantom";
inline static constexpr std::string_view RoguelikeMizukiThemeName = "Mizuki";
inline static constexpr std::string_view RoguelikeSamiThemeName = "Sami";
} // namespace asst

View File

@@ -74,13 +74,8 @@ bool asst::RoguelikeTask::set_params(const json::value& params)
{
LogTraceFunction;
std::string theme = params.get("theme", std::string(RoguelikePhantomThemeName));
static constexpr std::array all_themes = {
RoguelikePhantomThemeName,
RoguelikeMizukiThemeName,
RoguelikeSamiThemeName,
};
if (ranges::find(all_themes, theme) == all_themes.end()) {
std::string theme = params.get("theme", std::string(RoguelikeTheme::Phantom));
if (RoguelikeConfig::is_valid_theme(theme)) {
m_roguelike_task_ptr->set_tasks({ "Stop" });
Log.error("Unknown roguelike theme", theme);
return false;

View File

@@ -16,8 +16,21 @@ namespace asst
Collectible = 4,
};
class RoguelikeTheme
{
public:
static constexpr std::string_view Phantom = "Phantom";
static constexpr std::string_view Mizuki = "Mizuki";
static constexpr std::string_view Sami = "Sami";
};
class RoguelikeConfig
{
public:
static constexpr bool is_valid_theme(std::string_view theme)
{
return theme == RoguelikeTheme::Phantom || theme == RoguelikeTheme::Mizuki || theme == RoguelikeTheme::Sami;
}
public:
// 清理缓存的肉鸽数据
void clear();