示例#1
0
        static void SaveGmap(Gmap gmap)
        {
            const string OutputDirRoot = "gmaps";
            var          outputDir     = $"{OutputDirRoot}/{gmap.Name}";

            // Create output directory if it doesn't exist
            if (!Directory.Exists(OutputDirRoot))
            {
                Directory.CreateDirectory(OutputDirRoot);
            }

            // Create gmap output directory
            Directory.CreateDirectory(outputDir);

            var gmapContentGen = new GmapContentGenerator(LevelType.Nw);

            // Create a new level file for each level
            var levelNames = gmapContentGen.GetLevelNames(gmap);

            foreach (var level in levelNames)
            {
                File.Copy(TemplateFile, $"{outputDir}/{level}");
            }

            // Create the gmap file
            var gmapContent = gmapContentGen.Generate(gmap);

            File.AppendAllText($"{outputDir}/{gmap.Name}.gmap", gmapContent);
        }
        public IEnumerable <string> GetLevelNames(Gmap gmap)
        {
            var levelNames = new List <string>();

            for (var i = 0; i < (gmap.Width * gmap.Height); i++)
            {
                levelNames.Add(GetLevelName(i, gmap.Name, _levelType));
            }

            return(levelNames);
        }
        /// <summary>
        /// Returns the gmap file contents
        /// </summary>
        /// <returns></returns>
        public string Generate(Gmap gmap)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("GRMAP001");
            stringBuilder.AppendLine($"WIDTH {gmap.Width}");
            stringBuilder.AppendLine($"HEIGHT {gmap.Height}");

            if (gmap.NoAutomapping)
            {
                stringBuilder.AppendLine("NOAUTOMAPPING");
            }

            if (gmap.LoadFullMap)
            {
                stringBuilder.AppendLine("LOADFULLMAP");
            }

            stringBuilder.AppendLine("LEVELNAMES");

            var levelNames = GetLevelNames(gmap).ToList();

            for (var i = 0; i < levelNames.Count; i++)
            {
                // Start a new line once the current line has hit the width of the gmap
                if (i > 0 && i % gmap.Width == 0)
                {
                    stringBuilder.AppendLine();
                }

                var levelName = GetLevelName(i, gmap.Name, _levelType);
                stringBuilder.Append($"\"{levelName}\"");

                // Only append a comma if its NOT the end of the row
                if (i % gmap.Width < (gmap.Width - 1))
                {
                    stringBuilder.Append(',');
                }
            }

            stringBuilder.AppendLine();
            stringBuilder.Append("LEVELNAMESEND");

            return(stringBuilder.ToString());
        }