GameNetworkExample
import Felgo 3.0
import QtQuick 2.0
import "."
TestBase {
property alias challengeView: challengeView
property alias friendsView: challengeView.friendsView
property variant gameNetworkItem: gameNetwork
property int lastChallengeId: -1
ChallengeView {
id: challengeView
anchors.fill: parent
debugMode: true
}
Column {
visible: challengeView.state === "challengeOverview"
anchors.bottom: parent.bottom
Text {
color: "white"
text: "lastChallengeId: " + lastChallengeId
}
SimpleButton {
text: "Submit score to lastChallengeId"
onClicked: {
if(lastChallengeId === -1)
return;
gameNetwork.reportScore(Math.round(scoreSlider.value), "challenges", [lastChallengeId])
}
}
Row {
spacing: 20
GameSlider {
id: scoreSlider
minimumValue: -1000
maximumValue: 1000
value: 10
width: 200
height: 20
}
Text {
text: Math.round(scoreSlider.value)
color: "white"
}
}
SimpleButton {
text: "Receive all user challenges (see log output)"
onClicked: {
gameNetwork.api.getUserChallenges()
}
}
}
Connections {
target: gameNetworkItem
onChallengeCreated: {
console.debug("onChallengeCreated:", JSON.stringify(challengeData))
nativeUtils.displayMessageBox("Challenge created", "You can now submit a score to the challenge")
challengeView.state = "challengeOverview"
lastChallengeId = challengeData.id
}
onChallengeWithScoreSubmitted: {
console.debug("onChallengeWithScoreSubmitted:", JSON.stringify(challengeData))
nativeUtils.displayMessageBox("Challenge score submitted", "Waiting for the friend to complete the challenge")
lastChallengeId = -1
}
onChallengeAccepted: {
console.debug("onChallengeAccepted:", JSON.stringify(challengeData))
nativeUtils.displayMessageBox("Challenge was accepted", "Submit a score to the challenge to complete it")
lastChallengeId = challengeData.id
}
onChallengeCompleted: {
console.debug("onChallengeCompleted:", JSON.stringify(challengeData))
nativeUtils.displayMessageBox("Challenge completed", "Winner is: " + challengeData.winner.name + ", with score ")
lastChallengeId = -1
}
onLastQueriedUserChallengeListChanged: {
console.debug("onLastQueriedUserChallengeListChanged to:", JSON.stringify(gameNetwork.lastQueriedUserChallengeList) )
}