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:
parent
f7d8f09f92
commit
b0183b7c20
5 changed files with 56 additions and 3 deletions
|
|
@ -18,6 +18,7 @@ const icon := preload("res://plugins/itch/assets/itch.svg")
|
|||
@onready var api_key_box: LineEdit = $%ApiKeyInput
|
||||
@onready var save_button: Button = $%SaveButton
|
||||
@onready var help_label: Label = $%HelpLabel
|
||||
@onready var filter_check: CheckBox = $%FilterUnsupported
|
||||
|
||||
@onready var itch: ItchClient = get_tree().get_first_node_in_group("itch_client")
|
||||
|
||||
|
|
@ -27,6 +28,8 @@ func _ready() -> void:
|
|||
api_key_box.text = api_key
|
||||
api_key_box.secret = true
|
||||
|
||||
filter_check.button_pressed = settings_manager.get_value("plugin.itch", "filter_unsupported", true) as bool
|
||||
|
||||
help_label.text = "Get an API key from https://itch.io/user/settings/api-keys"
|
||||
|
||||
_update_status()
|
||||
|
|
@ -34,6 +37,7 @@ func _ready() -> void:
|
|||
itch.logged_in.connect(_on_login)
|
||||
|
||||
save_button.pressed.connect(_on_save_button)
|
||||
filter_check.toggled.connect(_on_filter_toggled)
|
||||
|
||||
|
||||
func _update_status() -> void:
|
||||
|
|
@ -68,3 +72,13 @@ func _on_save_button() -> void:
|
|||
if api_key == "":
|
||||
return
|
||||
itch.login_with_api_key(api_key)
|
||||
|
||||
|
||||
## Persists the platform filter and reloads the itch.io library so the
|
||||
## change applies without restarting. The setting is read back by
|
||||
## library_itch.gd on every library load, so toggling just re-filters.
|
||||
func _on_filter_toggled(pressed: bool) -> void:
|
||||
settings_manager.set_value("plugin.itch", "filter_unsupported", pressed)
|
||||
var library_manager := load("res://core/global/library_manager.tres") as LibraryManager
|
||||
if library_manager:
|
||||
library_manager.load_library("itch")
|
||||
|
|
|
|||
|
|
@ -42,6 +42,11 @@ layout_mode = 2
|
|||
autowrap_mode = 2
|
||||
text = "Get an API key from https://itch.io/user/settings/api-keys"
|
||||
|
||||
[node name="FilterUnsupported" type="CheckBox" parent="VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Only show games available on this platform"
|
||||
|
||||
[node name="SaveButton" type="Button" parent="VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue