mirror of
				https://github.com/raylib-cs/raylib-cs
				synced 2025-11-02 05:06:44 -05: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:
		@@ -6,24 +6,44 @@ namespace Examples
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public class Test
 | 
					    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
 | 
					        // menu for testing examples
 | 
				
			||||||
 | 
					        // specify name relative to example directory
 | 
				
			||||||
        public static void Run(string[] args)
 | 
					        public static void Run(string[] args)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Console.WriteLine("Welcome to raylib-cs!");
 | 
					            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)
 | 
					            while (true)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Console.WriteLine("Enter path to example");
 | 
					                Console.Write("Choose a example: ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // select example
 | 
				
			||||||
                var filePath = Console.ReadLine();
 | 
					                var filePath = Console.ReadLine();
 | 
				
			||||||
                var name = Path.GetFileNameWithoutExtension(filePath);
 | 
					                var name = Path.GetFileNameWithoutExtension(filePath);
 | 
				
			||||||
 | 
					                var dir = examples + filePath + ".cs";
 | 
				
			||||||
                Console.WriteLine("Running example " + filePath);
 | 
					                
 | 
				
			||||||
 | 
					                // run example if it exists
 | 
				
			||||||
                ChangeDirectory(filePath);
 | 
					                if (File.Exists(dir))
 | 
				
			||||||
                Type.GetType(name)?.GetMethod("Main")?.Invoke(null, args);
 | 
					                {
 | 
				
			||||||
 | 
					                    ChangeDirectory(Path.GetDirectoryName(dir));
 | 
				
			||||||
                Console.WriteLine();
 | 
					                    Type.GetType(name)?.GetMethod("Main")?.Invoke(null, args);
 | 
				
			||||||
 | 
					                    Console.WriteLine();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    Console.WriteLine(filePath + " is not a valid example");
 | 
				
			||||||
 | 
					                } 
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user