Skip to content
Snippets Groups Projects
Commit 44f8dfce authored by Ivar Nordvik Myrstad's avatar Ivar Nordvik Myrstad
Browse files

Merge branch '83-update-putroundscore' into 'dev'

Resolve "Update putRoundScore"

Closes #83

See merge request !80
parents ca82fa19 a3ce413f
No related branches found
No related tags found
1 merge request!80Resolve "Update putRoundScore"
...@@ -18,7 +18,7 @@ import com.gameware.game.states.MenuState; ...@@ -18,7 +18,7 @@ import com.gameware.game.states.MenuState;
import com.gameware.game.states.PlayStateTemplate; import com.gameware.game.states.PlayStateTemplate;
import com.gameware.game.states.LoginState; import com.gameware.game.states.LoginState;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -198,8 +198,6 @@ public class GameWare extends ApplicationAdapter { ...@@ -198,8 +198,6 @@ public class GameWare extends ApplicationAdapter {
LocalStorage ls = new LocalStorage(player, musicOn, soundEffects, includeFin); LocalStorage ls = new LocalStorage(player, musicOn, soundEffects, includeFin);
String lsString = json.toJson(ls); String lsString = json.toJson(ls);
file.writeString(lsString, false); file.writeString(lsString, false);
System.out.println(file.readString());
} }
private void readFromLocalStorage() { private void readFromLocalStorage() {
...@@ -211,6 +209,5 @@ public class GameWare extends ApplicationAdapter { ...@@ -211,6 +209,5 @@ public class GameWare extends ApplicationAdapter {
if(ls.getMusicOn() != null) { musicOn = ls.getMusicOn(); } if(ls.getMusicOn() != null) { musicOn = ls.getMusicOn(); }
if(ls.getSoundEffects()!=null){ soundEffects = ls.getSoundEffects(); } if(ls.getSoundEffects()!=null){ soundEffects = ls.getSoundEffects(); }
if(ls.getIncludeFin() != null) { includeFin = ls.getIncludeFin(); } if(ls.getIncludeFin() != null) { includeFin = ls.getIncludeFin(); }
System.out.println(file.readString());
} }
} }
...@@ -11,6 +11,7 @@ import com.badlogic.gdx.utils.JsonReader; ...@@ -11,6 +11,7 @@ import com.badlogic.gdx.utils.JsonReader;
import com.badlogic.gdx.utils.JsonValue; import com.badlogic.gdx.utils.JsonValue;
import com.gameware.game.models.Game; import com.gameware.game.models.Game;
import com.gameware.game.models.Highscore; import com.gameware.game.models.Highscore;
import com.gameware.game.models.ModelInterface;
import com.gameware.game.models.Player; import com.gameware.game.models.Player;
import com.gameware.game.models.Point; import com.gameware.game.models.Point;
import com.gameware.game.models.Round; import com.gameware.game.models.Round;
...@@ -278,16 +279,28 @@ public class QueryIntermediate { ...@@ -278,16 +279,28 @@ public class QueryIntermediate {
return round; return round;
} }
public static Round putRoundScore(String roundId, String tournamentId, int score) public static List<ModelInterface> putRoundScore(String roundId, String tournamentId, int score) throws IOException, NoSuchElementException {
throws IOException, NoSuchElementException {
String route = "rounds/" + roundId + "/" + tournamentId; String route = "rounds/" + roundId + "/" + tournamentId;
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
List<ModelInterface> models = new ArrayList<>();
params.put("scoreValue", Integer.toString(score)); params.put("scoreValue", Integer.toString(score));
String[] response = sendPutRequest(route, params); String[] response = sendPutRequest(route, params);
checkStatusCode(response); checkStatusCode(response);
Round round = json.fromJson(Round.class, response[1]); JsonValue base = jsonReader.parse(response[1]);
String roundString = base.get("round").toString();
String roundCheckString = base.get("roundCheck").toString();
System.out.println(roundCheckString);
System.out.println(roundCheckString.substring(roundCheckString.indexOf("{")));
Round round = json.fromJson(Round.class, roundString.substring(roundString.indexOf("{")));
RoundCheck roundCheck = json.fromJson(RoundCheck.class, roundCheckString.substring(roundCheckString.indexOf("{")));
checkObjectNotNull(round); checkObjectNotNull(round);
return round; checkObjectNotNull(roundCheck);
models.add(round);
models.add(roundCheck);
return models;
} }
// ---------------- Player methods ---------------- // ---------------- Player methods ----------------
......
...@@ -24,7 +24,11 @@ public class RoundCheck implements ModelInterface { ...@@ -24,7 +24,11 @@ public class RoundCheck implements ModelInterface {
} }
@Override @Override
public String report() {return new Json().toJson(this);} public String report() {
Json json = new Json();
json.setUsePrototypes(false);
return json.toJson(this);
}
@Override @Override
public String toString() { public String toString() {
......
...@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Texture; ...@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.GameWare; import com.gameware.game.GameWare;
import com.gameware.game.QueryIntermediate; import com.gameware.game.QueryIntermediate;
import com.gameware.game.models.ModelInterface;
import com.gameware.game.models.Round; import com.gameware.game.models.Round;
import com.gameware.game.models.RoundCheck; import com.gameware.game.models.RoundCheck;
import com.gameware.game.models.Tournament; import com.gameware.game.models.Tournament;
...@@ -13,6 +14,7 @@ import com.gameware.game.sprites.LoadingText; ...@@ -13,6 +14,7 @@ import com.gameware.game.sprites.LoadingText;
import com.gameware.game.sprites.PauseButton; import com.gameware.game.sprites.PauseButton;
import java.io.IOException; import java.io.IOException;
import java.util.List;
public abstract class PlayStateTemplate extends State { public abstract class PlayStateTemplate extends State {
...@@ -119,7 +121,8 @@ public abstract class PlayStateTemplate extends State { ...@@ -119,7 +121,8 @@ public abstract class PlayStateTemplate extends State {
if(round==null) { if(round==null) {
QueryIntermediate.postHighscore(GameWare.getInstance().getPlayer().getId(), gameId, this.score); QueryIntermediate.postHighscore(GameWare.getInstance().getPlayer().getId(), gameId, this.score);
} else{ } else{
updatedRound = QueryIntermediate.putRoundScore(round.get_id(),tournament.get_id(), this.score); List<ModelInterface> updatedRoundModels = QueryIntermediate.putRoundScore(round.get_id(),tournament.get_id(), this.score);
updatedRound = (Round) updatedRoundModels.get(0);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment