Esempio n. 1
0
        // Method that loads the layers
        private void LoadLevelFromStringLayers(string path)
        {
            var lines           = File.ReadAllLines(path);
            var boardParameters = lines.First().Split(',').Select(int.Parse).ToList();
            var width           = boardParameters[0];
            var height          = boardParameters[1];
            var depth           = boardParameters[2];

            for (var y = 0; y < height; y++)
            {
                var line = lines[y + 1].Split(LevelLoader.WidthSeparator.ToCharArray());
                for (var x = 0; x < width; x++)
                {
                    var cell = line[x].Split(LevelLoader.DepthSeparator.ToCharArray());
                    for (var z = 0; z < depth; z++)
                    {
                        var    blockString = cell[z];
                        string pieceValue  = null;
                        if (blockString.StartsWith("piece"))
                        {
                            pieceValue  = blockString.Substring(5);
                            blockString = "piece";
                        }
                        _levelEditor.CreateBlock(TileStringRepresentationToInt(blockString), x, y, z, pieceValue);
                    }
                }
            }
        }
        // Loads one layer
        private void LoadLevelFromString(int layer, string content)
        {
            // Split our layer on rows by the new lines (\n)
            List <string> lines = new List <string>(content.Split('\n'));

            // Place each block in order in the correct x and y position
            for (int i = 0; i < lines.Count; i++)
            {
                string[] blockIDs = lines[i].Split(',');
                for (int j = 0; j < blockIDs.Length - 1; j++)
                {
                    _levelEditor.CreateBlock(TileStringRepresentationToInt(blockIDs[j]), j, lines.Count - i - 1, layer);
                }
            }
            // Update to only show the correct layer(s)
            _levelEditor.UpdateLayerVisibility();
        }