config.d 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 string parseConf(string type, string filename) {
  10. try
  11. {
  12. auto file = File(filename);
  13. auto config = file.byLineCopy();
  14. static immutable typeMap = [
  15. "script": "SCRIPT:",
  16. "title": "TITLE:",
  17. "icon": "ICON:",
  18. "dialog_end_indicator": "DIALOG_END_INDICATOR:",
  19. "dialog_box": "DIALOG_BOX:",
  20. "fallback_font": "FALLBACK_FONT:",
  21. "default_screen_width": "DEFAULT_SCREEN_WIDTH:",
  22. "default_screen_height": "DEFAULT_SCREEN_HEIGHT:",
  23. "screen_width": "SCREEN_WIDTH:",
  24. "screen_height": "SCREEN_HEIGHT:",
  25. "default_fullscreen": "DEFAULT_FULLSCREEN:"
  26. ];
  27. if (type in typeMap)
  28. {
  29. auto prefix = typeMap[type];
  30. foreach (line; config)
  31. {
  32. auto trimmedLine = strip(line);
  33. if (trimmedLine.startsWith(prefix))
  34. {
  35. auto value = trimmedLine[prefix.length .. $].strip();
  36. debug debugWriteln("Value for ", type, ": ", value);
  37. return value;
  38. }
  39. }
  40. }
  41. }
  42. catch (Exception e)
  43. {
  44. debugWriteln(e.msg);
  45. }
  46. return "";
  47. }
  48. SystemSettings loadSettingsFromConfigFile(string confName) {
  49. return SystemSettings(
  50. parseConf("script", confName),
  51. parseConf("title", confName),
  52. parseConf("icon", confName),
  53. parseConf("dialog_end_indicator", confName),
  54. parseConf("dialog_box", confName),
  55. parseConf("fallback_font", confName),
  56. parseConf("default_screen_width", confName).to!int,
  57. parseConf("default_screen_height", confName).to!int,
  58. parseConf("screen_width", confName).to!int,
  59. parseConf("screen_height", confName).to!int,
  60. parseConf("default_fullscreen", confName).to!bool
  61. );
  62. }