Parcourir la source

Update default settings and colors

Colin Powell il y a 3 ans
Parent
commit
9ffd551943

+ 127 - 41
emus/settings.py

@@ -135,14 +135,6 @@ SCRAPER_SITE = os.getenv("EMUS_SCRAPER_SITE", "screenscraper")
 JSON_LOGGING = os.getenv("EMUS_JSON_LOGGING", False)
 LOG_TYPE = "json" if JSON_LOGGING else "log"
 
-RETROPIE_WEBRETRO_SYSTEM_MAP = {
-    "n64": "mupen64plus_next",
-    "nes": "nestopia",
-    "megadrive": "genesis_plus_gx",
-    "gba": "mgba",
-    "snes": "snes9x",
-}
-
 RETROPIE_RETROARCH_WEB_SYSTEM_MAP = {
     "3do": "opera",
     "atarijaguar": "virtualjaguar",
@@ -171,39 +163,132 @@ RETROPIE_RETROARCH_WEB_SYSTEM_MAP = {
     "wii": "dolphin",
 }
 
-GAME_SYSTEM_SLUG_MAP = {
-    "3do": "3DO",
-    "atarijaguar": "Atari Jaguar",
-    "atarilynx": "Atari Lynx",
-    "coleco": "Colecovision",
-    "dreamcast": "Dreamcast",
-    "fds": "Famicom Disc System",
-    "gb": "Game Boy",
-    "gba": "Game Boy Advance",
-    "gbc": "Game Boy Color",
-    "gc": "GameCube",
-    "mame-libretro": "Arcade",
-    "megadrive": "Genesis/Mega Drive",
-    "model3": "Sega Model 3",
-    "gamgear": "Game Gear",
-    "msx": "MSX",
-    "n64": "Nintendo 64",
-    "nds": "Nintendo DS",
-    "ngp": "Neo Geo Pocket",
-    "neogeo": "Neo Geo",
-    "ngpc": "Neo Geo Pocket Color",
-    "nes": "Nintendo",
-    "pcengine": "PC Engine/TurboGrafix 16",
-    "ps2": "Playstation 2",
-    "psp": "Playstation Portable",
-    "psx": "Playstation",
-    "ports": "Ports",
-    "saturn": "Saturn",
-    "scummvm": "ScummVM",
-    "sega32x": "Sega 32X",
-    "segacd": "Sega CD",
-    "snes": "Super Nintendo",
-    "wii": "Wii",
+GAME_SYSTEM_DEFAULTS = {
+    "3do": {
+        "name": "3DO",
+    },
+    "atarijaguar": {
+        "name": "Atari Jaguar",
+    },
+    "atarilynx": {
+        "name": "Atari Lynx",
+        "color": "FFBF00",
+    },
+    "coleco": {
+        "name": "Colecovision",
+    },
+    "dreamcast": {
+        "name": "Dreamcast",
+        "color": "ED872D",
+    },
+    "fds": {
+        "name": "Famicom Disc System",
+        "color": "B70E30",
+    },
+    "gb": {
+        "name": "Game Boy",
+        "color": "C0B8B1",
+    },
+    "gba": {
+        "name": "Game Boy Advance",
+        "color": "D5D5D5",
+        "webretro_core": "mgba",
+    },
+    "gbc": {
+        "name": "Game Boy Color",
+        "color": "",
+    },
+    "gc": {
+        "name": "GameCube",
+        "color": "7461C7",
+    },
+    "mame-libretro": {
+        "name": "Arcade",
+        "color": "111111",
+    },
+    "megadrive": {
+        "name": "Genesis/Mega Drive",
+        "color": "D03737",
+        "webretro_core": "genesis_plus_gx",
+    },
+    "model3": {
+        "name": "Sega Model 3",
+        "color": "",
+    },
+    "gamgear": {
+        "name": "Game Gear",
+        "color": "",
+    },
+    "msx": {
+        "name": "MSX",
+    },
+    "n64": {
+        "name": "Nintendo 64",
+        "color": "C76660",
+        "webretro_core": "mupen64plus_next",
+    },
+    "nds": {
+        "name": "Nintendo DS",
+        "color": "39D0D0",
+    },
+    "ngp": {
+        "name": "Neo Geo Pocket",
+    },
+    "neogeo": {
+        "name": "Neo Geo",
+    },
+    "ngpc": {
+        "name": "Neo Geo Pocket Color",
+    },
+    "nes": {"name": "Nintendo", "color": "656565", "webretro_core": "nestopia"},
+    "pcengine": {
+        "name": "PC Engine/TurboGrafix 16",
+        "color": "55B4CC",
+    },
+    "ps2": {
+        "name": "Playstation 2",
+        "color": "111CAA",
+    },
+    "psp": {
+        "name": "Playstation Portable",
+        "color": "",
+    },
+    "psx": {
+        "name": "Playstation",
+        "color": "E9DD00",
+    },
+    "ports": {
+        "name": "Ports",
+    },
+    "saturn": {
+        "name": "Saturn",
+        "color": "0047AB",
+    },
+    "scummvm": {
+        "name": "ScummVM",
+        "color": "E8B500",
+    },
+    "sega32x": {
+        "name": "Sega 32X",
+        "color": "",
+    },
+    "segacd": {
+        "name": "Sega CD",
+        "color": "",
+    },
+    "snes": {
+        "name": "Super Nintendo",
+        "color": "A060C7",
+        "webretro_core": "snes9x",
+    },
+    "virtualboy": {
+        "name": "Virtual Boy",
+        "color": "99AA11",
+    },
+    "wii": {
+        "name": "Wii",
+        "color": "",
+    },
 }
 
 default_level = "INFO"
@@ -274,6 +359,7 @@ LOGGING = {
         "daphne": {"handlers": ["file"], "propagate": False},
         "django.db.backends": {"handlers": ["null"]},
         "emus": {"handlers": ["console", "file"], "propagate": True},
+        "games": {"handlers": ["console", "file"], "propagate": True},
     },
 }
 

+ 18 - 12
games/management/commands/import_gamelist_xml_file.py

@@ -1,5 +1,5 @@
 from django.conf import settings
-from django.core.management.base import BaseCommand, CommandError
+from django.core.management.base import BaseCommand
 
 from games.utils import import_gamelist_file_to_db_for_system
 
@@ -22,23 +22,27 @@ class Command(BaseCommand):
 
     def import_from_slug(self, slug, file_path, full_scan=False):
         results = import_gamelist_file_to_db_for_system(slug, file_path, full_scan)
-    
+
         if not results:
-            self.style.ERROR("No games imported for {slug}, check for gamelist.xml file or re-run scraper")
+            self.style.ERROR(
+                "No games imported for {slug}, check for gamelist.xml file or re-run scraper"
+            )
             return
-    
+
         imported = results["imported"]
         not_imported = results["not_imported"]
-    
+
         if imported:
             self.stdout.write(
-                self.style.SUCCESS(f"Successfully imported {len(imported)} games for {slug}")
+                self.style.SUCCESS(
+                    f"Successfully imported {len(imported)} games for {slug}"
+                )
             )
         if not_imported:
             self.stdout.write(
                 self.style.SUCCESS(
                     f"Found, but did not update {len(not_imported)} games for {slug} (use --full-scan to update)"
-                    )
+                )
             )
         if not imported and not not_imported:
             self.stdout.write(
@@ -50,12 +54,14 @@ class Command(BaseCommand):
     def handle(self, *args, **options):
         game_system_slug = options["system"]
         if not game_system_slug:
-            self.style.ERROR("Please provide a game system slug, or all to import from all systems")
+            self.style.ERROR(
+                "Please provide a game system slug, or all to import from all systems"
+            )
             return False
         if game_system_slug == "all":
-            for slug in settings.GAME_SYSTEM_SLUG_MAP.keys():
+            for slug in settings.GAME_SYSTEM_DEFAULTS.keys():
                 self.import_from_slug(slug, options["file"], options["full_scan"])
         else:
-            self.import_from_slug(game_system_slug, options["file"], options["full_scan"])
-
-
+            self.import_from_slug(
+                game_system_slug, options["file"], options["full_scan"]
+            )

+ 7 - 3
games/management/commands/scrape_roms.py

@@ -17,10 +17,14 @@ class Command(BaseCommand):
             return False
 
         if game_system_slug == "all":
-            for slug in settings.GAME_SYSTEM_SLUG_MAP.keys():
+            for slug in settings.GAME_SYSTEM_DEFAULTS.keys():
                 scrape_out, load_out = skyscrape_console(slug)
-                self.stdout.write(self.style.SUCCESS(f"Successfully scraped roms for {slug}"))
+                self.stdout.write(
+                    self.style.SUCCESS(f"Successfully scraped roms for {slug}")
+                )
 
         else:
             scrape_out, load_out = skyscrape_console(game_system_slug)
-            self.stdout.write(self.style.SUCCESS("Successfully scraped roms for {slug}"))
+            self.stdout.write(
+                self.style.SUCCESS("Successfully scraped roms for {slug}")
+            )

+ 38 - 0
games/migrations/0014_alter_developer_options_alter_game_options_and_more.py

@@ -0,0 +1,38 @@
+# Generated by Django 4.0.3 on 2022-04-11 02:24
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('games', '0013_alter_game_screenshot'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='developer',
+            options={'ordering': ['name']},
+        ),
+        migrations.AlterModelOptions(
+            name='game',
+            options={'ordering': ['game_system', 'name']},
+        ),
+        migrations.AlterModelOptions(
+            name='gamesystem',
+            options={'ordering': ['name']},
+        ),
+        migrations.AlterModelOptions(
+            name='genre',
+            options={'ordering': ['name']},
+        ),
+        migrations.AlterModelOptions(
+            name='publisher',
+            options={'ordering': ['name']},
+        ),
+        migrations.AddField(
+            model_name='gamesystem',
+            name='color',
+            field=models.CharField(blank=True, help_text='Hex value for console badges', max_length=6, null=True),
+        ),
+    ]

+ 22 - 3
games/models.py

@@ -1,4 +1,3 @@
-from emus.settings import RETROPIE_WEBRETRO_SYSTEM_MAP
 from enum import Enum
 
 from django.conf import settings
@@ -72,10 +71,30 @@ class GameSystem(BaseModel):
         null=True,
         max_length=50,
     )
+    color = models.CharField(
+        blank=True,
+        null=True,
+        max_length=6,
+        help_text="Hex value for console badges",
+    )
+
+    @property
+    def defaults(self):
+        return settings.GAME_SYSTEM_DEFAULTS.get(self.retropie_slug, None)
+
+    @property
+    def get_color(self):
+        color = self.color
+        if not color and self.defaults:
+            color = self.defaults.get("color", "")
+        return color
 
     @property
     def webretro_core(self):
-        return settings.RETROPIE_WEBRETRO_SYSTEM_MAP.get(self.retropie_slug, None)
+        core = None
+        if self.defaults:
+            core = self.defaults.get("webretro_core", None)
+        return core
 
     def get_absolute_url(self):
         return reverse("games:game_system_detail", args=[self.slug])
@@ -195,5 +214,5 @@ class Game(BaseModel):
         return reverse("games:game_detail", args=[self.slug])
 
     def get_play_url(self):
-        if self.game_system.retropie_slug in RETROPIE_WEBRETRO_SYSTEM_MAP.keys():
+        if "webretro_core" in self.game_system.defaults.keys():
             return reverse("games:game_play_detail", args=[self.slug])

+ 4 - 3
games/utils.py

@@ -40,9 +40,10 @@ def import_gamelist_file_to_db_for_system(
     gamelist = ET.parse(file_path)
     game_system = GameSystem.objects.filter(retropie_slug=game_system_slug).first()
     if not game_system:
-        full_system_name = settings.GAME_SYSTEM_SLUG_MAP.get(
-            game_system_slug, game_system_slug
-        )
+        defaults = settings.GAME_SYSTM_DEFAULTS.get(game_system_slug, None)
+        full_system_name = game_system_slug
+        if defaults:
+            full_system_name = defaults.get("name", game_system_slug)
         game_system = GameSystem.objects.create(
             name=full_system_name, retropie_slug=game_system_slug
         )

+ 3 - 0
templates/base.html

@@ -32,6 +32,9 @@
          .card img { width:18em; padding: 1em; }
          .card-block { padding: 1em 0 1em 0; }
          .system-badge { padding: 1em; font-size: normal; }
+         {% for system in game_systems %}
+         .{{system.retropie_slug}} { background: #{{system.get_color}}; }
+         {% endfor %}
          .mame-libretro { background: #111111; }
          .gba { background: #D5D5D5; color:black;}
          .megadrive { background: #D03737; }

+ 1 - 1
templates/games/game_detail.html

@@ -38,6 +38,6 @@
 
     <p>{{object.description}}</p>
     {% if object.get_play_url  %}
-    <p><a href="{{game.get_play_url}}" class="btn btn-primary">Play</a></p>
+    <p><a href="{{game.get_play_url}}" class="btn btn-primary" targe="_blank">Play</a></p>
     {% endif %}
 {% endblock %}

+ 17 - 18
templates/games/game_play_detail.html

@@ -1,19 +1,18 @@
-{% extends "base.html" %}
 {% load static %}
-
-{% block head_extra %}
-    <script type="text/javascript" src="{% static 'js/webretro/embed/embed.js' %}"></script>
-{% endblock %}
-
-{% block title %}{{object.name}}{% endblock %}
-
-{% block content %}
-    <a href="{% url "games:game_list" %}">Back to list</a>
-
-    <div id="webretro-container" style="width:800px; height:600px"></div>
-    <script>webretroEmbed(document.getElementById("webretro-container"), "{% static 'js/webretro/index.html' %}", {core: "{{object.game_system.webretro_core}}", rom:"{{request.scheme}}://{{request.META.HTTP_HOST}}{{object.rom_file.url}}"});</script>
-    <p><a href="{{object.rom_file.url}}">Download ROM</a></p>
-
-    <p><img src={{object.screenshot.url}} /></p>
-
-{% endblock %}
+<!doctype html>
+<html class="no-js" lang="">
+    <head>
+        <title>{{game.name}}</title>
+        <meta charset="utf-8">
+        <meta http-equiv="x-ua-compatible" content="ie=edge">
+        <meta name="description" content="">
+        <meta name="viewport" content="width=device-width, initial-scale=1">
+        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
+        <script type="text/javascript" src="{% static 'js/webretro/embed/embed.js' %}"></script>
+    </head>
+    <body>
+        <div id="webretro-container" style="width:800px; height:600px"></div>
+        <script>webretroEmbed(document.getElementById("webretro-container"), "{% static 'js/webretro/index.html' %}", {core: "{{object.game_system.webretro_core}}", rom:"{{request.scheme}}://{{request.META.HTTP_HOST}}{{object.rom_file.url}}"});</script>
+        <p><a href="{{object.rom_file.url}}">Download ROM</a></p>
+    </body>
+</html>