1 /** 2 * Defines the static class Config, which handles all configuration options. 3 */ 4 module dash.utility.config; 5 import dash.utility.resources, dash.utility.data; 6 7 import std.experimental.logger; 8 import std.datetime; 9 10 /** 11 * The global instance of config. 12 */ 13 private Config configInst; 14 /// ditto 15 const(Config) config() @property 16 { 17 return configInst; 18 } 19 20 /** 21 * Static class which handles the configuration options and YAML interactions. 22 */ 23 struct Config 24 { 25 public: 26 @rename( "Logging" ) @optional 27 LoggerSettings logging; 28 @rename( "Display" ) @optional 29 DisplaySettings display; 30 @rename( "Graphics" ) @optional 31 GraphicsSettings graphics; 32 @rename( "UserInterface" ) @optional 33 UserInterfaceSettings userInterface; 34 @rename( "Editor" ) @optional 35 EditorSettings editor; 36 37 static struct LoggerSettings 38 { 39 @rename( "FilePath" ) @optional 40 string filePath = "dash.log"; 41 @rename( "Debug" ) @optional 42 Verbosities debug_ = Verbosities( LogLevel.all, LogLevel.all ); 43 @rename( "Release" ) @optional 44 Verbosities release = Verbosities( LogLevel.off, LogLevel.error ); 45 46 @ignore 47 Verbosities verbosities() const @property pure @safe nothrow @nogc 48 { 49 debug return debug_; 50 else return release; 51 } 52 53 static struct Verbosities 54 { 55 @rename( "OutputVerbosity" ) @optional @byName 56 LogLevel outputVerbosity = LogLevel.info; 57 @rename( "LoggingVerbosity" ) @optional @byName 58 LogLevel loggingVerbosity = LogLevel.all; 59 } 60 } 61 62 static struct DisplaySettings 63 { 64 @rename( "Fullscreen" ) 65 bool fullscreen; 66 @rename( "Height" ) @optional 67 uint height = 1920; 68 @rename( "Width" ) @optional 69 uint width = 720; 70 } 71 72 static struct GraphicsSettings 73 { 74 @rename( "BackfaceCulling" ) @optional 75 bool backfaceCulling = true; 76 @rename( "VSync" ) @optional 77 bool vsync = false; 78 @rename( "OpenGL33" ) @optional 79 bool usingGl33 = false; 80 } 81 82 static struct UserInterfaceSettings 83 { 84 @rename( "FilePath" ) @optional 85 string filePath = null; 86 } 87 88 static struct EditorSettings 89 { 90 @rename( "Port" ) @optional 91 ushort port = 8080; 92 @rename( "Route" ) @optional 93 string route = "ws"; 94 } 95 96 static: 97 @ignore 98 private Resource resource = internalResource; 99 100 void initialize() 101 { 102 auto res = deserializeFileByName!Config( Resources.ConfigFile ); 103 configInst = res[ 0 ]; 104 resource = res[ 1 ]; 105 } 106 107 void refresh() 108 { 109 if( resource.needsRefresh ) 110 { 111 configInst = deserializeFile!Config( resource ); 112 } 113 } 114 }