Skip to content

Commit

Permalink
Added Map Output Location Notice to interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mjungnickel18 committed Jun 7, 2020
1 parent 4b42f5c commit cfa70aa
Showing 1 changed file with 51 additions and 21 deletions.
72 changes: 51 additions & 21 deletions PapyrusCs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@ public partial class Program
private static Stopwatch _time = new Stopwatch();
private static Stopwatch _time2 = new Stopwatch();




static int Main(string[] args)
{

var newargs = args;

if (args.Length == 0 || !(new string[]{"map", "test","find"}.Contains(args[0])))
if (args.Length == 0 || !(new string[] { "map", "test", "find" }.Contains(args[0])))
{
newargs = new[] { "map" }.Concat((args)).ToArray();
}


return CommandLine.Parser.Default.ParseArguments<Options, TestOptions, FindOptions>(newargs)
.MapResult(
(Options opts) => {
(Options opts) =>
{
opts.Loaded = true;
return RunMapCommand(opts);
},
Expand All @@ -48,13 +49,14 @@ static int Main(string[] args)
errs => 1);
}





private static int RunMapCommand(Options options)



private static int RunMapCommand(Options options)
{
_time = Stopwatch.StartNew();
bool isInteractiveMode = false;
if (!options.Loaded)
{
return -1;
Expand Down Expand Up @@ -98,17 +100,24 @@ private static int RunMapCommand(Options options)
}

options.FileFormat = options.FileFormat.ToLowerInvariant();
if (new string[] {"jpg", "png", "webp", "none"}.All(x => x != options.FileFormat))
if (new string[] { "jpg", "png", "webp", "none" }.All(x => x != options.FileFormat))
{
Console.WriteLine($"The value {options.FileFormat} is not allowed for option -f");
return -1;
}

if(String.IsNullOrEmpty(options.MinecraftWorld))
if (String.IsNullOrEmpty(options.MinecraftWorld))
{
if (!InteractiveMode(options))
if (InteractiveMode(options))
{
isInteractiveMode = true;
}
else
{
return -1;
}
}

var world = new World();
try
{
Expand Down Expand Up @@ -169,7 +178,7 @@ private static int RunMapCommand(Options options)
Console.WriteLine("Generating a list of all chunk keys in the database.\nThis could take a few minutes");
var keys = world.GetDimension(options.Dimension).ToList();
allSubChunks = Enumerable.ToHashSet(keys.Select(x => new LevelDbWorldKey2(x))
.Where(k => constraintX(k) && constraintZ(k)));
.Where(k => constraintX(k) && constraintZ(k)));

_totalChunk = allSubChunks.GroupBy(x => x.XZ).Count();

Expand Down Expand Up @@ -199,7 +208,7 @@ private static int RunMapCommand(Options options)
int chunksPerDimension = options.ChunksPerDimension;
int tileSize = chunkSize * chunksPerDimension;
Console.WriteLine($"Tilesize is {tileSize}x{tileSize}");

if (String.IsNullOrEmpty(options.OutputPath))
{
options.OutputPath = Path.Combine("generatedmaps", world.WorldName);
Expand Down Expand Up @@ -236,25 +245,46 @@ private static int RunMapCommand(Options options)

var output = new OpenLayers();

output.OutputMap(tileSize,
options.OutputPath,
options.MapHtml,
output.OutputMap(tileSize,
options.OutputPath,
options.MapHtml,
strat.GetSettings(),
strat.IsUpdate,
options.ShowPlayerIcons,
options.ShowPlayerIcons,
world);

strat.Finish();

Console.WriteLine("Total Time {0}", _time.Elapsed);
}
world.Close();


Console.WriteLine("Map generation finished!");
if (options.OutputPath.Length >= 2 && options.OutputPath[1] == ':') // absolute path
{
Console.WriteLine($"Your map is at {options.OutputPath}");
}
else
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine($"Your map is at {Path.Combine(Environment.CurrentDirectory, options.OutputPath)}");
Console.WriteLine();
Console.WriteLine();
}


if (isInteractiveMode)
{
Console.WriteLine("Press enter to close this window!");
Console.ReadLine();
}

world.Close();
return 0;
}




private static IRenderStrategy InstanciateStrategy(Options options)
Expand All @@ -267,7 +297,7 @@ private static IRenderStrategy InstanciateStrategy(Options options)
//strat = new DataFlowStrategy<SKBitmap>(new Maploader.Renderer.Imaging.SkiaSharp());
strat = new DataFlowStrategy<Bitmap>(new Maploader.Renderer.Imaging.SystemDrawing());
break;

}

return strat;
Expand Down Expand Up @@ -316,9 +346,9 @@ private static void ConfigureStrategy(IRenderStrategy strat, Options options,
strat.Profile = options.Profile;
strat.DeleteExistingUpdateFolder = options.DeleteExistingUpdateFolder;
}






private static int CalculateZoom(int xmax, int xmin, int zmax, int zmin, int chunksPerDimension, out int extendedDia)
{
Expand Down

0 comments on commit cfa70aa

Please sign in to comment.