Godot 4 · GDScript
Друзья
Система дружбы: приглашения, список ожидающих и таблицы лидеров, отфильтрованные только по друзьям.
Отправить приглашение
Пригласите игрока по его ключу и слушайте invite_sent:
Gamdato.invite_sent.connect(_on_invite)
Gamdato.send_friend_invite(player_key, "Let's play!")# invitation: Dictionary (the one just created)
{
"id": String,
"to_player_key": String,
"to_player_name": String,
"status": "pending",
"message": String,
"created_at": String,
"expires_at": String
}Список приглашений
Получите ожидающие приглашения (отправленные и полученные) вместе:
Gamdato.invitations_listed.connect(_on_invites)
Gamdato.list_pending_invitations()# invitations: Array, each invitation:
{
"id": String, # pass this to respond/cancel
"direction": "incoming" | "outgoing",
"counterpart": {
"player_key": String,
"player_name": String
},
"status": "pending",
"message": String, # may be empty
"created_at": String, # ISO date
"responded_at": String, # null while pending
"expires_at": String # ISO date
}Ответ и отмена
Примите или отклоните полученное приглашение или отмените отправленное вами:
Gamdato.respond_invitation(invitation_id, true) # accept
Gamdato.cancel_invitation(invitation_id) # cancel a sent oneСписок ваших друзей
Получите список принятых друзей (не приглашений). При желании отфильтруйте по имени.
Gamdato.friends_loaded.connect(_on_friends)
Gamdato.list_friends() # or list_friends(50, "text")
func _on_friends(friends: Array) -> void:
for f in friends:
print("%s (since %s)" % [f.player_name, f.friends_since])# friends: Array, each friend:
{
"player_key": String,
"player_name": String,
"friends_since": String # ISO date
}Удаление друга
Удалите существующую дружбу по ключу игрока.
Gamdato.friend_removed.connect(_on_removed)
Gamdato.remove_friend(player_key)
func _on_removed(ok: bool, key: String, error_code: String) -> void:
if ok: print("Friend removed")