GameNetworkExample
import Felgo 3.0
import QtQuick 2.0
TestBase {
property string textInputState
property bool mergeDataOfOldUserWithNewUser: false
Column {
spacing: 5
Flow {
width: scene.width
spacing: 5
SimpleButton {
text: "Login"
onClicked: {
gameNetwork.authenticateLocalPlayer(true)
}
}
SimpleButton {
text: "Merge old WebStorage data with new user: "+ mergeDataOfOldUserWithNewUser
onClicked: {
mergeDataOfOldUserWithNewUser = !mergeDataOfOldUserWithNewUser
}
}
SimpleButton {
text: "Switch to User with DeviceId"
onClicked: {
textInputState = "deviceId"
nativeUtils.displayTextInput("Enter DeviceId", "", "", gameNetwork.user.deviceId)
}
}
SimpleButton {
text: "Change DevId to UDID"
onClicked: {
gameNetwork.user.facebookId = ""
gameNetwork.user.deviceId = system.UDID
gameNetwork.authenticateLocalPlayer(true)
}
}
SimpleButton {
text: "Change FbId"
onClicked: {
textInputState = "fbId"
nativeUtils.displayTextInput("Enter FacebookId", "", "", gameNetwork.facebookId)
}
}
SimpleButton {
text: "Change FbToken"
onClicked: {
textInputState = "fbToken"
nativeUtils.displayTextInput("Enter FacebookToken", "", "", gameNetwork.facebookToken)
}
}
SimpleButton {
text: "Fb Connect"
color: "green"
opacity: !gameNetwork.facebookConnectionSuccessful ? 1 : 0.2
onClicked: {
console.log("Facebook connect button clicked");
if(system.desktopPlatform) {
gameNetwork.loginWithFacebookCredentials(gameNetwork.facebookId, gameNetwork.facebookToken)
} else {
gameNetwork.connectFacebookUser()
}
}
}
SimpleButton {
id: fbLogoutButton
text: "Disc. Fb"
color: "brown"
opacity: gameNetwork.facebookConnectionSuccessful ? 1 : 0.2
onClicked: {
console.log("Facebook logout button clicked");
gameNetwork.disconnectFacebookUser()
}
}
SimpleButton {
text: gameNetwork.askForWritePermissionsAtFacebookConnect ? "AskWriteOn" : "AskWriteOff"
onClicked: {
gameNetwork.askForWritePermissionsAtFacebookConnect = !gameNetwork.askForWritePermissionsAtFacebookConnect
}
}
SimpleButton {
text: "Fb GET"
onClicked: {
facebook.getGraphRequest("")
}
}
SimpleButton {
text: "Fb POST"
opacity: !gameNetwork.facebookWritePermissionsAllowed ? 1 : 0.2
onClicked: {
facebook.postGraphRequest("")
}
}
SimpleButton {
id: fbDeleteData
text: "Delete Fb Data"
color: "red"
onClicked: {
console.log("Facebook Delete Data button clicked");
gameNetwork.deleteFacebookData()
}
}
SimpleButton {
id: userDelete
text: "Delete User"
color: "red"
onClicked: {
console.log("Delete Profile button clicked");
gameNetwork.deleteUser()
}
}
Connections {
target: nativeUtils
onTextInputFinished: {
if(textInputState === "deviceId" && accepted) {
gameNetwork.facebookId = ""
gameNetwork.facebookToken = ""
gameNetwork.user.deviceId = enteredText
if(mergeDataOfOldUserWithNewUser === false) {
gameNetwork.clearAllStoragesLocally()
}
gameNetwork.__clearUserData()
gameNetwork.userIdChangedOrAboutToChange()
gameNetwork.authenticateLocalPlayer(true)
} else if(textInputState === "fbId" && accepted) {
gameNetwork.facebookId = enteredText
if(system.desktopPlatform) {
gameNetwork.authenticateLocalPlayer(true)
}
} else if(textInputState === "fbToken" && accepted) {
gameNetwork.facebookToken = enteredText
if(system.desktopPlatform) {
gameNetwork.authenticateLocalPlayer(true)
}
}else if(textInputState === "username" && accepted) {
gameNetwork.updateUserName(enteredText)
}else if(textInputState === "userdata" && accepted) {
gameNetwork.updateUserCustomData(enteredText)
}
textInputState = ""
}
}
Connections {
target: gameNetwork.user
onUserBlocked: nativeUtils.displayAlertDialog("User blocked", "User got blocked")
}
SimpleButton {
text: "Change Username"
onClicked: {
textInputState = "username"
nativeUtils.displayTextInput("Enter Username", "", "", gameNetwork.user.name)
}
}
SimpleButton {
text: "Change Custom User data"
onClicked: {
textInputState = "userdata"
nativeUtils.displayTextInput("Enter Userdata", "", "", gameNetwork.user.customData)
}
}
SimpleButton {
text: gameNetwork.pauseRequests ? "PauseRequestsOn" : "PauseRequestsOff"
onClicked: {
gameNetwork.pauseRequests = !gameNetwork.pauseRequests
}
}
SimpleButton {
text: gameNetwork.api.simulateConnectionError ? "Network Off (network errors are simulated)" : "Network On"
onClicked: {
gameNetwork.api.simulateConnectionError = !gameNetwork.api.simulateConnectionError
if(!gameNetwork.api.simulateConnectionError) {
}
}
}
}
Text {
width: parent.width
wrapMode: Text.Wrap
text: "UserId: " + gameNetwork.user.userId + ", UserName: " + gameNetwork.userName + ", DisplayName: " + gameNetwork.displayName + ", DeviceId: " + gameNetwork.user.deviceId + ", CustomData: " + gameNetwork.user.customData + ", Blocked: " + gameNetwork.user.blocked + ", Locale: " + gameNetwork.user.locale + ", Timestamp: " + gameNetwork.user.timestamp + ", Token: " + gameNetwork.user.authenticationToken +
"\nFBId: " + gameNetwork.facebookId + ", FBTokenValid: " + gameNetwork.facebookTokenValid + ", " + (gameNetwork.facebookToken === "" ? "FBTokenEmpty" : "FBTokenSet") + ", grantedFbReadPerm: " + gameNetwork.grantedFacebookReadPermissions + ", grantedFbWritePerm: " + gameNetwork.grantedFacebookWritePermissions + ", grantedFbPerm: " + JSON.stringify(gameNetwork.grantedFacebookPermissions) +
"\nfacebookConnectionState: " + gameNetwork.facebookConnectionState + ", facebookConnectionSuccessful: " + gameNetwork.facebookConnectionSuccessful + ", facebook.sessionState: " + facebook.sessionState
color: "white"
font.pixelSize: 7
}