diff src/core/anime.cc @ 202:71832ffe425a

animia: re-add kvm fd source this is all being merged from my wildly out-of-date laptop. SORRY! in other news, I edited the CI file to install the wayland client as well, so the linux CI build might finally get wayland stuff.
author Paper <paper@paper.us.eu.org>
date Tue, 02 Jan 2024 06:05:06 -0500
parents 975a3f0965e2
children 7cf53145de11
line wrap: on
line diff
--- a/src/core/anime.cc	Sun Nov 19 19:13:28 2023 -0500
+++ b/src/core/anime.cc	Tue Jan 02 06:05:06 2024 -0500
@@ -5,9 +5,8 @@
 #include "core/anime.h"
 #include "core/date.h"
 #include "core/session.h"
+
 #include <algorithm>
-#include <chrono>
-#include <cmath>
 #include <string>
 #include <vector>
 
@@ -43,6 +42,41 @@
 	return list_info_->score;
 }
 
+std::string Anime::GetUserPresentableScore() const {
+	assert(list_info_.get());
+	const int score = list_info_->score;
+	if (score == 0)
+		return "";
+
+	switch (session.config.anime_list.score_format) {
+		case ScoreFormat::POINT_10_DECIMAL:
+			return std::to_string(score / 10) + "." + std::to_string(score % 10);
+		case ScoreFormat::POINT_10:
+			return std::to_string(score / 10);
+		case ScoreFormat::POINT_5: {
+			std::string stars = "";
+
+			for (int i = 0; i < 100; i += 20)
+				stars.append((i <= score) ? "★" : "☆");
+
+			return stars;
+		}
+		case ScoreFormat::POINT_3: {
+			if (score >= 100)
+				return ":)";
+			else if (score >= 66)
+				return ":|";
+			else if (score >= 33)
+				return ":(";
+			else
+				return "";
+		}
+		default:
+		case ScoreFormat::POINT_100:
+			return std::to_string(score);
+	}
+}
+
 Date Anime::GetUserDateStarted() const {
 	assert(list_info_.get());
 	return list_info_->started;
@@ -147,18 +181,19 @@
 
 std::vector<std::string> Anime::GetTitleSynonyms() const {
 	std::vector<std::string> result;
-#define IN_VECTOR(v, k) (std::count(v.begin(), v.end(), k))
-#define ADD_TO_SYNONYMS(v, k) \
-	if (!k.empty() && !IN_VECTOR(v, k) && k != GetUserPreferredTitle()) \
-	v.push_back(k)
-	ADD_TO_SYNONYMS(result, info_.title.english);
-	ADD_TO_SYNONYMS(result, info_.title.romaji);
-	ADD_TO_SYNONYMS(result, info_.title.native);
-	for (auto& synonym : info_.synonyms) {
-		ADD_TO_SYNONYMS(result, synonym);
-	}
-#undef ADD_TO_SYNONYMS
-#undef IN_VECTOR
+
+	auto add_to_synonyms = [this](std::vector<std::string>& vec, std::string key) {
+		if (!key.empty() && !std::count(vec.begin(), vec.end(), key) && key != GetUserPreferredTitle())
+			vec.push_back(key);
+	};
+
+	add_to_synonyms(result, info_.title.english);
+	add_to_synonyms(result, info_.title.romaji);
+	add_to_synonyms(result, info_.title.native);
+
+	for (auto& synonym : info_.synonyms)
+		add_to_synonyms(result, synonym);
+
 	return result;
 }
 
@@ -207,6 +242,7 @@
 }
 
 std::string Anime::GetServiceUrl() const {
+	/* todo: add support for other services... */
 	return "https://anilist.co/anime/" + std::to_string(GetId());
 }