config.d 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. module system.config;
  2. import std.stdio;
  3. import std.file;
  4. import std.string;
  5. import std.range;
  6. import variables;
  7. import std.conv;
  8. import system.abstraction;
  9. nothrow char parseConf(string filename, string type)
  10. {
  11. try
  12. {
  13. auto file = File(filename);
  14. auto config = file.byLineCopy();
  15. //mappings
  16. auto typeMap = [
  17. "sound": "SOUND:",
  18. "backward": "BACKWARD:",
  19. "forward": "FORWARD:",
  20. "right": "RIGHT:",
  21. "left": "LEFT:",
  22. "dialog": "DIALOG:",
  23. "opmenu": "OPMENU:"
  24. ];
  25. if (type in typeMap)
  26. {
  27. auto prefix = typeMap[type];
  28. foreach (line; config)
  29. {
  30. auto trimmedLine = strip(line);
  31. if (trimmedLine.startsWith(prefix))
  32. {
  33. auto button = trimmedLine[prefix.length .. $].strip();
  34. debug debugWriteln("Value for ", type, ": ", button);
  35. return button.front.to!char;
  36. }
  37. }
  38. }
  39. }
  40. catch (Exception e)
  41. {
  42. debugWriteln(e.msg);
  43. }
  44. return 'E';
  45. }
  46. SystemSettings loadSettingsFromConfigFile()
  47. {
  48. return SystemSettings(
  49. parseConf("conf/settings.conf", "right"),
  50. parseConf("conf/settings.conf", "left"),
  51. parseConf("conf/settings.conf", "backward"),
  52. parseConf("conf/settings.conf", "forward"),
  53. parseConf("conf/settings.conf", "dialog"),
  54. parseConf("conf/settings.conf", "opmenu"),
  55. parseConf("conf/settings.conf", "sound")
  56. );
  57. }