Add option to filter games not available on the current platform

The new 'Only show games available on this platform' checkbox in the
plugin settings drops games whose platforms don't include the OS
OpenGamepadUI is running on (e.g. Windows-only games on Linux). Games
with no platform info at all (HTML5) are kept since there's nothing to
filter on. The setting is read on every library load, so toggling it
reloads the itch.io library without a restart.
This commit is contained in:
Jose Falanga 2026-08-07 18:41:39 -03:00
parent f7d8f09f92
commit b0183b7c20
5 changed files with 56 additions and 3 deletions

View file

@ -3,6 +3,8 @@ extends Library
const ItchClient := preload("res://plugins/itch/core/itch_client.gd")
const _apps_cache_file: String = "apps.json"
var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager
@onready var itch: ItchClient = get_tree().get_first_node_in_group("itch_client")
## The item currently being installed/updated/uninstalled. OGPU's InstallManager
@ -84,13 +86,38 @@ func _on_install_progressed(_id: String, current: int, total: int) -> void:
install_progressed.emit(_active_item, float(current) / float(total))
## Returns true unless the "only show games available on this platform"
## filter is enabled and the game's platforms don't include the OS
## OpenGamepadUI is running on. Games with no platform info at all (e.g.
## HTML5) are kept, since there's nothing to filter on.
func _game_available_on_current_platform(game: Dictionary) -> bool:
if not _filter_unsupported():
return true
var platforms: Dictionary = game.get("platforms", {})
if platforms.is_empty():
return true
var current := "windows"
if OS.get_name() == "Linux":
current = "linux"
elif OS.get_name() == "macOS":
current = "osx"
return not (platforms.get(current, "") as String).is_empty()
func _filter_unsupported() -> bool:
return settings_manager.get_value("plugin.itch", "filter_unsupported", true) as bool
## Builds a LibraryLaunchItem for a game, or null when the entry isn't an
## actual game (itch.io also hosts tools, assets, soundtracks, comics, ...).
## actual game (itch.io also hosts tools, assets, soundtracks, comics, ...)
## or is filtered out by the "available on this platform" setting.
func _make_item(game: Dictionary, caves_by_game_id: Dictionary) -> Variant:
if game.is_empty():
return null
if game.get("classification", "game") != "game":
return null
if not _game_available_on_current_platform(game):
return null
var game_id: int = game.get("id", 0)
var cave: Dictionary = caves_by_game_id.get(game_id, {})
@ -121,7 +148,11 @@ func _load_library(caching_flags: int = Cache.FLAGS.LOAD | Cache.FLAGS.SAVE) ->
logger.info("itch.io apps found in cache. Using cache.")
var items := [] as Array[LibraryLaunchItem]
for i in json_items:
items.append(LibraryLaunchItem.from_dict(i))
var item := LibraryLaunchItem.from_dict(i)
var game: Dictionary = item.metadata.get("game", {})
if not _game_available_on_current_platform(game):
continue
items.append(item)
_queue_boxart(items)
return items