Abedalkareem / games_services

A Flutter plugin to support game center and google play games services.
122 stars 49 forks source link

Get Player Rank on A Laderboard #147

Closed francichecco closed 2 months ago

francichecco commented 9 months ago

Actually the Player class has only this method

getPlayerScore(
    {dynamic iOSLeaderboardID = "",
    dynamic androidLeaderboardID = ""}
)

with that I can retrive the player score on a laderboard.

Could you add the method to retrive the player ranking on a laderboard ? public abstract [String] getDisplayRank () <----------------------------------------- ADD THIS PLS

https://developers.google.com/android/reference/com/google/android/gms/games/leaderboard/LeaderboardScore

theLee3 commented 9 months ago

@Abedalkareem We could easily return a LeaderboardScoreData object that would contain the score, rank * more. Should we do so from getPlayerScore or create a new method getPlayerScoreData and encourage its use going forward?

There is no need to provide both individually as we are already retrieving the object with all of this information to just return the score value, and it would be wasteful to make extra network calls for data we have already retrieved.

egonbeermat commented 8 months ago

@theLee3 @Abedalkareem I actually implemented this about a year ago in a local modified version of this package, a method to retrieve a players score rank on leaderboards. I wanted to retrieve specifically by span - today, this week, all time - but getPlayerScore is only fixed to allTime and, not wanting to mess with an existing method given I'm not very familiar with native development, I cut and paste code into a new method getPlayerScoreObject that returns a fully populated LeaderboardScoreData, including the rank, on both iOS and Android.

I have created a pull request that incorporates this and a few other potentially useful (and non-breaking?) enhancements I use. Feel free to pick apart and re-write, but hopefully use!

Abedalkareem commented 5 months ago

Thanks, I approved the PR can you fix the conflict and then we can merge it @theLee3 what do you think?

egonbeermat commented 5 months ago

I resolved the conflict (I think! My first ever PR on another repo)

Abedalkareem commented 5 months ago

@egonbeermat That's awesome! Congrats on your first PR!

Thank you!

theLee3 commented 2 months ago

Great stuff @egonbeermat! Congrats!

Sorry I did not get involved before the PR was approved. Personal stuff got in the way. While I have not poured over the code committed, I have now used your work, including in part of my recent PR. As far as I can tell, everything works well.

egonbeermat commented 2 months ago

@theLee3 Thanks! Glad it all appears to work for you! I understand completely about that pesky personal stuff :)

theLee3 commented 2 months ago

Added in #155