1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-30 02:55:23 +00:00
OpenDiablo2/OpenDiablo2.TestConsole/Program.cs
nicholasdechiara 02e101edb8 Filled out eLevelId enum (#16)
* Filled out eLevelId enum

- Added OpenDiablo2.Core.UT unit test project
- Added ELevelIdHelper class which contains code that generates the enum from the mpq data
- Added a unit test that verifies EngineDataManager works
- Added a unit test that runs the ELevelIdHelper generate function
- Renamed some enum values for constistency (e.g. Act1_Town -> Act1_Town1, as it is in the mpq)

* Retargeted OpenDiablo2.Core.UT to .net Framework 4.6.1

* Added TestConsole

TestConsole currently only supports writing the elevelids enum to a file

Also, removed elevelids generation unit test
2018-11-25 14:12:25 -05:00

165 lines
5.1 KiB
C#

using OpenDiablo2.Common.Enums;
using OpenDiablo2.Common.Models;
using OpenDiablo2.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenDiablo2.TestConsole
{
class Program
{
private static GlobalConfiguration GlobalConfig = null;
private static MPQProvider MPQProv = null;
private static EngineDataManager EngineDataMan = null;
static void Main(string[] args)
{
Console.WriteLine("OpenDiablo2 TestConsole Loaded");
Console.WriteLine("Type 'help' for more info, 'exit' to close.");
bool exit = false;
while (!exit)
{
Console.Write("> ");
string command = Console.ReadLine();
List<string> words = GetWords(command);//new List<string>(command.Split(' '));
string func = words[0].ToUpper();
words.RemoveAt(0);
switch (func)
{
case "HELP":
Help(words);
break;
case "EXIT":
exit = true;
break;
case "LOADDATA":
LoadData(words);
break;
case "WRITELEVELIDS":
WriteELevelIds(words);
break;
}
}
// close out the program after exiting
Environment.Exit(0);
}
public static List<string> GetWords(string msg)
{
List<string> outs = new List<string>();
string curword = "";
bool inquote = false;
int i = 0;
while (i < msg.Length)
{
char c = msg[i];
if (c == '"')
{
inquote = !inquote;
}
else if (c == ' ' && !inquote)
{
outs.Add(curword);
curword = "";
}
else
{
curword += c;
}
i++;
}
outs.Add(curword);
return outs;
}
public static void Help(List<string> words)
{
if(words.Count < 1)
{
Console.WriteLine("Commands: HELP, EXIT, LOADDATA, WRITELEVELIDS");
Console.WriteLine("Type 'HELP [command]' for more info.");
return;
}
string command = words[0].ToUpper();
switch (command)
{
case "LOADDATA":
Console.WriteLine("'LOADDATA [path to mpq folder]' will load the MPQs and parse their data.");
Console.WriteLine("This function is pre-requisite to many others.");
return;
case "WRITELEVELIDS":
Console.WriteLine("'WRITELEVELIDS [filepath to write to]' will write the level ids enum to a file.");
Console.WriteLine("This function requires the data to be loaded first.");
return;
}
// if we get to the end, no command was matched
Help(new List<string>()); // run with an empty list to trigger default message
}
public static void LoadData(List<string> words)
{
if (words.Count < 1)
{
Console.WriteLine("Must supply a path to the folder where the MPQs are stored.");
return;
}
string path = words[0];
if (EngineDataMan != null)
{
Console.WriteLine("Data already loaded!");
return;
}
try
{
GlobalConfig = new GlobalConfiguration
{
BaseDataPath = Path.GetFullPath(path)
};
MPQProv = new MPQProvider(GlobalConfig);
EngineDataMan = new EngineDataManager(MPQProv);
}
catch(Exception e)
{
Console.WriteLine("Failed to load data! " + e.Message);
return;
}
Console.WriteLine("Data loaded.");
}
public static void WriteELevelIds(List<string> words)
{
if (words.Count < 1)
{
Console.WriteLine("Must supply a filepath to write to.");
return;
}
if(EngineDataMan == null)
{
Console.WriteLine("You must load the MPQ data first! See 'HELP LOADDATA'.");
return;
}
string path = words[0];
string output = "public enum eLevelId\r\n{\r\nNone,\r\n";
output += ELevelIdHelper.GenerateEnum(EngineDataMan.LevelPresets);
output += "}";
File.WriteAllText(path, output);
Console.WriteLine("Wrote eLevelIds enum to " + path + ".");
}
}
}