initial config loading system, shadows cvar, assetmanager
This commit is contained in:
39
Source/Game/Console/ConfigParser.cs
Normal file
39
Source/Game/Console/ConfigParser.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.IO;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public class ConfigParser
|
||||
{
|
||||
private ConfigParser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static Config ParseFile(string path)
|
||||
{
|
||||
Config config = new Config();
|
||||
using FileStream file = File.OpenRead(path);
|
||||
using StreamReader sr = new StreamReader(file);
|
||||
|
||||
string line;
|
||||
while ((line = sr.ReadLine()?.Trim()) != null)
|
||||
{
|
||||
if (line.StartsWith(@"//"))
|
||||
continue;
|
||||
|
||||
int spacePos = line.IndexOf(' ');
|
||||
if (spacePos == -1)
|
||||
continue;
|
||||
|
||||
string key = line.Substring(0, spacePos);
|
||||
string value = line.Substring(spacePos+1);
|
||||
|
||||
value = value.Trim('"');
|
||||
|
||||
config[key] = value;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user