Added first steps to load mechanic, v1.3.0
This commit is contained in:
parent
ae5378090c
commit
14f62410f5
File diff suppressed because it is too large
Load Diff
@ -117,8 +117,8 @@ namespace Assets.Scripts
|
||||
public void saveGame()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
string saveString = "[\r\n{\r\n\"Player\": {\r\n" + player.saveGame();
|
||||
saveString = saveString + "\r\n},\r\n\"World\": {\r\n" + worldGenerator.saveGame() + "\r\n}\r\n}\r\n]";
|
||||
string saveString = "{\r\n\"player\": {\r\n" + player.saveGame();
|
||||
saveString = saveString + "\r\n},\r\n\"world\": {\r\n" + worldGenerator.saveGame() + "\r\n}\r\n}";
|
||||
FileHandler.saveGame(saveString, "./save.json");
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,9 +27,17 @@ namespace Assets.Scripts
|
||||
sw.Close();
|
||||
}
|
||||
|
||||
public static void loadGame()
|
||||
public static void loadGame(Player player, WorldGenerator worldGenerator)
|
||||
{
|
||||
|
||||
if (hasSaveFile())
|
||||
{
|
||||
string[] lines = File.ReadAllLines("./save.json");
|
||||
string jsonString = "";
|
||||
foreach (string line in lines)
|
||||
{
|
||||
jsonString = jsonString + line.Replace("\r\n", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveAudio(string path, float music, float effects)
|
||||
@ -68,5 +76,10 @@ namespace Assets.Scripts
|
||||
{
|
||||
return "\"" + key + "\": " + value;
|
||||
}
|
||||
|
||||
public static bool hasSaveFile()
|
||||
{
|
||||
return File.Exists("./save.json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ namespace Assets.Scripts.Menu
|
||||
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandlerMenu>();
|
||||
audioHandler = GameObject.Find("AudioHandler").GetComponent<AudioHandler>();
|
||||
sceneHandler = GameObject.Find("SceneHandlerLoaded").GetComponent<SceneHandler>();
|
||||
GameObject.Find("btnLoad").SetActive(FileHandler.hasSaveFile());
|
||||
}
|
||||
|
||||
public void startGame()
|
||||
@ -66,5 +67,11 @@ namespace Assets.Scripts.Menu
|
||||
audioHandler.saveAudioSettings();
|
||||
uihandler.closeOptions();
|
||||
}
|
||||
|
||||
public void loadGame()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.loadGame(sceneHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,6 +50,7 @@ namespace Assets.Scripts.Menu
|
||||
PlayerPrefs.SetInt("race", GameObject.Find("dropRace").GetComponent<Dropdown>().value);
|
||||
PlayerPrefs.SetString("playername", GameObject.Find("inName").GetComponent<InputField>().text);
|
||||
PlayerPrefs.SetInt("difficulty", GameObject.Find("dropDifficulty").GetComponent<Dropdown>().value);
|
||||
PlayerPrefs.SetInt("isLoad", 0);
|
||||
sceneHandler.openGameScene();
|
||||
}
|
||||
|
||||
@ -174,5 +175,11 @@ namespace Assets.Scripts.Menu
|
||||
GameObject.Find("txtSecondary_Creation").GetComponent<Text>().text = "Mana: " + playerstats[3];
|
||||
|
||||
}
|
||||
|
||||
public void loadGame(SceneHandler sceneHandler)
|
||||
{
|
||||
PlayerPrefs.SetInt("isLoad", 1);
|
||||
sceneHandler.openGameScene();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -476,14 +476,26 @@ namespace Assets.Scripts
|
||||
}
|
||||
|
||||
public void openIntroduction()
|
||||
{
|
||||
if (PlayerPrefs.GetInt("isLoad") == 0)
|
||||
{
|
||||
GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().resetGame(PlayerPrefs.GetInt("cityAmount"));
|
||||
GameObject.Find("Player").GetComponent<Player>().generatePlayer();
|
||||
GameObject.Find("Player").GetComponent<Player>().finishPlayerCreation();
|
||||
updatePlayerHUD();
|
||||
hideOtherElements(introduction);
|
||||
state = UIState.TUTORIAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
FileHandler.loadGame(GameObject.Find("Player").GetComponent<Player>(), GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>());
|
||||
hideOtherElements(introduction);
|
||||
introduction.transform.localScale = new Vector3(0, 0, 0);
|
||||
tutorial.transform.localScale = new Vector3(0,0,0);
|
||||
showHUD();
|
||||
state = UIState.GAME;
|
||||
}
|
||||
updatePlayerHUD();
|
||||
}
|
||||
|
||||
public void closeTutorial()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user