Skip to content

Commit

Permalink
feat: added Discord rpc methods
Browse files Browse the repository at this point in the history
  • Loading branch information
akorzunin committed Sep 13, 2024
1 parent 8ef5503 commit 29c13f4
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/components/DiscordStatus.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,34 @@ class_name DiscordStatus

func _ready():
DiscordRPC.app_id = ENV.DISCORD_APP_ID # Application ID
DiscordRPC.details = "Main menu"
DiscordRPC.state = "Checkpoint 23/23"
DiscordRPC.details = init_state.details
DiscordRPC.state = init_state.desc
DiscordRPC.large_image = 'icon' # Image key from "Art Assets"
DiscordRPC.large_image_text = "Try it now!"
DiscordRPC.small_image = 'icon' # Image key from "Art Assets"
DiscordRPC.small_image_text = "Fighting the end boss! D:"
DiscordRPC.refresh()

DiscordRPC.start_timestamp = int(Time.get_unix_time_from_system()) # "02:46 elapsed"
# DiscordRPC.end_timestamp = int(Time.get_unix_time_from_system()) + 3600 # +1 hour in unix time / "01:00:00 remaining"
const init_state := {
details = "Main menu",
desc = "Chilling",
}

DiscordRPC.refresh() # Always refresh after changing the values!
const loop_state := {
details = "In Game",
desc = "Level: %s",
}

func set_state(details: String, desc: String, with_time: bool = false):
DiscordRPC.details = details
DiscordRPC.state = desc
if with_time:
DiscordRPC.start_timestamp = int(Time.get_unix_time_from_system()) # "02:46 elapsed"
DiscordRPC.refresh()

func set_menu_state():
set_state(init_state.details, init_state.desc)

func set_loop_state(level := 0):
set_state(
loop_state.details,
loop_state.desc % level if level else "tutorial",
true
)

0 comments on commit 29c13f4

Please sign in to comment.