mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-08 22:17:34 +01:00
Fix and reenable game support
This commit is contained in:
parent
4adb209894
commit
f22911b4a0
@ -163,26 +163,36 @@ class GameSupportResolver:
|
||||
for package in Package.query.filter(Package.type == PackageType.MOD, Package.state != PackageState.DELETED).all():
|
||||
retval = self.resolve(package, [])
|
||||
for game in retval:
|
||||
support = PackageGameSupport(package, game)
|
||||
support = PackageGameSupport(package, game, 1)
|
||||
db.session.add(support)
|
||||
|
||||
def update(self, package: Package) -> None:
|
||||
"""
|
||||
Add supported game to a package, given the confidence.
|
||||
|
||||
Higher confidences outweigh lower ones.
|
||||
"""
|
||||
def add_supported(self, package: Package, supported_games: PackageSet, confidence: int):
|
||||
previous_supported: Dict[str, PackageGameSupport] = {}
|
||||
for support in package.supported_games.all():
|
||||
db.session.merge(support.game)
|
||||
previous_supported[support.game.getId()] = support
|
||||
|
||||
retval = self.resolve(package, [])
|
||||
for game in retval:
|
||||
for game in supported_games:
|
||||
assert game
|
||||
|
||||
lookup = previous_supported.pop(game.getId(), None)
|
||||
if lookup is None:
|
||||
support = PackageGameSupport(package, game)
|
||||
support = PackageGameSupport(package, game, confidence)
|
||||
db.session.add(support)
|
||||
elif lookup.confidence == 0:
|
||||
elif lookup.confidence <= confidence:
|
||||
lookup.supports = True
|
||||
lookup.confidence = confidence
|
||||
db.session.merge(lookup)
|
||||
|
||||
for game, support in previous_supported.items():
|
||||
if support.confidence == 0:
|
||||
db.session.remove(support)
|
||||
if support.confidence == confidence:
|
||||
db.session.delete(support)
|
||||
|
||||
def update(self, package: Package) -> None:
|
||||
retval = self.resolve(package, [])
|
||||
self.add_supported(package, retval, 1)
|
||||
|
@ -358,9 +358,10 @@ class PackageGameSupport(db.Model):
|
||||
|
||||
__table_args__ = (db.UniqueConstraint("game_id", "package_id", name="_package_game_support_uc"),)
|
||||
|
||||
def __init__(self, package, game):
|
||||
def __init__(self, package, game, confidence):
|
||||
self.package = package
|
||||
self.game = game
|
||||
self.confidence = confidence
|
||||
|
||||
|
||||
class Package(db.Model):
|
||||
|
@ -116,9 +116,9 @@ def postReleaseCheckUpdate(self, release: PackageRelease, path):
|
||||
db.session.add(Dependency(package, meta=meta, optional=True))
|
||||
|
||||
# Update game supports
|
||||
# if package.type == PackageType.MOD:
|
||||
# resolver = GameSupportResolver()
|
||||
# resolver.update(package)
|
||||
if package.type == PackageType.MOD:
|
||||
resolver = GameSupportResolver()
|
||||
resolver.update(package)
|
||||
|
||||
# Update min/max
|
||||
if tree.meta.get("min_minetest_version"):
|
||||
|
@ -323,7 +323,7 @@
|
||||
{{ render_pkggrid(packages_uses) }}
|
||||
{% endif %}
|
||||
|
||||
{% if false %}
|
||||
{% if package.type == package.type.GAME %}
|
||||
<h2>{{ _("Content") }}</h2>
|
||||
<a href="{{ package.getURL('packages.game_hub') }}" class="btn btn-lg btn-primary">
|
||||
{{ _("View content for game") }}
|
||||
@ -432,7 +432,7 @@
|
||||
</dl>
|
||||
{% endif %}
|
||||
|
||||
{% if false %}
|
||||
{% if package.type == package.type.MOD %}
|
||||
<h3>{{ _("Compatible Games") }}</h3>
|
||||
<div style="max-height: 300px; overflow: hidden auto;">
|
||||
{% for support in package.getSortedSupportedGames() %}
|
||||
|
Loading…
Reference in New Issue
Block a user