Skip to content

Commit

Permalink
Merge pull request #54 from TaloDev/develop
Browse files Browse the repository at this point in the history
Release 0.16.0
  • Loading branch information
tudddorrr authored Dec 15, 2024
2 parents 64ee25e + 9da7d66 commit 9d92c68
Show file tree
Hide file tree
Showing 13 changed files with 494 additions and 15 deletions.
119 changes: 119 additions & 0 deletions addons/talo/apis/channels_api.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
class_name ChannelsAPI extends TaloAPI
## An interface for communicating with the Talo Channels API.
##
## This API is used to send messages between players who are subscribed to channels.
##
## @tutorial: https://docs.trytalo.com/docs/godot/channels

## Get a list of channels that players can join.
func get_channels(page: int) -> Array:
var res = await client.make_request(HTTPClient.METHOD_GET, "?page=%s" % page)

match (res.status):
200:
var channels: Array[TaloChannel] = []
channels.assign(res.body.channels.map(func (channel: Dictionary): return TaloChannel.new(channel)))
return [channels, res.body.count, res.body.isLastPage]
_:
return []

## Get a list of channels that the current player is subscribed to.
func get_subscribed_channels() -> Array[TaloChannel]:
if Talo.identity_check() != OK:
return []

var res = await client.make_request(HTTPClient.METHOD_GET, "/subscriptions")

match (res.status):
200:
var channels: Array[TaloChannel] = []
channels.assign(res.body.channels.map(func (channel: Dictionary): return TaloChannel.new(channel)))
return channels
_:
return []

## Create a new channel. The player who creates this channel will automatically become the owner. If auto cleanup is enabled, the channel will be deleted when the owner or the last member leaves.
func create(name: String, auto_cleanup: bool = false, props: Dictionary = {}) -> TaloChannel:
if Talo.identity_check() != OK:
return

var props_to_send = props.keys().map(func (key: String): return { key = key, value = str(props[key]) })

var res = await client.make_request(HTTPClient.METHOD_POST, "", {
name = name,
autoCleanup = auto_cleanup,
props = props_to_send
})

match (res.status):
200:
return TaloChannel.new(res.body.channel)
_:
return null

## Join an existing channel.
func join(channel_id: int) -> TaloChannel:
if Talo.identity_check() != OK:
return

var res = await client.make_request(HTTPClient.METHOD_POST, "/%s/join" % channel_id)

match (res.status):
200:
return TaloChannel.new(res.body.channel)
_:
return null

## Leave a channel.
func leave(channel_id: int) -> void:
if Talo.identity_check() != OK:
return

await client.make_request(HTTPClient.METHOD_POST, "/%s/leave" % channel_id)

## Update a channel. This will only work if the current player is the owner of the channel.
func update(channel_id: int, name: String = "", new_owner_alias_id: int = -1, props: Dictionary = {}) -> TaloChannel:
if Talo.identity_check() != OK:
return

var data = {}
if not name.is_empty():
data.name = name
if new_owner_alias_id != -1:
data.ownerAliasId = new_owner_alias_id
if props.size() > 0:
data.props = props

var res = await client.make_request(HTTPClient.METHOD_PUT, "/%s" % channel_id, data)

match (res.status):
200:
return TaloChannel.new(res.body.channel)
403:
push_error("Player does not have permissions to update channel %s." % channel_id)
return null
_:
return null

## Delete a channel. This will only work if the current player is the owner of the channel.
func delete(channel_id: int) -> void:
if Talo.identity_check() != OK:
return

var res = await client.make_request(HTTPClient.METHOD_DELETE, "/%s" % channel_id)

match (res.status):
403:
push_error("Player does not have permissions to delete channel %s." % channel_id)

## Send a message to a channel.
func send_message(channel_id: int, message: String) -> void:
if Talo.identity_check() != OK:
return

Talo.socket.send("v1.channels.message", {
channel = {
id = channel_id
},
message = message
})
5 changes: 3 additions & 2 deletions addons/talo/apis/feedback_api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ class_name FeedbackAPI extends TaloAPI
## @tutorial: https://docs.trytalo.com/docs/godot/feedback

## Get a list of feedback categories that are available for players to submit feedback.
func get_categories() -> Array:
func get_categories() -> Array[TaloFeedbackCategory]:
var res = await client.make_request(HTTPClient.METHOD_GET, "/categories")

match (res.status):
200:
var categories: Array = res.body.feedbackCategories.map(func (category: Dictionary): return TaloFeedbackCategory.new(category))
var categories: Array[TaloFeedbackCategory] = []
categories.assign(res.body.categories.map(func (category: Dictionary): return TaloFeedbackCategory.new(category)))
return categories
_:
return []
Expand Down
6 changes: 3 additions & 3 deletions addons/talo/apis/player_auth_api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func register(identifier: String, password: String, email: String = "", verifica

match (res.status):
200:
session_manager.handle_session_created(res.body.alias, res.body.sessionToken)
session_manager.handle_session_created(res.body.alias, res.body.sessionToken, res.body.socketToken)
return OK
_:
return _handle_error(res)
Expand All @@ -48,7 +48,7 @@ func login(identifier: String, password: String) -> Array[Variant]: ## [Error, b
if res.body.has("verificationRequired"):
session_manager.save_verification_alias_id(res.body.aliasId)
else:
session_manager.handle_session_created(res.body.alias, res.body.sessionToken)
session_manager.handle_session_created(res.body.alias, res.body.sessionToken, res.body.socketToken)

return [OK, res.body.has("verificationRequired")]
_:
Expand All @@ -63,7 +63,7 @@ func verify(verification_code: String) -> Error:

match (res.status):
200:
session_manager.handle_session_created(res.body.alias, res.body.sessionToken)
session_manager.handle_session_created(res.body.alias, res.body.sessionToken, res.body.socketToken)
return OK
_:
return _handle_error(res)
Expand Down
3 changes: 2 additions & 1 deletion addons/talo/apis/players_api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func identify(service: String, identifier: String) -> void:
match (res.status):
200:
Talo.current_alias = TaloPlayerAlias.new(res.body.alias)
Talo.socket.set_socket_token(res.body.socketToken)
identified.emit(Talo.current_player)
_:
if not await Talo.is_offline():
Expand Down Expand Up @@ -47,7 +48,7 @@ func merge(player_id1: String, player_id2: String) -> TaloPlayer:
return null

## Generate a mostly-unique identifier.
func generate_identifer() -> String:
func generate_identifier() -> String:
var time_hash: String = str(TimeUtils.get_timestamp_msec()).sha256_text()
var size = 12
var split_start: int = RandomNumberGenerator.new().randi_range(0, time_hash.length() - size)
Expand Down
6 changes: 3 additions & 3 deletions addons/talo/apis/saves_api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ signal save_loading_completed
var _saves_manager = TaloSavesManager.new()

## All of the player's fetched saves.
var all:
var all: Array[TaloGameSave]:
get: return _saves_manager.all_saves

## The latest save that was updated.
var latest:
var latest: TaloGameSave:
get: return _saves_manager.get_latest_save()

## The current save that has been chosen.
var current:
var current: TaloGameSave:
get: return _saves_manager.current_save

## Sync an offline save with an online save using the offline save data.
Expand Down
20 changes: 20 additions & 0 deletions addons/talo/entities/channel.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class_name TaloChannel extends TaloEntityWithProps

var id: int
var display_name: String
var owner_alias: TaloPlayerAlias
var total_messages: int
var member_count: int
var created_at: String
var updated_at: String

func _init(data: Dictionary):
super._init(data.props.map(func (prop): return TaloProp.new(prop.key, prop.value)))

id = data.id
display_name = data.name
owner_alias = TaloPlayerAlias.new(data.owner)
total_messages = data.totalMessages
member_count = data.memberCount
created_at = data.createdAt
updated_at = data.updatedAt
4 changes: 2 additions & 2 deletions addons/talo/plugin.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[plugin]

name="Talo Game Services"
description="Talo (https://trytalo.com) is an open-source game backend with services designed to help you build games faster. You can currently:\n\n- Identify and authenticate players\n- Store persistent data across players\n- Track events (levelling up, finding loot, etc)\n- Display high scores with leaderboards\n- Store and load player saves\n- Load game config options and flags from the cloud\n- Get feedback directly from your players"
description="Talo (https://trytalo.com) is an open-source game backend with services designed to help you build games faster. You can currently:\n\n- Identify and authenticate players\n- Store persistent data across players\n- Track events (levelling up, finding loot, etc)\n- Display high scores with leaderboards\n- Store and load player saves\n- Load game config options and flags from the cloud\n- Get feedback directly from your players\n- Send channel messages between players"
author="trytalo"
version="0.15.0"
version="0.16.0"
script="talo_autoload.gd"
132 changes: 132 additions & 0 deletions addons/talo/samples/chat/chat.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
[gd_scene load_steps=3 format=3 uid="uid://b6am7sdy8k7gu"]

[ext_resource type="Script" path="res://addons/talo/samples/chat/scripts/chat.gd" id="1_pqhos"]

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_gim24"]
content_margin_left = 5.0
content_margin_top = 5.0
content_margin_right = 5.0
content_margin_bottom = 5.0

[node name="Chat" type="Node2D"]
script = ExtResource("1_pqhos")

[node name="Control" type="Control" parent="."]
layout_mode = 3
anchors_preset = 0
offset_right = 1080.0
offset_bottom = 720.0

[node name="ChannelListLabel" type="Label" parent="Control"]
layout_mode = 0
offset_left = 20.0
offset_top = 20.0
offset_right = 164.0
offset_bottom = 43.0
text = "Available channels"

[node name="ChannelList" type="Panel" parent="Control"]
layout_mode = 1
anchors_preset = 9
anchor_bottom = 1.0
offset_left = 20.0
offset_top = 60.0
offset_right = 220.0
offset_bottom = -80.0
grow_vertical = 2

[node name="ScrollContainer" type="ScrollContainer" parent="Control/ChannelList"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxEmpty_gim24")
horizontal_scroll_mode = 0

[node name="Channels" type="VBoxContainer" parent="Control/ChannelList/ScrollContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3

[node name="ChatLabel" type="Label" parent="Control"]
layout_mode = 0
offset_left = 240.0
offset_top = 20.0
offset_right = 384.0
offset_bottom = 43.0
text = "Chat messages"

[node name="Chat" type="Panel" parent="Control"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 240.0
offset_top = 60.0
offset_right = -20.0
offset_bottom = -80.0
grow_horizontal = 2
grow_vertical = 2

[node name="ScrollContainer" type="ScrollContainer" parent="Control/Chat"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxEmpty_gim24")

[node name="Messages" type="VBoxContainer" parent="Control/Chat/ScrollContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3

[node name="ChatMessage" type="LineEdit" parent="Control"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -840.0
offset_top = -60.0
offset_right = -20.0
offset_bottom = -20.0
grow_horizontal = 0
grow_vertical = 0
placeholder_text = "Send a message"

[node name="ChannelName" type="LineEdit" parent="Control"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -1060.0
offset_top = -60.0
offset_right = -930.0
offset_bottom = -20.0
grow_horizontal = 0
grow_vertical = 0
placeholder_text = "Channel name"

[node name="AddChannelButton" type="Button" parent="Control"]
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 160.0
offset_top = -60.0
offset_right = 220.0
offset_bottom = -20.0
grow_vertical = 0
text = "Add"

[connection signal="text_submitted" from="Control/ChatMessage" to="." method="_on_chat_message_text_submitted"]
[connection signal="pressed" from="Control/AddChannelButton" to="." method="_on_add_channel_button_pressed"]
Loading

0 comments on commit 9d92c68

Please sign in to comment.