2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-04-03 11:09:40 -04:00

Update Examples/Test.cs

- Back to using relative paths for testing examples. For example enter "core/core_basic_window".
This commit is contained in:
ChrisDill 2018-10-24 20:06:20 +01:00
parent 527bf58521
commit 0b5bd6f453

View File

@ -6,24 +6,44 @@ namespace Examples
{
public class Test
{
public static string GetExampleDirectory()
{
var dir = Environment.CurrentDirectory;
dir = dir.Substring(0, dir.LastIndexOf("Raylib-cs") + 9) + "\\Examples\\";
return dir;
}
// menu for testing examples
// specify name relative to example directory
public static void Run(string[] args)
{
Console.WriteLine("Welcome to raylib-cs!");
Console.WriteLine("---------------------");
var examples = GetExampleDirectory();
Console.WriteLine("Looking for examples relative to " + examples);
Console.WriteLine("For example, core/core_basic_window");
while (true)
{
Console.WriteLine("Enter path to example");
Console.Write("Choose a example: ");
// select example
var filePath = Console.ReadLine();
var name = Path.GetFileNameWithoutExtension(filePath);
Console.WriteLine("Running example " + filePath);
ChangeDirectory(filePath);
Type.GetType(name)?.GetMethod("Main")?.Invoke(null, args);
Console.WriteLine();
var dir = examples + filePath + ".cs";
// run example if it exists
if (File.Exists(dir))
{
ChangeDirectory(Path.GetDirectoryName(dir));
Type.GetType(name)?.GetMethod("Main")?.Invoke(null, args);
Console.WriteLine();
}
else
{
Console.WriteLine(filePath + " is not a valid example");
}
}
}
}