Chaaaaangesss
This commit is contained in:
parent
ea408ef184
commit
82e787984f
8 changed files with 210 additions and 62 deletions
20
.vscode/launch.json
vendored
Normal file
20
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": ".NET Core Launch (console)",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "launch",
|
||||||
|
"preLaunchTask": "build",
|
||||||
|
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/GraalGmapGenerator.dll",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"console": "internalConsole"
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
24
.vscode/tasks.json
vendored
Normal file
24
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "shell",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
// Ask dotnet build to generate full paths for file names.
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"group": "build",
|
||||||
|
"presentation": {
|
||||||
|
"reveal": "silent"
|
||||||
|
},
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
31
GraalGmapGenerator/GmapWriter.cs
Normal file
31
GraalGmapGenerator/GmapWriter.cs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
using System.IO;
|
||||||
|
using GraalGmapGenerator.Enums;
|
||||||
|
|
||||||
|
namespace GraalGmapGenerator
|
||||||
|
{
|
||||||
|
public static class GmapWriter
|
||||||
|
{
|
||||||
|
private const string TemplateFile = "template.nw";
|
||||||
|
|
||||||
|
public static void SaveGmap(string destinationPath, Gmap gmap)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(destinationPath))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(destinationPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
var gmapContentGen = new GmapContentGenerator(LevelType.Nw);
|
||||||
|
|
||||||
|
// Create a new level file for each level
|
||||||
|
var levelNames = gmapContentGen.GetLevelNames(gmap);
|
||||||
|
foreach (string levelName in levelNames)
|
||||||
|
{
|
||||||
|
File.Copy(TemplateFile, $"{destinationPath}/{levelName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the gmap file
|
||||||
|
var gmapContent = gmapContentGen.Generate(gmap);
|
||||||
|
File.AppendAllText($"{destinationPath}/{gmap.Name}.gmap", gmapContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,7 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
17
GraalGmapGenerator/Helpers.cs
Normal file
17
GraalGmapGenerator/Helpers.cs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace GraalGmapGenerator
|
||||||
|
{
|
||||||
|
public static class Helpers
|
||||||
|
{
|
||||||
|
public static bool YesNoToBool(string input)
|
||||||
|
{
|
||||||
|
var inputLowered = input.ToLower();
|
||||||
|
if (input == "y" || input == "yes")
|
||||||
|
return true;
|
||||||
|
if (input == "n" || input == "no")
|
||||||
|
return false;
|
||||||
|
throw new ArgumentException("Invalid input given.", nameof(input));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,93 +1,129 @@
|
||||||
using GraalGmapGenerator.Enums;
|
using System;
|
||||||
using System;
|
using GraalGmapGenerator.Validators;
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace GraalGmapGenerator
|
namespace GraalGmapGenerator
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
const string TemplateFile = "template.nw";
|
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine(
|
||||||
|
"Welcome to the GMAP generator. You can use this tool to easily generate a GMAP file " +
|
||||||
|
"\nwith the accompanying level files. Simply provide values for settings below, hitting enter " +
|
||||||
|
"\nto move to the next setting."
|
||||||
|
);
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine(
|
||||||
|
"If you run into any problems with the tool, drop me an email at me@aaronjy.me and I " +
|
||||||
|
"\nwill endeavour to respond as soon as possible. " +
|
||||||
|
"\nThanks for using my software! - Aaron Yarborough"
|
||||||
|
);
|
||||||
|
Console.WriteLine("------------------------");
|
||||||
|
|
||||||
var mapBuilder = new GmapBuilder();
|
var mapBuilder = new GmapBuilder();
|
||||||
|
|
||||||
Console.WriteLine("Gmap name...");
|
Console.WriteLine("Gmap name...");
|
||||||
mapBuilder.SetName(Console.ReadLine());
|
string gmapName = Console.ReadLine();
|
||||||
|
mapBuilder.SetName(gmapName);
|
||||||
|
|
||||||
Console.WriteLine("Gmap width (in levels, for example: 8)...");
|
Console.WriteLine("Gmap width (in levels, for example: 8)...");
|
||||||
// need to handle errors
|
int width = int.Parse(
|
||||||
int width;
|
GetInput(
|
||||||
do
|
inputFunc: () => Console.ReadLine(),
|
||||||
{
|
validator: (input) =>
|
||||||
var isValid = int.TryParse(Console.ReadLine(), out width) && width > 0;
|
{
|
||||||
if (!isValid)
|
if (!GmapPropertyValidators.IsValidDimension(input))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Please enter a valid gmap width!");
|
Console.WriteLine("Please enter a valid gmap width!");
|
||||||
}
|
return false;
|
||||||
} while (width <= 0);
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
Console.WriteLine("Gmap height (in levels, for example: 5)...");
|
Console.WriteLine("Gmap height (in levels, for example: 5)...");
|
||||||
int height;
|
int height = int.Parse(
|
||||||
do
|
GetInput(
|
||||||
{
|
inputFunc: () => Console.ReadLine(),
|
||||||
var isValid = int.TryParse(Console.ReadLine(), out height) && height > 0;
|
validator: (input) =>
|
||||||
if (!isValid)
|
{
|
||||||
{
|
if (!GmapPropertyValidators.IsValidDimension(input))
|
||||||
Console.WriteLine("Please enter a valid gmap height!");
|
{
|
||||||
}
|
Console.WriteLine("Please enter a valid gmap height!");
|
||||||
} while (height <= 0);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
mapBuilder.SetDimensions(width, height);
|
mapBuilder.SetDimensions(width, height);
|
||||||
|
|
||||||
Console.WriteLine("Load full map? (y/n)...");
|
Console.WriteLine("Load full map? (y/n)...");
|
||||||
if (Console.ReadLine() == "y")
|
Console.WriteLine("INFO: Loads all map parts into memory on startup.");
|
||||||
{
|
|
||||||
mapBuilder.LoadFullMap(true);
|
var loadFullMapStr = GetInput(
|
||||||
}
|
inputFunc: () => Console.ReadLine(),
|
||||||
|
validator: (input) =>
|
||||||
|
{
|
||||||
|
if (!GmapPropertyValidators.IsValidYesNoInput(input))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please provide a valid \"y\" or \"n\" value!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
mapBuilder.LoadFullMap(Helpers.YesNoToBool(loadFullMapStr));
|
||||||
|
|
||||||
Console.WriteLine("No automapping? (y/n)...");
|
Console.WriteLine("No automapping? (y/n)...");
|
||||||
if (Console.ReadLine() == "y")
|
Console.WriteLine("INFO: Disables the assembly of automagical screenshots into a map that is drawn over the MAPIMG image.");
|
||||||
{
|
|
||||||
mapBuilder.NoAutomapping(true);
|
var noAutoMappingStr = GetInput(
|
||||||
}
|
inputFunc: () => Console.ReadLine(),
|
||||||
|
validator: (input) =>
|
||||||
|
{
|
||||||
|
if (!GmapPropertyValidators.IsValidYesNoInput(input))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please provide a valid \"y\" or \"n\" value!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
mapBuilder.NoAutomapping(Helpers.YesNoToBool(noAutoMappingStr));
|
||||||
|
|
||||||
|
Console.WriteLine("Save directory...");
|
||||||
|
Console.WriteLine($"INFO: If you do not wish to provide a save directory, you can leave this setting blank (hit ENTER) and the GMAP will be created under \"gmaps/\" in the application directory ({AppDomain.CurrentDomain.BaseDirectory}/gmaps/{gmapName}/)");
|
||||||
|
|
||||||
|
// string saveDirectory =
|
||||||
Console.WriteLine("Generating gmap...");
|
Console.WriteLine("Generating gmap...");
|
||||||
var gmap = mapBuilder.Build();
|
var gmap = mapBuilder.Build();
|
||||||
|
|
||||||
Console.WriteLine("Saving gmap...");
|
Console.WriteLine("Saving gmap...");
|
||||||
SaveGmap(gmap);
|
GmapWriter.SaveGmap(gmap);
|
||||||
|
|
||||||
Console.WriteLine("Done!");
|
Console.WriteLine("Done!");
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SaveGmap(Gmap gmap)
|
private static string GetInput(Func<string> inputFunc, Func<string, bool> validator)
|
||||||
{
|
{
|
||||||
const string OutputDirRoot = "gmaps";
|
do
|
||||||
var outputDir = $"{OutputDirRoot}/{gmap.Name}";
|
|
||||||
|
|
||||||
// Create output directory if it doesn't exist
|
|
||||||
if (!Directory.Exists(OutputDirRoot))
|
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(OutputDirRoot);
|
string inputResolved = inputFunc();
|
||||||
}
|
if (validator(inputResolved))
|
||||||
|
{
|
||||||
// Create gmap output directory
|
return inputResolved;
|
||||||
Directory.CreateDirectory(outputDir);
|
}
|
||||||
|
} while (true);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
22
GraalGmapGenerator/Validators/GmapPropertyValidators.cs
Normal file
22
GraalGmapGenerator/Validators/GmapPropertyValidators.cs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace GraalGmapGenerator.Validators
|
||||||
|
{
|
||||||
|
public static class GmapPropertyValidators
|
||||||
|
{
|
||||||
|
public static bool IsValidDimension(string input)
|
||||||
|
{
|
||||||
|
return int.TryParse(input, out int width) && width > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsValidYesNoInput(string input)
|
||||||
|
{
|
||||||
|
var inputLowered = input.ToLower();
|
||||||
|
if (inputLowered == "yes" || inputLowered == "y")
|
||||||
|
return true;
|
||||||
|
if (inputLowered == "no" || inputLowered == "n")
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,7 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue