Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for age rating metadata #941

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/backend/model/gaming/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct GameData {
QStringList genres;
QStringList tags;

QString age_rating;
short player_count = 1;
float rating = 0.0;
QDate release_date;
Expand Down Expand Up @@ -78,6 +79,7 @@ class Game : public QObject {
GETTER(const QString&, sortBy, sort_by)
GETTER(const QString&, summary, summary)
GETTER(const QString&, description, description)
GETTER(const QString&, ageRating, age_rating)
GETTER(const QDate&, releaseDate, release_date)
GETTER(int, playerCount, player_count)
GETTER(float, rating, rating)
Expand Down Expand Up @@ -109,6 +111,7 @@ class Game : public QObject {
SETTER(QString, SortBy, sort_by)
SETTER(QString, Summary, summary)
SETTER(QString, Description, description)
SETTER(QString, AgeRating, age_rating)
SETTER(QDate, ReleaseDate, release_date)

SETTER(QString, LaunchCmd, launch_params.launch_cmd)
Expand Down Expand Up @@ -139,6 +142,7 @@ class Game : public QObject {
Q_PROPERTY(QString sortBy READ sortBy CONSTANT)
Q_PROPERTY(QString summary READ summary CONSTANT)
Q_PROPERTY(QString description READ description CONSTANT)
Q_PROPERTY(QString age READ ageRating CONSTANT)
Q_PROPERTY(QDate release READ releaseDate CONSTANT)
Q_PROPERTY(int players READ playerCount CONSTANT)
Q_PROPERTY(float rating READ rating CONSTANT)
Expand Down
9 changes: 9 additions & 0 deletions src/backend/providers/pegasus_metadata/PegasusMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ enum class GameAttrib : unsigned char {
PLAYER_COUNT,
SHORT_DESC,
LONG_DESC,
AGE,
RELEASE,
RATING,
LAUNCH_CMD,
Expand Down Expand Up @@ -131,6 +132,7 @@ Metadata::Metadata(QString log_tag)
{ QStringLiteral("summary"), GameAttrib::SHORT_DESC },
{ QStringLiteral("description"), GameAttrib::LONG_DESC },
{ QStringLiteral("release"), GameAttrib::RELEASE },
{ QStringLiteral("age"), GameAttrib::AGE },
{ QStringLiteral("rating"), GameAttrib::RATING },
// sort title variations
{ QStringLiteral("sorttitle"), GameAttrib::SORT_BY },
Expand Down Expand Up @@ -369,6 +371,13 @@ void Metadata::apply_game_entry(ParserState& ps, const metafile::Entry& entry, S
ps.cur_game->setDescription(std::move(text));
}
break;
case GameAttrib::AGE:
{
QString text = metafile::merge_lines(entry.values);
replace_newlines(text);
ps.cur_game->setAgeRating(std::move(text));
}
break;
case GameAttrib::RELEASE:
{
const auto rx_match = rx_date.match(first_line_of(ps, entry));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ genres:
genre with spaces
sortby: Game IX
players: 2-4
age: 13+
rating: 80%
# repeating single keys will overwrite
release: 1998
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ genres: genre1, genre2,
players: 2-4

file: subdir/game_in_subdir.ext
age: 13+
rating: 80%
# repeating keys will overwrite previous values
release: 1998
Expand Down
1 change: 1 addition & 0 deletions tests/backend/providers/pegasus/test_PegasusProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ void test_PegasusProvider::with_meta()
QCOMPARE(game.genreListConst(), QStringList({"genre1", "genre2", "genre with spaces"}));
QCOMPARE(game.playerCount(), 4);
QCOMPARE(game.releaseDate(), QDate(1998, 5, 1));
QCOMPARE(game.ageRating(), QStringLiteral("13+"));
QCOMPARE(game.summary(), QStringLiteral("something short here"));
QCOMPARE(game.description(), QStringLiteral("a very long\n\ndescription"));
QCOMPARE(game.rating(), 0.8f);
Expand Down