-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
247 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
66 changes: 66 additions & 0 deletions
66
app/src/main/java/io/cgisca/godot/gpgs/accountinfo/PlayerInfoController.kt
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,66 @@ | ||
package io.cgisca.godot.gpgs.accountinfo | ||
|
||
import android.app.Activity | ||
import com.google.android.gms.auth.api.signin.GoogleSignIn | ||
import com.google.android.gms.games.Games | ||
import com.google.gson.Gson | ||
import io.cgisca.godot.gpgs.ConnectionController | ||
import io.cgisca.godot.gpgs.model.PlayerInfo | ||
import io.cgisca.godot.gpgs.model.PlayerLevel | ||
import io.cgisca.godot.gpgs.model.PlayerLevelInfo | ||
|
||
class PlayerInfoController( | ||
private val activity: Activity, | ||
private val playerInfoListener: PlayerInfoListener, | ||
private val connectionController: ConnectionController | ||
) { | ||
|
||
fun fetchPlayerInfo() { | ||
val googleSignInAccount = GoogleSignIn.getLastSignedInAccount(activity) | ||
if (connectionController.isConnected().first && googleSignInAccount != null) { | ||
Games.getPlayersClient(activity, googleSignInAccount).currentPlayer | ||
.addOnCompleteListener { task -> | ||
val player = task.result | ||
if (task.isSuccessful && player != null) { | ||
val levelInfo = player.levelInfo | ||
val playerLevelInfo = if (levelInfo != null) { | ||
PlayerLevelInfo( | ||
levelInfo.currentXpTotal, | ||
levelInfo.lastLevelUpTimestamp, | ||
if (levelInfo.currentLevel != null) PlayerLevel( | ||
levelInfo.currentLevel.levelNumber, | ||
levelInfo.currentLevel.minXp, | ||
levelInfo.currentLevel.maxXp | ||
) else null, | ||
if (levelInfo.nextLevel != null) PlayerLevel( | ||
levelInfo.nextLevel.levelNumber, | ||
levelInfo.nextLevel.minXp, | ||
levelInfo.nextLevel.maxXp | ||
) else null | ||
) | ||
} else { | ||
null | ||
} | ||
|
||
val playerInfo = PlayerInfo( | ||
player.playerId, | ||
player.displayName, | ||
player.name, | ||
player.iconImageUrl, | ||
player.hiResImageUrl, | ||
player.title, | ||
player.bannerImageLandscapeUrl, | ||
player.bannerImagePortraitUrl, | ||
playerLevelInfo | ||
) | ||
|
||
playerInfoListener.onPlayerInfoLoaded(Gson().toJson(playerInfo)) | ||
} else { | ||
playerInfoListener.onPlayerInfoLoadingFailed() | ||
} | ||
} | ||
} else { | ||
playerInfoListener.onPlayerInfoLoadingFailed() | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/io/cgisca/godot/gpgs/accountinfo/PlayerInfoListener.kt
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,6 @@ | ||
package io.cgisca.godot.gpgs.accountinfo | ||
|
||
interface PlayerInfoListener { | ||
fun onPlayerInfoLoadingFailed() | ||
fun onPlayerInfoLoaded(response: String) | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/io/cgisca/godot/gpgs/model/PlayerInfo.kt
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,28 @@ | ||
package io.cgisca.godot.gpgs.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class PlayerInfo( | ||
@SerializedName("player_id") val playerId: String, | ||
@SerializedName("display_name") val displayName: String, | ||
val name: String, | ||
@SerializedName("icon_image_url") val iconImageUrl: String?, | ||
@SerializedName("hi_res_image_url") val hiResImageUrl: String?, | ||
val title: String?, | ||
@SerializedName("banner_image_landscape_url") val bannerImageLandscapeUrl: String?, | ||
@SerializedName("banner_image_portrait_url") val bannerImagePortraitUrl: String?, | ||
@SerializedName("level_info") val levelInfo: PlayerLevelInfo? | ||
) | ||
|
||
data class PlayerLevelInfo( | ||
@SerializedName("current_xp_total") val currentXpTotal: Long, | ||
@SerializedName("last_level_up_timestamp") val lastLevelUpTimestamp: Long, | ||
@SerializedName("current_level") val currentLevel: PlayerLevel?, | ||
@SerializedName("next_level") val nextLevel: PlayerLevel? | ||
) | ||
|
||
data class PlayerLevel( | ||
@SerializedName("level_number") val levelNumber: Int, | ||
@SerializedName("min_xp") val minXp: Long, | ||
@SerializedName("max_xp") val maxXp: Long | ||
) |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/io/cgisca/godot/gpgs/model/PlayerStats.kt
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,12 @@ | ||
package io.cgisca.godot.gpgs.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class PlayerStats( | ||
@SerializedName("avg_session_length") val avgSessionLength: Double, | ||
@SerializedName("days_last_played") val daysSinceLastPlayed: Int, | ||
@SerializedName("purchases") val numberOfPurchases: Int, | ||
@SerializedName("sessions") val numberOfSessions: Int, | ||
@SerializedName("session_percentile") val sessionPercentile: Double, | ||
@SerializedName("spend_percentile") val spendPercentile: Double | ||
) |
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
Oops, something went wrong.