From 7f00b77db35d932c2fe4957fc72175f112b97535 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 25 Jun 2022 00:32:32 +0100 Subject: [PATCH] Add helpful page for game support --- app/blueprints/packages/__init__.py | 13 ++++- app/blueprints/packages/packages.py | 15 ++++++ app/flatpages/help.md | 1 + app/flatpages/help/game_support.md | 37 ++++++++++++++ app/models/packages.py | 8 ++- app/templates/packages/game_support.html | 64 ++++++++++++++++++++++++ app/templates/packages/view.html | 9 +++- 7 files changed, 142 insertions(+), 5 deletions(-) create mode 100644 app/flatpages/help/game_support.md create mode 100644 app/templates/packages/game_support.html diff --git a/app/blueprints/packages/__init__.py b/app/blueprints/packages/__init__.py index 47f471ca..35fb3a2e 100644 --- a/app/blueprints/packages/__init__.py +++ b/app/blueprints/packages/__init__.py @@ -17,7 +17,7 @@ from flask import Blueprint from flask_babel import gettext -from app.models import User, Package, Permission +from app.models import User, Package, Permission, PackageType bp = Blueprint("packages", __name__) @@ -26,7 +26,7 @@ def get_package_tabs(user: User, package: Package): if package is None or not package.checkPerm(user, Permission.EDIT_PACKAGE): return [] - return [ + retval = [ { "id": "edit", "title": gettext("Edit Details"), @@ -64,5 +64,14 @@ def get_package_tabs(user: User, package: Package): } ] + if package.type == PackageType.MOD: + retval.insert(1, { + "id": "game_support", + "title": gettext("Supported Games"), + "url": package.getURL("packages.game_support") + }) + + return retval + from . import packages, screenshots, releases, reviews, game_hub diff --git a/app/blueprints/packages/packages.py b/app/blueprints/packages/packages.py index 99898f61..e7e100ee 100644 --- a/app/blueprints/packages/packages.py +++ b/app/blueprints/packages/packages.py @@ -624,3 +624,18 @@ def similar(package): return render_template("packages/similar.html", package=package, packages_modnames=packages_modnames, similar_topics=similar_topics) + + +@bp.route("/packages///support/") +@login_required +@is_package_page +def game_support(package): + if package.type != PackageType.MOD: + abort(404) + + if not (package.checkPerm(current_user, Permission.EDIT_PACKAGE) or + package.checkPerm(current_user, Permission.APPROVE_NEW)): + abort(403) + + return render_template("packages/game_support.html", package=package, + tabs=get_package_tabs(current_user, package), current_tab="game_support") diff --git a/app/flatpages/help.md b/app/flatpages/help.md index 2eb481f1..cdcc9b7f 100644 --- a/app/flatpages/help.md +++ b/app/flatpages/help.md @@ -19,6 +19,7 @@ toc: False * [Git Update Detection](update_config) * [Creating Releases using Webhooks](release_webhooks) * [Package Configuration and Releases Guide](package_config) +* [Supported Games](game_support) ## Help for Specific User Ranks diff --git a/app/flatpages/help/game_support.md b/app/flatpages/help/game_support.md new file mode 100644 index 00000000..d38feae8 --- /dev/null +++ b/app/flatpages/help/game_support.md @@ -0,0 +1,37 @@ +title: Supported Games + +

+ This feature is experimental +

+ +## Why? + +The supported/compatible games feature allows mods to specify the games that they work with, which improves +user experience. + + +## Support sources + +### mod.conf + +You can use `supported_games` to specify games that your mod is compatible with. + +You can use `unsupported_games` to specify games that your mod doesn't work with, which is useful for overriding +ContentDB's automatic detection. + +Both of these are comma-separated lists of game technical ids. Any `_game` suffixes are ignored, just like in Minetest. + + supported_games = minetest_game, repixture + unsupported_games = lordofthetest, nodecore, whynot + +### Dependencies + +ContentDB will analyse hard dependencies and work out which games a mod supports. + +This uses a recursive algorithm that works out whether a dependency can be installed independently, or if it requires +a certain game. + + +## Combining all the sources + +mod.conf will override anything ContentDB detects. diff --git a/app/models/packages.py b/app/models/packages.py index cf5da522..ff362b20 100644 --- a/app/models/packages.py +++ b/app/models/packages.py @@ -506,8 +506,12 @@ class Package(db.Model): def getSortedOptionalDependencies(self): return self.getSortedDependencies(False) - def getSortedSupportedGames(self): - supported = self.supported_games.filter_by(supports=True).all() + def getSortedSupportedGames(self, include_unsupported=False): + query = self.supported_games + if not include_unsupported: + query = query.filter_by(supports=True) + + supported = query.all() supported.sort(key=lambda x: -(x.game.score + 100000*x.confidence)) return supported diff --git a/app/templates/packages/game_support.html b/app/templates/packages/game_support.html new file mode 100644 index 00000000..09a40347 --- /dev/null +++ b/app/templates/packages/game_support.html @@ -0,0 +1,64 @@ +{% extends "packages/package_base.html" %} + +{% block title %} +{{ _("Supported Games") }} +{% endblock %} + +{% block content %} +

{{ self.title() }}

+ +

+ + {{ _("Read more") }} + + {{ _("Support is determined based on dependencies and fields in mod.conf") }} +

+ + +{% endblock %} diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html index e252c6db..869da7c9 100644 --- a/app/templates/packages/view.html +++ b/app/templates/packages/view.html @@ -433,7 +433,14 @@ {% endif %} {% if package.type == package.type.MOD %} -

{{ _("Compatible Games") }}

+

+ {% if package.checkPerm(current_user, "EDIT_PACKAGE") %} + + + + {% endif %} + {{ _("Compatible Games") }} +

{% for support in package.getSortedSupportedGames() %}