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()
|
public void saveGame()
|
||||||
{
|
{
|
||||||
audioHandler.playButtonClick();
|
audioHandler.playButtonClick();
|
||||||
string saveString = "[\r\n{\r\n\"Player\": {\r\n" + player.saveGame();
|
string saveString = "{\r\n\"player\": {\r\n" + player.saveGame();
|
||||||
saveString = saveString + "\r\n},\r\n\"World\": {\r\n" + worldGenerator.saveGame() + "\r\n}\r\n}\r\n]";
|
saveString = saveString + "\r\n},\r\n\"world\": {\r\n" + worldGenerator.saveGame() + "\r\n}\r\n}";
|
||||||
FileHandler.saveGame(saveString, "./save.json");
|
FileHandler.saveGame(saveString, "./save.json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,9 +27,17 @@ namespace Assets.Scripts
|
|||||||
sw.Close();
|
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)
|
public static void saveAudio(string path, float music, float effects)
|
||||||
@ -68,5 +76,10 @@ namespace Assets.Scripts
|
|||||||
{
|
{
|
||||||
return "\"" + key + "\": " + value;
|
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>();
|
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandlerMenu>();
|
||||||
audioHandler = GameObject.Find("AudioHandler").GetComponent<AudioHandler>();
|
audioHandler = GameObject.Find("AudioHandler").GetComponent<AudioHandler>();
|
||||||
sceneHandler = GameObject.Find("SceneHandlerLoaded").GetComponent<SceneHandler>();
|
sceneHandler = GameObject.Find("SceneHandlerLoaded").GetComponent<SceneHandler>();
|
||||||
|
GameObject.Find("btnLoad").SetActive(FileHandler.hasSaveFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startGame()
|
public void startGame()
|
||||||
@ -66,5 +67,11 @@ namespace Assets.Scripts.Menu
|
|||||||
audioHandler.saveAudioSettings();
|
audioHandler.saveAudioSettings();
|
||||||
uihandler.closeOptions();
|
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.SetInt("race", GameObject.Find("dropRace").GetComponent<Dropdown>().value);
|
||||||
PlayerPrefs.SetString("playername", GameObject.Find("inName").GetComponent<InputField>().text);
|
PlayerPrefs.SetString("playername", GameObject.Find("inName").GetComponent<InputField>().text);
|
||||||
PlayerPrefs.SetInt("difficulty", GameObject.Find("dropDifficulty").GetComponent<Dropdown>().value);
|
PlayerPrefs.SetInt("difficulty", GameObject.Find("dropDifficulty").GetComponent<Dropdown>().value);
|
||||||
|
PlayerPrefs.SetInt("isLoad", 0);
|
||||||
sceneHandler.openGameScene();
|
sceneHandler.openGameScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,5 +175,11 @@ namespace Assets.Scripts.Menu
|
|||||||
GameObject.Find("txtSecondary_Creation").GetComponent<Text>().text = "Mana: " + playerstats[3];
|
GameObject.Find("txtSecondary_Creation").GetComponent<Text>().text = "Mana: " + playerstats[3];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadGame(SceneHandler sceneHandler)
|
||||||
|
{
|
||||||
|
PlayerPrefs.SetInt("isLoad", 1);
|
||||||
|
sceneHandler.openGameScene();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -477,12 +477,24 @@ namespace Assets.Scripts
|
|||||||
|
|
||||||
public void openIntroduction()
|
public void openIntroduction()
|
||||||
{
|
{
|
||||||
GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().resetGame(PlayerPrefs.GetInt("cityAmount"));
|
if (PlayerPrefs.GetInt("isLoad") == 0)
|
||||||
GameObject.Find("Player").GetComponent<Player>().generatePlayer();
|
{
|
||||||
GameObject.Find("Player").GetComponent<Player>().finishPlayerCreation();
|
GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().resetGame(PlayerPrefs.GetInt("cityAmount"));
|
||||||
|
GameObject.Find("Player").GetComponent<Player>().generatePlayer();
|
||||||
|
GameObject.Find("Player").GetComponent<Player>().finishPlayerCreation();
|
||||||
|
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();
|
updatePlayerHUD();
|
||||||
hideOtherElements(introduction);
|
|
||||||
state = UIState.TUTORIAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeTutorial()
|
public void closeTutorial()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user