Exemple #1
0
    /// <summary>
    /// Copy relevant data to new map, that uses new node type
    /// </summary>
    /// <param name="oldMap"></param>
    /// <returns></returns>
    public static LevelMap ConvertToNew(LevelMap_old oldMap)
    {
        if (oldMap.version != 0)
        {
            Debug.Log("Error: map is not version 0, cannot convert to version 1");
            return(null);
        }
        LevelMap newMap = new LevelMap();

        newMap.version         = 1;
        newMap.defaultPosition = oldMap.defaultPosition;                // copy map info
        newMap.sourceNodeIndex = oldMap.sourceNodeIndex;
        newMap.targetNodeIndex = oldMap.targetNodeIndex;
        newMap.checkpoints     = new int[oldMap.checkpoints.Length];
        for (int i = 0; i < oldMap.checkpoints.Length; i++)
        {
            newMap.checkpoints[i] = oldMap.checkpoints[i];
        }
        newMap.stringleft = oldMap.stringleft;

        Node[] newNodes = new Node[oldMap.size];
        for (int i = 0; i < oldMap.size; i++)
        {
            newNodes[i] = oldMap[i].ConvertToNew();             // create matching nodes of the new type
        }

        newMap.setNodes(newNodes);

        //set corner-drawing.

        return(newMap);
    }
Exemple #2
0
 /// <summary>
 /// Loads the map from the given file path.
 /// Prints some warinings if things don't work right.
 /// Returns the loaded map.
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static LevelMap_old Load(string path)
 {
     if (File.Exists(path))                  // can only load the map if the given file exists
     //Debug.Log("Success: map file exists at path: " + path);
     {
         string       jsonData = File.ReadAllText(path);
         LevelMap_old map      = JsonUtility.FromJson <LevelMap_old>(jsonData);
         if (map == null)
         {
             Debug.Log("Error: map is null, WTF?");
             return(null);
         }
         return(map);
     }
     else
     {
         return(null);
     }
 }
 /// <summary>
 /// update map from old version of node
 /// </summary>
 public void updateMapVer()
 {
     Debug.Log("Trying to load level at: \"" + Application.dataPath + levelPath + "/room_" + levelName + ".json\"");
     if (File.Exists(Application.dataPath + levelPath + "/room_" + levelName + ".json"))
     {
         LevelMap_old oldVer = LevelMap_old.Load(Application.dataPath + levelPath + "/room_" + levelName + ".json");
         if (oldVer == null)
         {
             return;
         }
         LevelMap newVer = LevelMap_old.ConvertToNew(oldVer);
         LevelEditor_2.setCornerDrawing(newVer);
         GameManager.gameplay.map = newVer;
         LevelEditor_2.setCornerDrawing(newVer);
         GameManager.gameplay.currentPosition = GameManager.gameplay.map[GameManager.gameplay.map.sourceNodeIndex];
         GameManager.gameplay.resetLevelAssets();
         GameManager.gameplay.levelNameText.text = levelName;
         Debug.Log("Updated level at: \"" + Application.dataPath + levelPath + "/room_" + levelName + ".json\"");
     }
     else
     {
         Debug.Log("Error: Map file does not exist at path \"" + Application.dataPath + levelPath + "/room_" + levelName + ".json\"");
     }
 }