config.d 2.1 KB

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