Skip to content

Commit

Permalink
Merge pull request #1119 from rommapp/romm-1114
Browse files Browse the repository at this point in the history
[ROMM-1114] Fetch and use age ratings in UI and filters
  • Loading branch information
gantoine authored Sep 21, 2024
2 parents bca5520 + 8bf3ff6 commit 8a13611
Show file tree
Hide file tree
Showing 70 changed files with 365 additions and 89 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"python.testing.cwd": "${workspaceFolder}/backend",
"python.testing.pytestArgs": ["."],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
1 change: 1 addition & 0 deletions backend/endpoints/responses/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class RomSchema(BaseModel):
collections: list[str]
companies: list[str]
game_modes: list[str]
age_ratings: list[str]
igdb_metadata: RomIGDBMetadata | None
moby_metadata: RomMobyMetadata | None

Expand Down
1 change: 1 addition & 0 deletions backend/endpoints/tests/test_rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_update_rom(rename_file_mock, get_rom_by_id_mock, client, access_token,
"expanded_games": "[]",
"ports": "[]",
"similar_games": "[]",
"age_ratings": "[1, 2]",
},
)
assert response.status_code == 200
Expand Down
208 changes: 202 additions & 6 deletions backend/handler/metadata/igdb_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class IGDBPlatform(TypedDict):
name: NotRequired[str]


class IGDBAgeRating(TypedDict):
rating: str
category: str
rating_cover_url: str


class IGDBMetadataPlatform(TypedDict):
igdb_id: int
name: str
Expand All @@ -63,6 +69,7 @@ class IGDBMetadata(TypedDict):
collections: list[str]
companies: list[str]
game_modes: list[str]
age_ratings: list[IGDBAgeRating]
platforms: list[IGDBMetadataPlatform]
expansions: list[IGDBRelatedGame]
dlcs: list[IGDBRelatedGame]
Expand Down Expand Up @@ -105,6 +112,11 @@ def extract_metadata_from_igdb_rom(
IGDBMetadataPlatform(igdb_id=p.get("id", ""), name=p.get("name", ""))
for p in rom.get("platforms", [])
],
"age_ratings": [
IGDB_AGE_RATINGS[r["rating"]]
for r in rom.get("age_ratings", [])
if r["rating"] in IGDB_AGE_RATINGS
],
"expansions": [
IGDBRelatedGame(
id=e["id"],
Expand Down Expand Up @@ -556,21 +568,21 @@ async def get_matched_roms_by_name(
]

return [
IGDBRom( # type: ignore[misc]
{
IGDBRom(
{ # type: ignore[misc]
k: v
for k, v in {
"igdb_id": rom["id"],
"slug": rom["slug"],
"name": rom["name"],
"summary": rom.get("summary", ""),
"url_cover": self._normalize_cover_url(
rom.get("cover", {})
.get("url", "")
.replace("t_thumb", "t_cover_big")
pydash.get(rom, "cover.url", "").replace(
"t_thumb", "t_cover_big"
)
),
"url_screenshots": [
self._normalize_cover_url(s.get("url", ""))
self._normalize_cover_url(s.get("url", "")) # type: ignore[arg-type]
for s in rom.get("screenshots", [])
],
"igdb_metadata": extract_metadata_from_igdb_rom(rom),
Expand Down Expand Up @@ -693,6 +705,7 @@ async def get_oauth_token(self) -> str:
"similar_games.slug",
"similar_games.name",
"similar_games.cover.url",
"age_ratings.rating",
]

SEARCH_FIELDS = ["game.id", "name"]
Expand Down Expand Up @@ -921,3 +934,186 @@ async def get_oauth_token(self) -> str:
{"slug": "vc", "name": "Virtual Console"},
{"slug": "airconsole", "name": "AirConsole"},
]

IGDB_AGE_RATINGS: dict[int, IGDBAgeRating] = {
1: {
"rating": "Three",
"category": "PEGI",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/pegi/pegi_3.png",
},
2: {
"rating": "Seven",
"category": "PEGI",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/pegi/pegi_7.png",
},
3: {
"rating": "Twelve",
"category": "PEGI",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/pegi/pegi_12.png",
},
4: {
"rating": "Sixteen",
"category": "PEGI",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/pegi/pegi_16.png",
},
5: {
"rating": "Eighteen",
"category": "PEGI",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/pegi/pegi_18.png",
},
6: {
"rating": "RP",
"category": "ESRB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/esrb/esrb_rp.png",
},
7: {
"rating": "EC",
"category": "ESRB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/esrb/esrb_ec.png",
},
8: {
"rating": "E",
"category": "ESRB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/esrb/esrb_e.png",
},
9: {
"rating": "E10",
"category": "ESRB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/esrb/esrb_e10.png",
},
10: {
"rating": "T",
"category": "ESRB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/esrb/esrb_t.png",
},
11: {
"rating": "M",
"category": "ESRB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/esrb/esrb_m.png",
},
12: {
"rating": "AO",
"category": "ESRB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/esrb/esrb_ao.png",
},
13: {
"rating": "CERO_A",
"category": "CERO",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/cero/cero_a.png",
},
14: {
"rating": "CERO_B",
"category": "CERO",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/cero/cero_b.png",
},
15: {
"rating": "CERO_C",
"category": "CERO",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/cero/cero_c.png",
},
16: {
"rating": "CERO_D",
"category": "CERO",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/cero/cero_d.png",
},
17: {
"rating": "CERO_Z",
"category": "CERO",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/cero/cero_z.png",
},
18: {
"rating": "USK_0",
"category": "USK",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/usk/usk_0.png",
},
19: {
"rating": "USK_6",
"category": "USK",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/usk/usk_6.png",
},
20: {
"rating": "USK_12",
"category": "USK",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/usk/usk_12.png",
},
21: {
"rating": "USK_16",
"category": "USK",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/usk/usk_16.png",
},
22: {
"rating": "USK_18",
"category": "USK",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/usk/usk_18.png",
},
23: {
"rating": "GRAC_ALL",
"category": "GRAC",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/grac/grac_all.png",
},
24: {
"rating": "GRAC_Twelve",
"category": "GRAC",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/grac/grac_twelve.png",
},
25: {
"rating": "GRAC_Fifteen",
"category": "GRAC",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/grac/grac_fifteen.png",
},
26: {
"rating": "GRAC_Eighteen",
"category": "GRAC",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/grac/grac_eighteen.png",
},
27: {
"rating": "GRAC_TESTING",
"category": "GRAC",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/grac/grac_testing.png",
},
28: {
"rating": "CLASS_IND_L",
"category": "CLASS_IND",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/classind/classind_l.png",
},
29: {
"rating": "CLASS_IND_Ten",
"category": "CLASS_IND",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/classind/classind_ten.png",
},
30: {
"rating": "CLASS_IND_Twelve",
"category": "CLASS_IND",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/classind/classind_twelve.png",
},
31: {
"rating": "ACB_G",
"category": "ACB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/acb/acb_g.png",
},
32: {
"rating": "ACB_PG",
"category": "ACB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/acb/acb_pg.png",
},
33: {
"rating": "ACB_M",
"category": "ACB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/acb/acb_m.png",
},
34: {
"rating": "ACB_MA15",
"category": "ACB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/acb/acb_ma15.png",
},
35: {
"rating": "ACB_R18",
"category": "ACB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/acb/acb_r18.png",
},
36: {
"rating": "ACB_RC",
"category": "ACB",
"rating_cover_url": "https://www.igdb.com/icons/rating_icons/acb/acb_rc.png",
},
}
4 changes: 4 additions & 0 deletions backend/models/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ def companies(self) -> list[str]:
def game_modes(self) -> list[str]:
return self.igdb_metadata.get("game_modes", [])

@property
def age_ratings(self) -> list[str]:
return [r["rating"] for r in self.igdb_metadata.get("age_ratings", [])]

@property
def fs_resources_path(self) -> str:
return f"roms/{str(self.platform_id)}/{str(self.id)}"
Expand Down
1 change: 1 addition & 0 deletions backend/models/tests/rom_response_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
}
}
],
"age_ratings": [{ "rating": 1 }, { "rating": 2 }],
"expansions": [
{
"id": 239930,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/__generated__/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/__generated__/models/DetailedRomSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions frontend/src/__generated__/models/IGDBAgeRating.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/src/__generated__/models/RomIGDBMetadata.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/__generated__/models/RomSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/__generated__/models/SimpleRomSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ emitter?.on("showCreateUserDialog", () => {
show.value = true;
});
// Functions
async function createUser() {
await userApi
.createUser(user.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ emitter?.on("showEditUserDialog", (userToEdit) => {
show.value = true;
});
// Functions
function triggerFileInput() {
const fileInput = document.getElementById("file-input");
fileInput?.click();
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/Administration/Users/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const usersPerPage = ref(isNaN(storedUsersPerPage) ? 25 : storedUsersPerPage);
const pageCount = ref(0);
emitter?.on("updateDataTablePages", updateDataTablePages);
// Functions
function updateDataTablePages() {
pageCount.value = Math.ceil(usersStore.allUsers.length / usersPerPage.value);
}
Expand Down
Loading

0 comments on commit 8a13611

Please sign in to comment.