mirror of
https://github.com/JHDev2006/Super-Mario-Bros.-Remastered-Public.git
synced 2025-10-22 15:38:14 +00:00
Modularize Discord RPC (#247)
This commit delegates all Discord-related functions to DiscordManager.gd and adds a project setting bool to toggle using Discord RPC at all. Toggling off will reduce cpu and memory overhead when Discord is not needed.
This commit is contained in:
@@ -105,7 +105,7 @@ var undo_redo = UndoRedo.new()
|
|||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
$TileMenu.hide()
|
$TileMenu.hide()
|
||||||
Global.set_discord_status("In The Level Editor...")
|
DiscordManager.set_discord_status("In The Level Editor...")
|
||||||
Global.level_editor = self
|
Global.level_editor = self
|
||||||
playing_level = false
|
playing_level = false
|
||||||
menu_open = $TileMenu.visible
|
menu_open = $TileMenu.visible
|
||||||
|
63
Scripts/Classes/Singletons/DiscordManager.gd
Normal file
63
Scripts/Classes/Singletons/DiscordManager.gd
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
var enabled: bool = ProjectSettings.get_setting("application/use_discord", false) and not (OS.has_feature("linux") and OS.has_feature("arm64"))
|
||||||
|
var rpc = null
|
||||||
|
|
||||||
|
class DiscordRPCStub:
|
||||||
|
var app_id
|
||||||
|
var start_timestamp
|
||||||
|
var details
|
||||||
|
var state
|
||||||
|
var large_image
|
||||||
|
var small_image
|
||||||
|
|
||||||
|
func start(): pass
|
||||||
|
func refresh(): pass
|
||||||
|
func get_is_discord_working() -> bool: return false
|
||||||
|
func shutdown(): pass
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
if enabled:
|
||||||
|
rpc = Engine.get_singleton("DiscordRPC")
|
||||||
|
else:
|
||||||
|
rpc = DiscordRPCStub.new()
|
||||||
|
setup_discord_rpc()
|
||||||
|
|
||||||
|
func _process(_delta: float) -> void:
|
||||||
|
if enabled:
|
||||||
|
rpc.run_callbacks()
|
||||||
|
|
||||||
|
func setup_discord_rpc() -> void:
|
||||||
|
if not enabled:
|
||||||
|
return
|
||||||
|
rpc.app_id = 1331261692381757562
|
||||||
|
rpc.start_timestamp = int(Time.get_unix_time_from_system())
|
||||||
|
rpc.details = "In Title Screen.."
|
||||||
|
if rpc.get_is_discord_working():
|
||||||
|
rpc.refresh()
|
||||||
|
|
||||||
|
func set_discord_status(details: String = "") -> void:
|
||||||
|
if not enabled:
|
||||||
|
return
|
||||||
|
rpc.details = details
|
||||||
|
if rpc.get_is_discord_working():
|
||||||
|
rpc.refresh()
|
||||||
|
|
||||||
|
func update_discord_status(details: String) -> void:
|
||||||
|
if not enabled:
|
||||||
|
return
|
||||||
|
rpc.details = details
|
||||||
|
rpc.state = details
|
||||||
|
rpc.large_image = (Global.level_theme + Global.theme_time).to_lower()
|
||||||
|
rpc.small_image = Global.current_campaign.to_lower()
|
||||||
|
if rpc.get_is_discord_working():
|
||||||
|
rpc.refresh()
|
||||||
|
|
||||||
|
func refresh_discord_rpc() -> void:
|
||||||
|
if not enabled:
|
||||||
|
return
|
||||||
|
if not rpc.get_is_discord_working():
|
||||||
|
return
|
||||||
|
Global.update_game_status()
|
||||||
|
update_discord_status("")
|
||||||
|
rpc.refresh()
|
1
Scripts/Classes/Singletons/DiscordManager.gd.uid
Normal file
1
Scripts/Classes/Singletons/DiscordManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://yx2impqs0lo5
|
@@ -169,7 +169,6 @@ func _ready() -> void:
|
|||||||
get_server_version()
|
get_server_version()
|
||||||
if OS.is_debug_build():
|
if OS.is_debug_build():
|
||||||
debug_mode = false
|
debug_mode = false
|
||||||
setup_discord_rpc()
|
|
||||||
check_for_rom()
|
check_for_rom()
|
||||||
|
|
||||||
func check_for_rom() -> void:
|
func check_for_rom() -> void:
|
||||||
@@ -333,32 +332,11 @@ func close_freeze() -> void:
|
|||||||
|
|
||||||
var recording_dir = "user://marathon_recordings/"
|
var recording_dir = "user://marathon_recordings/"
|
||||||
|
|
||||||
func setup_discord_rpc() -> void:
|
|
||||||
DiscordRPC.app_id = 1331261692381757562
|
|
||||||
DiscordRPC.start_timestamp = int(Time.get_unix_time_from_system())
|
|
||||||
DiscordRPC.details = "In Title Screen.."
|
|
||||||
if DiscordRPC.get_is_discord_working():
|
|
||||||
DiscordRPC.refresh()
|
|
||||||
|
|
||||||
func set_discord_status(details := "") -> void:
|
|
||||||
DiscordRPC.details = details
|
|
||||||
if DiscordRPC.get_is_discord_working():
|
|
||||||
DiscordRPC.refresh()
|
|
||||||
|
|
||||||
func update_game_status() -> void:
|
func update_game_status() -> void:
|
||||||
var lives_str := str(Global.lives)
|
var lives_str := str(Global.lives)
|
||||||
if Settings.file.difficulty.inf_lives == 1:
|
if Settings.file.difficulty.inf_lives == 1:
|
||||||
lives_str = "∞"
|
lives_str = "∞"
|
||||||
var string := "Coins = " + str(Global.coins) + " Lives = " + lives_str
|
var string := "Coins = " + str(Global.coins) + " Lives = " + lives_str
|
||||||
DiscordRPC.large_image = (Global.level_theme + Global.theme_time).to_lower()
|
|
||||||
DiscordRPC.small_image = Global.current_campaign.to_lower()
|
|
||||||
DiscordRPC.state = string
|
|
||||||
|
|
||||||
func refresh_discord_rpc() -> void:
|
|
||||||
if DiscordRPC.get_is_discord_working() == false:
|
|
||||||
return
|
|
||||||
update_game_status()
|
|
||||||
DiscordRPC.refresh()
|
|
||||||
|
|
||||||
func open_marathon_results() -> void:
|
func open_marathon_results() -> void:
|
||||||
get_node("GameHUD/MarathonResults").open()
|
get_node("GameHUD/MarathonResults").open()
|
||||||
|
@@ -75,7 +75,7 @@ func _ready() -> void:
|
|||||||
|
|
||||||
if Global.current_game_mode == Global.GameMode.CAMPAIGN:
|
if Global.current_game_mode == Global.GameMode.CAMPAIGN:
|
||||||
SaveManager.write_save(Global.current_campaign)
|
SaveManager.write_save(Global.current_campaign)
|
||||||
Global.set_discord_status("Playing " + Global.current_campaign + ": " + str(world_num) + "-" + str(Global.level_num))
|
DiscordManager.set_discord_status("Playing " + Global.current_campaign + ": " + str(world_num) + "-" + str(Global.level_num))
|
||||||
$BG/Control/WorldNum.text = str(world_num) +"-" + str(Global.level_num)
|
$BG/Control/WorldNum.text = str(world_num) +"-" + str(Global.level_num)
|
||||||
if Settings.file.difficulty.inf_lives:
|
if Settings.file.difficulty.inf_lives:
|
||||||
$BG/Control/LivesCount.text = "* ∞"
|
$BG/Control/LivesCount.text = "* ∞"
|
||||||
|
@@ -11,8 +11,8 @@ windows.debug.x86_64 = "windows/discord_game_sdk_binding_debug.dll"
|
|||||||
windows.release.x86_64 = "windows/discord_game_sdk_binding.dll"
|
windows.release.x86_64 = "windows/discord_game_sdk_binding.dll"
|
||||||
linux.debug.x86_64 = "linux/libdiscord_game_sdk_binding_debug.so"
|
linux.debug.x86_64 = "linux/libdiscord_game_sdk_binding_debug.so"
|
||||||
linux.release.x86_64 = "linux/libdiscord_game_sdk_binding.so"
|
linux.release.x86_64 = "linux/libdiscord_game_sdk_binding.so"
|
||||||
linux.debug.arm64 = "linux/libdiscord_game_sdk_binding_debug.so"
|
;linux.debug.arm64 = "linux/libdiscord_game_sdk_binding_debug.so"
|
||||||
linux.release.arm64 = "linux/libdiscord_game_sdk_binding.so"
|
;linux.release.arm64 = "linux/libdiscord_game_sdk_binding.so"
|
||||||
linux.debug.rv64 = "linux/libdiscord_game_sdk_binding_debug.so"
|
linux.debug.rv64 = "linux/libdiscord_game_sdk_binding_debug.so"
|
||||||
linux.release.rv64 = "linux/libdiscord_game_sdk_binding.so"
|
linux.release.rv64 = "linux/libdiscord_game_sdk_binding.so"
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ windows.debug.x86_64 = { "windows/discord_game_sdk.dll": "" }
|
|||||||
windows.release.x86_64 = { "windows/discord_game_sdk.dll": "" }
|
windows.release.x86_64 = { "windows/discord_game_sdk.dll": "" }
|
||||||
linux.debug.x86_64 = { "linux/libdiscord_game_sdk.so": "" }
|
linux.debug.x86_64 = { "linux/libdiscord_game_sdk.so": "" }
|
||||||
linux.release.x86_64 = { "linux/libdiscord_game_sdk.so": "" }
|
linux.release.x86_64 = { "linux/libdiscord_game_sdk.so": "" }
|
||||||
linux.debug.arm64 = { "linux/libdiscord_game_sdk.so": "" }
|
;linux.debug.arm64 = { "linux/libdiscord_game_sdk.so": "" }
|
||||||
linux.release.arm64 = { "linux/libdiscord_game_sdk.so": "" }
|
;linux.release.arm64 = { "linux/libdiscord_game_sdk.so": "" }
|
||||||
linux.debug.rv64 = { "linux/libdiscord_game_sdk.so": "" }
|
linux.debug.rv64 = { "linux/libdiscord_game_sdk.so": "" }
|
||||||
linux.release.rv64 = { "linux/libdiscord_game_sdk.so": "" }
|
linux.release.rv64 = { "linux/libdiscord_game_sdk.so": "" }
|
||||||
|
BIN
godotgif/bin/libgodotgif.linux.template_debug.arm64.so
Normal file
BIN
godotgif/bin/libgodotgif.linux.template_debug.arm64.so
Normal file
Binary file not shown.
BIN
godotgif/bin/libgodotgif.linux.template_release.arm64.so
Normal file
BIN
godotgif/bin/libgodotgif.linux.template_release.arm64.so
Normal file
Binary file not shown.
@@ -24,6 +24,7 @@ boot_splash/show_image=false
|
|||||||
boot_splash/fullsize=false
|
boot_splash/fullsize=false
|
||||||
boot_splash/use_filter=false
|
boot_splash/use_filter=false
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
use_discord=true
|
||||||
|
|
||||||
[autoload]
|
[autoload]
|
||||||
|
|
||||||
@@ -32,8 +33,8 @@ ModLoader="*res://addons/mod_loader/mod_loader.gd"
|
|||||||
Global="*res://Scenes/Prefabs/Global.tscn"
|
Global="*res://Scenes/Prefabs/Global.tscn"
|
||||||
Settings="*res://Scenes/Prefabs/Autoload/Settings.tscn"
|
Settings="*res://Scenes/Prefabs/Autoload/Settings.tscn"
|
||||||
SaveManager="*res://Scripts/Classes/Singletons/SaveManager.gd"
|
SaveManager="*res://Scripts/Classes/Singletons/SaveManager.gd"
|
||||||
|
DiscordManager="*res://Scripts/Classes/Singletons/DiscordManager.gd"
|
||||||
AudioManager="*res://Scenes/Prefabs/Autoload/AudioManager.tscn"
|
AudioManager="*res://Scenes/Prefabs/Autoload/AudioManager.tscn"
|
||||||
DiscordRPCLoader="*res://addons/discord-rpc-gd/nodes/discord_autoload.gd"
|
|
||||||
BetterTerrain="*res://addons/better-terrain/BetterTerrain.gd"
|
BetterTerrain="*res://addons/better-terrain/BetterTerrain.gd"
|
||||||
GameBanana="*res://Scripts/Classes/Singletons/GameBananaManager.gd"
|
GameBanana="*res://Scripts/Classes/Singletons/GameBananaManager.gd"
|
||||||
SpeedrunHandler="*res://Scripts/Classes/Singletons/SpeedrunHandler.gd"
|
SpeedrunHandler="*res://Scripts/Classes/Singletons/SpeedrunHandler.gd"
|
||||||
|
Reference in New Issue
Block a user