diff --git a/.gitignore b/.gitignore index 69a1846..ac2e6cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .godot dist +*.uid +*.remap +*.import diff --git a/core/itch_settings.gd b/core/itch_settings.gd index 8c72918..bacffbd 100644 --- a/core/itch_settings.gd +++ b/core/itch_settings.gd @@ -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") diff --git a/core/itch_settings.tscn b/core/itch_settings.tscn index aacea83..9c201b7 100644 --- a/core/itch_settings.tscn +++ b/core/itch_settings.tscn @@ -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 diff --git a/core/library_itch.gd b/core/library_itch.gd index e50fb72..2d2a28f 100644 --- a/core/library_itch.gd +++ b/core/library_itch.gd @@ -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 diff --git a/plugin.json b/plugin.json index 756cfa3..3bf4d0e 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "plugin.id": "itch", "plugin.name": "itch.io", - "plugin.version": "0.1.8", + "plugin.version": "0.1.9", "plugin.min-api-version": "1.1.0", "plugin.link": "https://forge.thergic.ar/jose/itchio-opengamepadui-plugin", "plugin.source": "https://forge.thergic.ar/jose/itchio-opengamepadui-plugin",