Skip to content
Snippets Groups Projects
Commit 911ff8fe authored by Taneli Riihimäki's avatar Taneli Riihimäki
Browse files

Continue working on getting the factions and joining into them

parent 7e8674af
No related branches found
No related tags found
No related merge requests found
...@@ -42,40 +42,53 @@ class GameList extends Component { ...@@ -42,40 +42,53 @@ class GameList extends Component {
console.log(error); console.log(error);
}); });
} }
// Get all the factions from the server
getFactions() { getFactions() {
fetch(`https://tacs-testing.cf:8443/game/${this.state.selectedGame.id}`), fetch(`https://tacs-testing.cf:8443/game/${this.state.selectedGame.id}`, {
{ method: "GET",
method: "GET", headers: {
headers: { Accept: "application/json",
Accept: "application/json", "Content-Type": "application/json"
"Content-Type": "application/json"
}
} }
.then(response => response.json()) })
.then(factions => { .then(response => response.json())
console.log(factions); .then(factions => {
// this.setState({ console.log(factions);
// factions, this.setState({
// selectedFaction: factions[0] factions: factions.factions,
// }); selectedFaction: factions[0]
})
.catch(error => {
console.log(error);
}); });
})
.catch(error => {
console.log(error);
});
} }
joinFaction() {} joinFaction() {}
// Toggles the tracking boolean // Toggles the tracking boolean (some thought mistake somewhere makes this kinda weird ¯\_(ツ)_/¯ )
handleTrackingChange() { handleTrackingChange() {
this.setState({ tracking: !this.state.tracking }); this.setState({ tracking: !this.state.tracking });
if (!this.state.tracking) {
this.startTracking();
} else if (this.state.tracking) {
this.stopTracking();
}
} }
// Start the player tracking with the wanted interval (ms) // Start the player tracking with the wanted interval (ms)
startTracking() { startTracking() {
let interval = 3000; this.getCurrentLocation();
let interval = 10000;
this.intervalID = setInterval(() => { this.intervalID = setInterval(() => {
console.log( console.log(
"Nyt träkätää nim birusti peliä: " + this.state.selectedGame.name "Nyt träkätää nim birusti peliä: " + this.state.selectedGame.name
); );
console.log(
"Pelaajan latitude: " +
this.state.userLocation.latitude +
"Pelaajan longitude: " +
this.state.userLocation.longitude
);
fetch( fetch(
`https:/tacs-testing.cf:8443/tracking/location/${ `https:/tacs-testing.cf:8443/tracking/location/${
this.state.selectedGame.id this.state.selectedGame.id
...@@ -110,11 +123,11 @@ class GameList extends Component { ...@@ -110,11 +123,11 @@ class GameList extends Component {
// Start & stop tracking depending on the boolean 'tracking' in state // Start & stop tracking depending on the boolean 'tracking' in state
componentDidUpdate() { componentDidUpdate() {
if (this.state.tracking) { // if (this.state.tracking) {
this.startTracking(); // this.startTracking();
} else if (!this.state.tracking) { // } else if (!this.state.tracking) {
this.stopTracking(); // this.stopTracking();
} // }
} }
// When you select a game with the picker, clears the tracking interval and gets the factions of the game // When you select a game with the picker, clears the tracking interval and gets the factions of the game
selectGame = (selectedGame, itemIndex) => { selectGame = (selectedGame, itemIndex) => {
...@@ -137,6 +150,7 @@ class GameList extends Component { ...@@ -137,6 +150,7 @@ class GameList extends Component {
}; };
navigator.geolocation.getCurrentPosition( navigator.geolocation.getCurrentPosition(
position => { position => {
console.log("Position : " + position);
this.setState({ this.setState({
userLocation: { userLocation: {
latitude: position.coords.latitude, latitude: position.coords.latitude,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment