Game Support: Clean up code a little

This commit is contained in:
rubenwardy 2024-07-04 20:25:48 +01:00
parent 813db2b8f9
commit a38a650dc1

@ -89,6 +89,9 @@ class GSPackage:
def unsupported_games(self) -> set[str]: def unsupported_games(self) -> set[str]:
return self.user_unsupported_games return self.user_unsupported_games
def add_error(self, error: str):
return self.errors.add(error)
class GameSupport: class GameSupport:
packages: Dict[str, GSPackage] packages: Dict[str, GSPackage]
@ -157,14 +160,14 @@ class GameSupport:
# Dep is game independent # Dep is game independent
pass pass
elif len(for_dep) == 0: elif len(for_dep) == 0:
package.errors.add(f"Unable to fulfill dependency {depend}") package.add_error(f"Unable to fulfill dependency {depend}")
return None return None
elif len(ret) == 0: elif len(ret) == 0:
ret = for_dep ret = for_dep
else: else:
ret.intersection_update(for_dep) ret.intersection_update(for_dep)
if len(ret) == 0: if len(ret) == 0:
package.errors.add("Game support conflict, unable to install package on any games") package.add_error("Game support conflict, unable to install package on any games")
return None return None
return ret return ret
@ -176,17 +179,17 @@ class GameSupport:
err = f"Dependency cycle detected: {' -> '.join(visited)} -> {package.id_}" err = f"Dependency cycle detected: {' -> '.join(visited)} -> {package.id_}"
for id_ in visited: for id_ in visited:
package2 = self.get(id_) package2 = self.get(id_)
package2.errors.add(err) package2.add_error(err)
return None return None
visited = visited.copy()
visited.append(package.id_)
if package.type == PackageType.GAME: if package.type == PackageType.GAME:
return {package.name} return {package.name}
elif package.is_confirmed: elif package.is_confirmed:
return package.supported_games return package.supported_games
else:
visited = visited.copy()
visited.append(package.id_)
ret = self._get_supported_games_for_deps(package, visited) ret = self._get_supported_games_for_deps(package, visited)
if ret is None: if ret is None:
assert len(package.errors) > 0 assert len(package.errors) > 0
@ -200,12 +203,12 @@ class GameSupport:
if len(ret) > 0: if len(ret) > 0:
for supported in package.user_supported_games: for supported in package.user_supported_games:
if supported not in ret: if supported not in ret:
package.errors.add(f"`{supported}` is specified in supported_games but it is impossible to run {package.name} in that game. " + package.add_error(f"`{supported}` is specified in supported_games but it is impossible to run {package.name} in that game. " +
f"Its dependencies can only be fulfilled in {', '.join([f'`{x}`' for x in ret])}. " + f"Its dependencies can only be fulfilled in {', '.join([f'`{x}`' for x in ret])}. " +
"Check your hard dependencies.") "Check your hard dependencies.")
if package.supports_all_games: if package.supports_all_games:
package.errors.add( package.add_error(
"This package cannot support all games as some dependencies require specific game(s): " + "This package cannot support all games as some dependencies require specific game(s): " +
", ".join([f'`{x}`' for x in ret])) ", ".join([f'`{x}`' for x in ret]))