Skip to content

Commit 8eb4486

Browse files
authored
Merge pull request #233 from TaloDev/remove-prop-rejection-signal
Remove prop rejection signals, keep them inline with update results
2 parents 2a69ea1 + 92c6250 commit 8eb4486

10 files changed

Lines changed: 54 additions & 52 deletions

File tree

addons/talo/apis/channels_api.gd

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ signal channel_ownership_transferred(channel: TaloChannel, new_owner_player_alia
1717
signal channel_deleted(channel: TaloChannel)
1818
## Emitted when a channel is updated.
1919
signal channel_updated(channel: TaloChannel, changed_properties: Array[String])
20-
## Emitted when one or more props are rejected during a channel create or update.
21-
signal channel_props_rejected(rejected_props: Array[TaloRejectedProp])
2220
## Emitted when channel storage props are updated or deleted.
2321
signal channel_storage_props_updated(channel: TaloChannel, upserted_props: Array[TaloChannelStorageProp], deleted_props: Array[TaloChannelStorageProp])
2422
## Emitted when one or more storage props were not successfully set.
@@ -118,9 +116,9 @@ func get_subscribed_channels(options: GetSubscribedChannelsOptions = GetSubscrib
118116
return []
119117

120118
## 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. Private channels can only be joined by players who have been invited to the channel. Channels with temporary membership will remove players at the end of their session.
121-
func create(options: CreateChannelOptions = CreateChannelOptions.new()) -> TaloChannel:
119+
func create(options: CreateChannelOptions = CreateChannelOptions.new()) -> ChannelUpsertResult:
122120
if Talo.identity_check() != OK:
123-
return
121+
return ChannelUpsertResult.new(false, null)
124122

125123
var props_to_send := options.props \
126124
.keys() \
@@ -136,15 +134,12 @@ func create(options: CreateChannelOptions = CreateChannelOptions.new()) -> TaloC
136134

137135
match res.status:
138136
200:
139-
return TaloChannel.new(res.body.channel)
137+
return ChannelUpsertResult.new(true, TaloChannel.new(res.body.channel))
140138
400:
141139
var rejected_props := TaloRejectedProp.from_response(res.body)
142-
if rejected_props.size() > 0:
143-
channel_props_rejected.emit(rejected_props)
144-
145-
return null
140+
return ChannelUpsertResult.new(false, null, rejected_props)
146141
_:
147-
return null
142+
return ChannelUpsertResult.new(false, null)
148143

149144
## Join an existing channel.
150145
func join(channel_id: int) -> TaloChannel:
@@ -167,9 +162,9 @@ func leave(channel_id: int) -> void:
167162
await client.make_request(HTTPClient.METHOD_POST, "/%s/leave" % channel_id)
168163

169164
## Update a channel. This will only work if the current player is the owner of the channel.
170-
func update(channel_id: int, options: UpdateChannelOptions = UpdateChannelOptions.new()) -> TaloChannel:
165+
func update(channel_id: int, options: UpdateChannelOptions = UpdateChannelOptions.new()) -> ChannelUpsertResult:
171166
if Talo.identity_check() != OK:
172-
return
167+
return ChannelUpsertResult.new(false, null)
173168

174169
var data := {}
175170
if not options.name.is_empty():
@@ -189,18 +184,15 @@ func update(channel_id: int, options: UpdateChannelOptions = UpdateChannelOption
189184

190185
match res.status:
191186
200:
192-
return TaloChannel.new(res.body.channel)
187+
return ChannelUpsertResult.new(true, TaloChannel.new(res.body.channel))
193188
400:
194189
var rejected_props := TaloRejectedProp.from_response(res.body)
195-
if rejected_props.size() > 0:
196-
channel_props_rejected.emit(rejected_props)
197-
198-
return null
190+
return ChannelUpsertResult.new(false, null, rejected_props)
199191
403:
200192
push_error("Player does not have permissions to update channel %s." % channel_id)
201-
return null
193+
return ChannelUpsertResult.new(false, null)
202194
_:
203-
return null
195+
return ChannelUpsertResult.new(false, null)
204196

205197
## Delete a channel. This will only work if the current player is the owner of the channel.
206198
func delete(channel_id: int) -> void:
@@ -433,3 +425,13 @@ class MembersPage:
433425
self.count = count
434426
self.items_per_page = items_per_page
435427
self.is_last_page = is_last_page
428+
429+
class ChannelUpsertResult:
430+
var success: bool
431+
var channel: TaloChannel
432+
var rejected_props: Array[TaloRejectedProp]
433+
434+
func _init(success: bool, channel: TaloChannel, rejected_props: Array[TaloRejectedProp] = []) -> void:
435+
self.success = success
436+
self.channel = channel
437+
self.rejected_props = rejected_props

addons/talo/apis/feedback_api.gd

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ class_name FeedbackAPI extends TaloAPI
55
##
66
## @tutorial: https://docs.trytalo.com/docs/godot/feedback
77

8-
## Emitted when one or more props are rejected during feedback submission.
9-
signal props_rejected(rejected_props: Array[TaloRejectedProp])
10-
118
## Get a list of feedback categories that are available for players to submit feedback.
129
func get_categories() -> Array[TaloFeedbackCategory]:
1310
var res := await client.make_request(HTTPClient.METHOD_GET, "/categories")
@@ -21,9 +18,9 @@ func get_categories() -> Array[TaloFeedbackCategory]:
2118
return []
2219

2320
## Submit feedback for a specific category. Optionally add props for extra context.
24-
func send(category_internal_name: String, comment: String, props: Dictionary[String, String] = {}) -> void:
21+
func send(category_internal_name: String, comment: String, props: Dictionary[String, String] = {}) -> FeedbackSendResult:
2522
if Talo.identity_check() != OK:
26-
return
23+
return FeedbackSendResult.new(false)
2724

2825
var props_to_send := props \
2926
.keys() \
@@ -35,7 +32,17 @@ func send(category_internal_name: String, comment: String, props: Dictionary[Str
3532
})
3633

3734
match res.status:
35+
200:
36+
return FeedbackSendResult.new(true)
3837
400:
39-
var rejected_props := TaloRejectedProp.from_response(res.body)
40-
if rejected_props.size() > 0:
41-
props_rejected.emit(rejected_props)
38+
return FeedbackSendResult.new(false, TaloRejectedProp.from_response(res.body))
39+
_:
40+
return FeedbackSendResult.new(false)
41+
42+
class FeedbackSendResult:
43+
var success: bool
44+
var rejected_props: Array[TaloRejectedProp]
45+
46+
func _init(success: bool, rejected_props: Array[TaloRejectedProp] = []) -> void:
47+
self.success = success
48+
self.rejected_props = rejected_props

addons/talo/apis/leaderboards_api.gd

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ class_name LeaderboardsAPI extends TaloAPI
55
##
66
## @tutorial: https://docs.trytalo.com/docs/godot/leaderboards
77

8-
## Emitted when one or more props are rejected during an entry add.
9-
signal props_rejected(rejected_props: Array[TaloRejectedProp])
10-
118
var _entries_manager := TaloLeaderboardEntriesManager.new()
129

1310
## Get a list of all the entries that have been previously fetched or created for a leaderboard. The options include "alias_id", "player_id" and "alias_service" for additional filtering.
@@ -76,7 +73,7 @@ func get_entries(internal_name: String, options := GetEntriesOptions.new()) -> E
7673
## Add an entry to a leaderboard. The props (key-value pairs) parameter is used to store additional data with the entry.
7774
func add_entry(internal_name: String, score: float, props: Dictionary[String, Variant] = {}) -> AddEntryResult:
7875
if Talo.identity_check() != OK:
79-
return null
76+
return AddEntryResult.new(null, false)
8077

8178
var res := await client.make_request(HTTPClient.METHOD_POST, "/%s/entries" % internal_name, {
8279
score = score,
@@ -91,12 +88,9 @@ func add_entry(internal_name: String, score: float, props: Dictionary[String, Va
9188
return AddEntryResult.new(entry, res.body.updated)
9289
400:
9390
var rejected_props := TaloRejectedProp.from_response(res.body)
94-
if rejected_props.size() > 0:
95-
props_rejected.emit(rejected_props)
96-
97-
return null
91+
return AddEntryResult.new(null, false, rejected_props)
9892
_:
99-
return null
93+
return AddEntryResult.new(null, false)
10094

10195
class EntriesPage:
10296
var entries: Array[TaloLeaderboardEntry]
@@ -113,10 +107,12 @@ class EntriesPage:
113107
class AddEntryResult:
114108
var entry: TaloLeaderboardEntry
115109
var updated: bool
110+
var rejected_props: Array[TaloRejectedProp]
116111

117-
func _init(entry: TaloLeaderboardEntry, updated: bool) -> void:
112+
func _init(entry: TaloLeaderboardEntry, updated: bool, rejected_props: Array[TaloRejectedProp] = []) -> void:
118113
self.entry = entry
119114
self.updated = updated
115+
self.rejected_props = rejected_props
120116

121117
class GetEntriesOptions:
122118
var page: int = 0

addons/talo/apis/players_api.gd

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ signal identification_failed(error: TaloIdentifyError)
1717
## Emitted after calling clear_identity().
1818
signal identity_cleared()
1919

20-
## Emitted when one or more props are rejected during a player update.
21-
signal props_rejected(rejected_props: Array[TaloRejectedProp])
22-
2320
## Emitted when a debounced player update settles.
2421
signal player_updated(success: bool)
2522

@@ -108,9 +105,6 @@ func _run_debounced_update() -> Variant:
108105
Talo.current_alias.write_offline_alias()
109106

110107
var rejected_props := TaloRejectedProp.from_response(res.body)
111-
if rejected_props.size() > 0:
112-
props_rejected.emit(rejected_props)
113-
114108
return rejected_props
115109
_:
116110
return null

addons/talo/apis/saves_api.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func delete_save(save: TaloGameSave, unload_if_current_save: bool = false) -> vo
195195
func get_format_version() -> String:
196196
return _saves_manager.get_format_version()
197197

198-
class SaveUpdateResult extends RefCounted:
198+
class SaveUpdateResult:
199199
var success: bool
200200
var save: TaloGameSave
201201

addons/talo/samples/channel_storage/scripts/channel_storage_demo.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ func _ready() -> void:
2929
create_options.props = {
3030
"channel-storage-demo": "true"
3131
}
32-
demo_channel = await Talo.channels.create(create_options)
32+
var result := await Talo.channels.create(create_options)
33+
if result.success:
34+
demo_channel = result.channel
3335

3436
await Talo.channels.join(demo_channel.id)
3537

addons/talo/samples/chat/scripts/chat.gd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func _on_add_channel_button_pressed() -> void:
4646
options.name = %ChannelName.text
4747
options.auto_cleanup = true
4848

49-
var channel := await Talo.channels.create(options)
50-
if channel:
51-
_subscriptions.append(channel)
52-
_add_channel_label(channel.id, channel.name)
49+
var result := await Talo.channels.create(options)
50+
if result.success:
51+
_subscriptions.append(result.channel)
52+
_add_channel_label(result.channel.id, result.channel.name)
5353
%ChannelName.text = ""
5454

5555
func _add_chat_message(message: String) -> void:

addons/talo/samples/leaderboards/scripts/leaderboard.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func _on_submit_pressed() -> void:
7575
var team := "Blue" if RandomNumberGenerator.new().randi_range(0, 1) == 0 else "Red"
7676

7777
var res := await Talo.leaderboards.add_entry(leaderboard_internal_name, score, {team = team})
78-
assert(is_instance_valid(res))
78+
assert(res.entry != null)
7979
info_label.text = "You scored %s points for the %s team!%s" % [score, team, " Your highscore was updated!" if res.updated else ""]
8080

8181
_build_entries()

addons/talo/samples/playground/scripts/add_entry_button.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ func _on_pressed() -> void:
1414
var score := RandomNumberGenerator.new().randi_range(1, 50)
1515
var res := await Talo.leaderboards.add_entry(leaderboard_name, score)
1616

17-
if is_instance_valid(res):
17+
if res.entry:
1818
%ResponseLabel.text = "Added score: %s, new high score: %s" % [score, res.updated]

addons/talo/samples/playground/scripts/delete_prop_button.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ func _on_pressed() -> void:
1111
%ResponseLabel.text = "prop_name not set on DeletePropButton"
1212
return
1313

14-
Talo.current_player.delete_prop(prop_name)
14+
var result: PlayersAPI.PlayerUpdateResult = await Talo.current_player.delete_prop(prop_name)
15+
%ResponseLabel.text = "%s deleted successfully" % prop_name if result.success else "Failed to delete %s" % prop_name

0 commit comments

Comments
 (0)