mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 14:37:36 +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():
|
for package in Package.query.filter(Package.type == PackageType.MOD, Package.state != PackageState.DELETED).all():
|
||||||
retval = self.resolve(package, [])
|
retval = self.resolve(package, [])
|
||||||
for game in retval:
|
for game in retval:
|
||||||
support = PackageGameSupport(package, game)
|
support = PackageGameSupport(package, game, 1)
|
||||||
db.session.add(support)
|
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] = {}
|
previous_supported: Dict[str, PackageGameSupport] = {}
|
||||||
for support in package.supported_games.all():
|
for support in package.supported_games.all():
|
||||||
|
db.session.merge(support.game)
|
||||||
previous_supported[support.game.getId()] = support
|
previous_supported[support.game.getId()] = support
|
||||||
|
|
||||||
retval = self.resolve(package, [])
|
for game in supported_games:
|
||||||
for game in retval:
|
|
||||||
assert game
|
assert game
|
||||||
|
|
||||||
lookup = previous_supported.pop(game.getId(), None)
|
lookup = previous_supported.pop(game.getId(), None)
|
||||||
if lookup is None:
|
if lookup is None:
|
||||||
support = PackageGameSupport(package, game)
|
support = PackageGameSupport(package, game, confidence)
|
||||||
db.session.add(support)
|
db.session.add(support)
|
||||||
elif lookup.confidence == 0:
|
elif lookup.confidence <= confidence:
|
||||||
lookup.supports = True
|
lookup.supports = True
|
||||||
|
lookup.confidence = confidence
|
||||||
db.session.merge(lookup)
|
db.session.merge(lookup)
|
||||||
|
|
||||||
for game, support in previous_supported.items():
|
for game, support in previous_supported.items():
|
||||||
if support.confidence == 0:
|
if support.confidence == confidence:
|
||||||
db.session.remove(support)
|
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"),)
|
__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.package = package
|
||||||
self.game = game
|
self.game = game
|
||||||
|
self.confidence = confidence
|
||||||
|
|
||||||
|
|
||||||
class Package(db.Model):
|
class Package(db.Model):
|
||||||
|
@ -116,9 +116,9 @@ def postReleaseCheckUpdate(self, release: PackageRelease, path):
|
|||||||
db.session.add(Dependency(package, meta=meta, optional=True))
|
db.session.add(Dependency(package, meta=meta, optional=True))
|
||||||
|
|
||||||
# Update game supports
|
# Update game supports
|
||||||
# if package.type == PackageType.MOD:
|
if package.type == PackageType.MOD:
|
||||||
# resolver = GameSupportResolver()
|
resolver = GameSupportResolver()
|
||||||
# resolver.update(package)
|
resolver.update(package)
|
||||||
|
|
||||||
# Update min/max
|
# Update min/max
|
||||||
if tree.meta.get("min_minetest_version"):
|
if tree.meta.get("min_minetest_version"):
|
||||||
|
@ -323,7 +323,7 @@
|
|||||||
{{ render_pkggrid(packages_uses) }}
|
{{ render_pkggrid(packages_uses) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if false %}
|
{% if package.type == package.type.GAME %}
|
||||||
<h2>{{ _("Content") }}</h2>
|
<h2>{{ _("Content") }}</h2>
|
||||||
<a href="{{ package.getURL('packages.game_hub') }}" class="btn btn-lg btn-primary">
|
<a href="{{ package.getURL('packages.game_hub') }}" class="btn btn-lg btn-primary">
|
||||||
{{ _("View content for game") }}
|
{{ _("View content for game") }}
|
||||||
@ -432,7 +432,7 @@
|
|||||||
</dl>
|
</dl>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if false %}
|
{% if package.type == package.type.MOD %}
|
||||||
<h3>{{ _("Compatible Games") }}</h3>
|
<h3>{{ _("Compatible Games") }}</h3>
|
||||||
<div style="max-height: 300px; overflow: hidden auto;">
|
<div style="max-height: 300px; overflow: hidden auto;">
|
||||||
{% for support in package.getSortedSupportedGames() %}
|
{% for support in package.getSortedSupportedGames() %}
|
||||||
|
Loading…
Reference in New Issue
Block a user