Skip to content
Snippets Groups Projects
Commit 8a8d4c37 authored by ivarnm's avatar ivarnm
Browse files

#79 Change player_id to player object

parent 242a92d4
No related branches found
No related tags found
1 merge request!76Resolve "Local Storage"
......@@ -77,9 +77,10 @@ public class GameWare extends ApplicationAdapter {
musicOn = true;
// Local Storage
gsm.push(new LoginState(gsm));
readFromLocalStorage();
if(player != null) {
if(player == null) {
gsm.push(new LoginState(gsm));
} else {
gsm.push(new MenuState(gsm));
}
if(musicOn){music.play();}
......@@ -194,11 +195,7 @@ public class GameWare extends ApplicationAdapter {
FileHandle file = Gdx.files.local(localStorageFilePath);
Json json = new Json();
json.setUsePrototypes(false);
String playerId = null;
if(player != null) {
playerId = player.getId();
}
LocalStorage ls = new LocalStorage(playerId, musicOn, soundEffects, includeFin);
LocalStorage ls = new LocalStorage(player, musicOn, soundEffects, includeFin);
String lsString = json.toJson(ls);
file.writeString(lsString, false);
System.out.println(file.readString());
......@@ -210,11 +207,7 @@ public class GameWare extends ApplicationAdapter {
if(!file.exists()) { return; }
String fileOutput = file.readString();
LocalStorage ls = new Json().fromJson(LocalStorage.class, fileOutput);
if(ls.get_id() != null) {
try {
player = QueryIntermediate.getPlayerById(ls.get_id());
} catch (IOException e) {e.printStackTrace();}
}
if(ls.getPlayer() != null) { player = ls.getPlayer(); }
if(ls.getMusicOn() != null) { musicOn = ls.getMusicOn(); }
if(ls.getSoundEffects()!=null){ soundEffects = ls.getSoundEffects(); }
if(ls.getIncludeFin() != null) { includeFin = ls.getIncludeFin(); }
......
package com.gameware.game.models;
public class LocalStorage {
// private Player player;
private String _id; //playerId
private Player player;
private Boolean musicOn;
private Boolean soundEffects;
private Boolean includeFin;
......@@ -10,15 +9,15 @@ public class LocalStorage {
public LocalStorage() {
}
public LocalStorage(String _id, Boolean musicOn, Boolean soundEffects, Boolean includeFin) {
this._id = _id;
public LocalStorage(Player player, Boolean musicOn, Boolean soundEffects, Boolean includeFin) {
this.player = player;
this.musicOn = musicOn;
this.soundEffects = soundEffects;
this.includeFin = includeFin;
}
public String get_id() {
return _id;
public Player getPlayer() {
return player;
}
public Boolean getMusicOn() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment