-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from TaloDev/develop
Release 0.16.0
- Loading branch information
Showing
13 changed files
with
494 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
Oops, something went wrong.