Commit df91e3b8 by Philipp Adolf

Allow querying level count in loader

parent 28ad94b1
...@@ -13,6 +13,7 @@ public class GameMaster : MonoBehaviour { ...@@ -13,6 +13,7 @@ public class GameMaster : MonoBehaviour {
// Use this for initialization // Use this for initialization
void Start () { void Start () {
levelLoader = new DeserializedLevelsLoader(); levelLoader = new DeserializedLevelsLoader();
levelLoader.load();
} }
public void loadLevel(int numberOfPlayers, int level = -1) public void loadLevel(int numberOfPlayers, int level = -1)
......
...@@ -7,9 +7,7 @@ using UnityEngine; ...@@ -7,9 +7,7 @@ using UnityEngine;
public class DeserializedLevelsLoader public class DeserializedLevelsLoader
{ {
// Levels deserialized // Levels deserialized
private DeserializedLevels deserializedLevels; private DeserializedLevels deserializedLevels = null;
private int currentLevelIndex = 0;
private const string prefabsFolder = "Prefabs/"; private const string prefabsFolder = "Prefabs/";
...@@ -33,8 +31,27 @@ public class DeserializedLevelsLoader ...@@ -33,8 +31,27 @@ public class DeserializedLevelsLoader
public const string xmlItemsGOName = "XmlItems"; public const string xmlItemsGOName = "XmlItems";
public void load ()
{
deserializedLevels = XmlIO.LoadXml<DeserializedLevels>("Levels");
}
public int getLevelCount ()
{
if (deserializedLevels == null)
throw new System.InvalidOperationException();
return deserializedLevels.levels.Length;
}
public void loadLevel (int levelIndex = 0) public void loadLevel (int levelIndex = 0)
{ {
if (deserializedLevels == null)
throw new System.InvalidOperationException();
if (levelIndex >= deserializedLevels.levels.Length)
throw new System.ArgumentException();
prefabPool = new Dictionary<string, GameObject>(); prefabPool = new Dictionary<string, GameObject>();
sceneItemsList = new List<ItemStruct>(); sceneItemsList = new List<ItemStruct>();
...@@ -44,14 +61,7 @@ public class DeserializedLevelsLoader ...@@ -44,14 +61,7 @@ public class DeserializedLevelsLoader
parentOfXmlItems = new GameObject(xmlItemsGOName).transform; parentOfXmlItems = new GameObject(xmlItemsGOName).transform;
deserializedLevels = XmlIO.LoadXml<DeserializedLevels>("Levels"); DeserializedLevels.Level currentLevel = deserializedLevels.levels[levelIndex];
// if startlevel is in the XML i.e. <Developer StartLevel="3" /> then get level from there
// otherwise start with level 1
currentLevelIndex = (levelIndex > deserializedLevels.levels.Length - 1) ? 0 : levelIndex;
DeserializedLevels.Level currentLevel = deserializedLevels.levels[currentLevelIndex];
sceneItemsList.Clear(); sceneItemsList.Clear();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment