Initial commit
This commit is contained in:
commit
3132a5015a
14 changed files with 1730 additions and 0 deletions
79
plugin.gd
Normal file
79
plugin.gd
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
extends Plugin
|
||||
|
||||
## itch.io plugin entrypoint
|
||||
##
|
||||
## Boots the ItchClient (which spawns and speaks to butlerd, itch's official
|
||||
## JSON-RPC launcher daemon) and registers the Library implementation so
|
||||
## installed itch.io games show up alongside everything else in the user's
|
||||
## OpenGamepadUI library.
|
||||
|
||||
const ItchClient := preload("res://plugins/itch/core/itch_client.gd")
|
||||
|
||||
var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager
|
||||
var notification_manager := load("res://core/global/notification_manager.tres") as NotificationManager
|
||||
var settings_menu := load("res://plugins/itch/core/itch_settings.tscn") as PackedScene
|
||||
var icon := preload("res://plugins/itch/assets/itch.svg")
|
||||
|
||||
var itch: ItchClient
|
||||
var api_key := settings_manager.get_value("plugin.itch", "api_key", "") as String
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
logger = Log.get_logger("Itch", Log.LEVEL.INFO)
|
||||
|
||||
# Load the itch client. This spawns butlerd in the background and
|
||||
# manages the JSON-RPC connection to it.
|
||||
itch = load("res://plugins/itch/core/itch_client.tscn").instantiate()
|
||||
itch.bootstrap_finished.connect(_on_client_start)
|
||||
itch.client_ready.connect(_on_client_ready)
|
||||
itch.logged_in.connect(_on_client_logged_in)
|
||||
add_child(itch)
|
||||
|
||||
# Load the Library implementation
|
||||
var library: Library = load("res://plugins/itch/core/library_itch.tscn").instantiate()
|
||||
add_child(library)
|
||||
|
||||
|
||||
# Triggers when butlerd has been spawned
|
||||
func _on_client_start() -> void:
|
||||
if not itch.client_started:
|
||||
var notify := Notification.new("Unable to start the itch.io (butlerd) client")
|
||||
notify.icon = icon
|
||||
logger.error(notify.text)
|
||||
notification_manager.show(notify)
|
||||
return
|
||||
|
||||
|
||||
# Triggers when butlerd has completed its handshake and is ready for calls
|
||||
func _on_client_ready() -> void:
|
||||
if api_key == "":
|
||||
var notify := Notification.new("itch.io API key required")
|
||||
notify.icon = icon
|
||||
logger.info(notify.text)
|
||||
notification_manager.show(notify)
|
||||
return
|
||||
|
||||
# If we have a saved API key, try logging in with it automatically
|
||||
itch.login_with_api_key(api_key)
|
||||
|
||||
|
||||
# Triggers when the itch client finishes a login attempt
|
||||
func _on_client_logged_in(status: ItchClient.LOGIN_STATUS, profile: Dictionary) -> void:
|
||||
var notify := Notification.new("")
|
||||
notify.icon = icon
|
||||
|
||||
if status == ItchClient.LOGIN_STATUS.OK:
|
||||
var username: String = profile.get("user", {}).get("username", "")
|
||||
notify.text = "Successfully logged in to itch.io as " + username
|
||||
logger.info(notify.text)
|
||||
notification_manager.show(notify)
|
||||
return
|
||||
|
||||
notify.text = "Failed to log in to itch.io. Check your API key in plugin settings."
|
||||
logger.warn(notify.text)
|
||||
notification_manager.show(notify)
|
||||
|
||||
|
||||
# Return the settings menu scene
|
||||
func get_settings_menu() -> Control:
|
||||
return settings_menu.instantiate()
|
||||
Loading…
Add table
Add a link
Reference in a new issue