Tidy up project structure. Some updates

This commit is contained in:
Aaron Yarborough 2020-09-12 12:14:09 +02:00
parent 0697973dc7
commit c676907e44
14 changed files with 44 additions and 34 deletions

View file

@ -1,15 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using GraalGmapGenerator.Models;
using GraalGmapGenerator.Options;
namespace GraalGmapGenerator
namespace GraalGmapGenerator.Generators
{
public class GmapContentGenerator
{
readonly GmapContentGenerationOptions _options;
readonly GmapContentGeneratorOptions _options;
public GmapContentGenerator(GmapContentGenerationOptions options)
public GmapContentGenerator(GmapContentGeneratorOptions options)
{
_options = options ?? throw new ArgumentNullException(nameof(options));
}
@ -64,7 +65,7 @@ namespace GraalGmapGenerator
stringBuilder.Append($"\"{level.FileName}\"");
// Only append a comma if its NOT the end of the row
if (i % gmap.Width < (gmap.Width - 1))
if (i % gmap.Width < gmap.Width - 1)
{
stringBuilder.Append(',');
}

View file

@ -1,17 +1,17 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using GraalGmapGenerator.Models;
using GraalGmapGenerator.Options;
namespace GraalGmapGenerator
namespace GraalGmapGenerator.Generators
{
public class LevelContentGenerator
{
private string _templateContent;
private LevelContentGenerationOptions _options;
private LevelContentGeneratorOptions _options;
public LevelContentGenerator(LevelContentGenerationOptions options)
public LevelContentGenerator(LevelContentGeneratorOptions options)
{
_options = options;
_templateContent = GetTemplateFileContent(options.TemplateFilePath);
@ -26,7 +26,7 @@ namespace GraalGmapGenerator
if (_options.AddLevelLinks)
{
IEnumerable<LevelLink> links = GetLevelLinks(gmap, level);
foreach(LevelLink link in links)
foreach (LevelLink link in links)
{
stringBuilder.AppendLine(link.ToString());
}
@ -60,7 +60,7 @@ namespace GraalGmapGenerator
}
// If level is not on the bottom row
if (level.Index < (gmap.Width * gmap.Height) - gmap.Width - 1)
if (level.Index < gmap.Width * gmap.Height - gmap.Width - 1)
{
int linkLevelIndex = level.Index + gmap.Width;
string levelFileName = Level.GetFileName(gmap.Name, linkLevelIndex, level.LevelType);

View file

@ -1,4 +1,6 @@
namespace GraalGmapGenerator
using GraalGmapGenerator.Models;
namespace GraalGmapGenerator
{
public class GmapBuilder
{
@ -40,10 +42,7 @@
_addLevelLinks = value;
return this;
}
/// <summary>
/// Builds the gmap
/// </summary>
public Gmap Build()
{
return new Gmap(

View file

@ -1,5 +1,7 @@
using System.IO;
using GraalGmapGenerator.Enums;
using GraalGmapGenerator.Generators;
using GraalGmapGenerator.Models;
namespace GraalGmapGenerator
{
@ -14,14 +16,14 @@ namespace GraalGmapGenerator
Directory.CreateDirectory(destinationPath);
}
var gmapContentGen = new GmapContentGenerator(new Options.GmapContentGenerationOptions
var gmapContentGen = new GmapContentGenerator(new Options.GmapContentGeneratorOptions
{
LevelType = LevelType.Nw
});
GmapContent gmapContent = gmapContentGen.Generate(gmap);
var levelContentGen = new LevelContentGenerator(new Options.LevelContentGenerationOptions
var levelContentGen = new LevelContentGenerator(new Options.LevelContentGeneratorOptions
{
AddLevelLinks = gmap.AddLevelLinks,
TemplateFilePath = DefaultTemplateFilePath

View file

@ -1,4 +1,4 @@
namespace GraalGmapGenerator
namespace GraalGmapGenerator.Models
{
public class Gmap
{

View file

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace GraalGmapGenerator
namespace GraalGmapGenerator.Models
{
public class GmapContent
{

View file

@ -1,20 +1,20 @@
using System;
using GraalGmapGenerator.Enums;
namespace GraalGmapGenerator
namespace GraalGmapGenerator.Models
{
public class Level
{
public const int Width = 64;
public const int Height = 64;
public string FileName { get; }
public int Index { get; }
public LevelType LevelType { get; }
public Level(Gmap gmap, int index, LevelType levelType)
{
FileName = Level.GetFileName(gmap.Name, index, levelType);
FileName = GetFileName(gmap.Name, index, levelType);
Index = index;
LevelType = levelType;
}
@ -27,7 +27,7 @@ namespace GraalGmapGenerator
throw new NotImplementedException($"{levelType} has not been implemented.");
case LevelType.Nw:
return ".nw";
return ".nw";
case LevelType.Graal:
return ".graal";

View file

@ -1,4 +1,4 @@
namespace GraalGmapGenerator
namespace GraalGmapGenerator.Models
{
public class LevelLink
{
@ -10,7 +10,14 @@ namespace GraalGmapGenerator
public string DestinationX { get; }
public string DestinationY { get; }
public LevelLink(string levelFileName, int x, int y, int width, int height, string destinationX, string destinationY)
public LevelLink(
string levelFileName,
int x,
int y,
int width,
int height,
string destinationX,
string destinationY)
{
LevelFileName = levelFileName;
X = x;

View file

@ -2,7 +2,7 @@ using GraalGmapGenerator.Enums;
namespace GraalGmapGenerator.Options
{
public class GmapContentGenerationOptions
public class GmapContentGeneratorOptions
{
public LevelType LevelType { get; set; }
}

View file

@ -1,6 +1,6 @@
namespace GraalGmapGenerator.Options
{
public class LevelContentGenerationOptions
public class LevelContentGeneratorOptions
{
public string TemplateFilePath { get; set; }
public bool AddLevelLinks { get; set; }

View file

@ -4,9 +4,9 @@ namespace GraalGmapGeneratorTests.Fake
{
internal static class GmapContentGenerationOptionsFake
{
internal static GmapContentGenerationOptions Get()
internal static GmapContentGeneratorOptions Get()
{
return new GmapContentGenerationOptions
return new GmapContentGeneratorOptions
{
LevelType = GraalGmapGenerator.Enums.LevelType.Graal
};

View file

@ -1,4 +1,4 @@
using GraalGmapGenerator;
using GraalGmapGenerator.Models;
namespace GraalGmapGeneratorTests.Fake
{

View file

@ -1,5 +1,6 @@
using GraalGmapGenerator;
using GraalGmapGenerator.Enums;
using GraalGmapGenerator.Enums;
using GraalGmapGenerator.Generators;
using GraalGmapGenerator.Models;
using GraalGmapGenerator.Options;
using GraalGmapGeneratorTests.Fake;
using NUnit.Framework;
@ -91,7 +92,7 @@ namespace GraalGmapGeneratorTests
public void Generate_SavesValidLevels_ForLevelType(LevelType levelType, string expectedFileExtension)
{
Gmap gmap = GmapFake.Get();
var generator = new GmapContentGenerator(new GmapContentGenerationOptions
var generator = new GmapContentGenerator(new GmapContentGeneratorOptions
{
LevelType = levelType
});

View file

@ -1,4 +1,4 @@
using GraalGmapGenerator;
using GraalGmapGenerator.Models;
using NUnit.Framework;
namespace GraalGmapGeneratorTests