Exemplo n.º 1
0
    public void getLevel(int levelNum)
    {
        setFilePath();

        //level num is a string so that it can separate and also be more specific - e.g. 001 instead of 1. There is reason to my madness.
        string        levelFile  = File.ReadAllText(filePath + "LevelData.txt");
        List <string> levelSplit = levelFile.Split(';').ToList <string>();

        Debug.Log(levelSplit.Count); //last index is blank
        Debug.Log(levelSplit[levelToLoad]);

        string fullLevelString = levelSplit[(levelNum)].TrimStart('|');

        levelSplit = fullLevelString.Split('|').ToList <string>();

        List <BaseTile>   existingTiles = GameObject.Find("SquareGrid").transform.GetComponentsInChildren <BaseTile>().ToList();
        List <Vector2Int> tileCoords    = new List <Vector2Int>();

        //get tile coordinates
        for (int tileNum = 0; tileNum < existingTiles.Count; tileNum++)
        {
            Vector2Int V2Extract;
            ExtractVector2Int(existingTiles[tileNum].name, out V2Extract);
            tileCoords.Insert(tileNum, V2Extract);
        }

        Debug.Log("Remember to clear, create and rename the grid before this");

        //set our custom tiles
        for (int i = (levelToLoad == 0) ? 0 : 1; i < levelSplit.Count; i++)
        {
            string tileInfo = levelSplit[i];
            Debug.Log("TileInfo: " + tileInfo);

            Debug.Log(tileInfo + " is getting tileType");
            //extract tile type
            BaseTile.TileTypes tileType = (BaseTile.TileTypes)System.Enum.Parse(typeof(BaseTile.TileTypes), tileInfo.Substring(0, tileInfo.IndexOf('(')));

            //extract tile coords
            Vector2Int V2Extract;
            ExtractVector2Int(tileInfo, out V2Extract);

            //get current and set tile values
            int      findNum = tileCoords.IndexOf(V2Extract);
            BaseTile target  = existingTiles[findNum];
            target = BaseTile.ChangeTo(tileType, target);
            //***********get target return yeehaw

            //set satellite/output values
            if (tileInfo.Contains("+"))
            {
                string extraVal = tileInfo.Substring(tileInfo.IndexOf('+'));
                if (target.tileType == BaseTile.TileTypes.Satalite)
                {
                    ExtractVector2Int(extraVal, out V2Extract);
                    (target as Satellite).ReflectDirection = V2Extract;
                }
                if (target.tileType == BaseTile.TileTypes.LightOutput)
                {
                    string[] extraVals = extraVal.Split('+');
                    //0 is a blank value... much better ways to do this but I am being #lazy
                    bool doneDirection = false;
                    foreach (string val in extraVals)
                    {
                        if (doneDirection == false && val.Length > 1)
                        {
                            //light direction
                            ExtractVector2Int(val, out V2Extract);
                            Debug.Log(extraVal + " returned " + val + " to " + V2Extract);
                            (target as LightOutput).LightDirection = V2Extract;
                        }
                        else if (val.Length > 1)
                        {
                            //target colour
                            TileColor col = new TileColor();
#if VIV_ToDo
                            extractColor(val, out col);
#endif
                            (target as LightOutput).OutputColour = col;
                            Debug.Log("Got Colour: " + col);
                        }
                    }
                }
                if (target.tileType == BaseTile.TileTypes.LightTarget)
                {
                    TileColor col = new TileColor();
#if VIV_ToDo
                    extractColor(extraVal, out col);
#endif
                    (target as TargetTile).TargetColour = col;
                    Debug.Log("Got Colour: " + col);
                }
            }
        }
    }
Exemplo n.º 2
0
 void ChangeTo(Tile.TileTypes newType)
 {
     BaseTile.ChangeTo(newType, (BaseTile)target);
 }