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