-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.gd
More file actions
91 lines (69 loc) · 2.76 KB
/
plugin.gd
File metadata and controls
91 lines (69 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
extends Plugin
const SteamClient := preload("res://plugins/steam/core/steam_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/steam/core/steam_settings.tscn") as PackedScene
var icon := preload("res://plugins/steam/assets/steam.svg")
var steam: SteamClient
var user := settings_manager.get_value("plugin.steam", "user", "") as String
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
logger = Log.get_logger("Steam", Log.LEVEL.INFO)
# Load the Steam client
steam = load("res://plugins/steam/core/steam_client.tscn").instantiate()
steam.bootstrap_finished.connect(_on_client_start)
steam.client_ready.connect(_on_client_ready)
steam.logged_in.connect(_on_client_logged_in)
add_child(steam)
# Load the Steam Store implementation
#var store: Node = load(plugin_base + "/core/store.tscn").instantiate()
#add_child(store)
# Load the Library implementation
var library: Library = load("res://plugins/steam/core/library_steam.tscn").instantiate()
add_child(library)
# Load the boxart implementation
var boxart: BoxArtProvider = load("res://plugins/steam/core/boxart_steam.tscn").instantiate()
add_child(boxart)
# Triggers when Steam has started
func _on_client_start():
# Ensure the client was started
if not steam.client_started:
var notify := Notification.new("Unable to start steam client")
notify.icon = icon
logger.error(notify.text)
notification_manager.show(notify)
return
# Triggers when the Steam Client is ready
func _on_client_ready():
# Check our settings to see if we have logged in before
if user == "":
var notify := Notification.new("Steam login required")
notify.icon = icon
logger.info(notify.text)
notification_manager.show(notify)
return
# If we have logged in before, try logging in with saved credentials
steam.login(user)
# Triggers when the Steam Client is logged in
func _on_client_logged_in(status: SteamClient.LOGIN_STATUS):
var notify := Notification.new("")
notify.icon = icon
if status == SteamClient.LOGIN_STATUS.OK:
notify.text = "Successfully logged in to Steam"
logger.info(notify.text)
return
if status == SteamClient.LOGIN_STATUS.INVALID_PASSWORD:
notify.text = "Steam login required"
logger.info(notify.text)
return
if status == SteamClient.LOGIN_STATUS.TFA_REQUIRED:
notify.text = "SteamGuard code required"
logger.info(notify.text)
return
if status == SteamClient.LOGIN_STATUS.FAILED:
notify.text = "Failed to login to Steam"
logger.info(notify.text)
return
# Return the settings menu scene
func get_settings_menu() -> Control:
return settings_menu.instantiate()