Incremental Engine  1.0.6
A 2D Game Engine to create Idle Games
IncrementalEngine::Config Struct Reference

#include <Config.h>

Public Member Functions

 Config ()
 

Public Attributes

std::string ApplicationName
 
bool Fullscreen
 
D3DXVECTOR2 WindowSize
 
float ScreenDepth
 
float ScreenNear
 
bool VsyncEnabled
 
bool ShowCursor
 
D3DXVECTOR4 BackgroundColor
 

Private Member Functions

void ReadConfigElement (std::string name, std::string type, Json object)
 
void ReadString (std::string name, std::string object)
 
void ReadInt (std::string name, int object)
 
void ReadFloat (std::string name, float object)
 
void ReadBool (std::string name, bool object)
 
void ReadVector2 (std::string name, D3DXVECTOR2 object)
 
void ReadColor (std::string name, D3DXVECTOR4 object)
 

Detailed Description

Definition at line 13 of file Config.h.

Constructor & Destructor Documentation

◆ Config()

IncrementalEngine::Config::Config ( )

Definition at line 6 of file Config.cpp.

7  {
8  std::ifstream t(PATH);
9  std::string json(
10  (std::istreambuf_iterator<char>(t)),
11  std::istreambuf_iterator<char>()
12  );
13 
14  std::string error = "";
15  auto resources = Json::parse(json, error);
16 
17  if (error != "")
18  {
19  StringAsWCHAR_ptr(error, LPCWSTR Error);
20  MessageBox(NULL, Error, L"Config Error", MB_OK);
21  }
22 
23  auto items = resources.object_items();
24  if (items.empty())
25  {
26  MessageBox(NULL, L"Resources load failed. Check file structure.", L"Config Error", MB_OK);
27  }
28 
29  HRESULT result;
30  for (auto const& item : items)
31  {
32  auto obj = item.second.object_items().begin();
33  ReadConfigElement(item.first, obj->first, obj->second);
34  }
35  }

Member Function Documentation

◆ ReadBool()

void IncrementalEngine::Config::ReadBool ( std::string  name,
bool  object 
)
private

Definition at line 105 of file Config.cpp.

106  {
107  if (name == "Fullscreen")
108  Fullscreen = object;
109 
110  if (name == "VsyncEnabled")
111  VsyncEnabled = object;
112 
113  if (name == "ShowCursor")
114  ShowCursor = object;
115  }

◆ ReadColor()

void IncrementalEngine::Config::ReadColor ( std::string  name,
D3DXVECTOR4  object 
)
private

Definition at line 123 of file Config.cpp.

124  {
125  if (name == "BackgroundColor")
126  BackgroundColor = object;
127  }

◆ ReadConfigElement()

void IncrementalEngine::Config::ReadConfigElement ( std::string  name,
std::string  type,
Json  object 
)
private

Definition at line 39 of file Config.cpp.

40  {
41  if (type == "string")
42  {
43  ReadString(name, object.string_value());
44  }
45 
46  if (type == "int")
47  {
48  ReadInt(name, object.int_value());
49  }
50 
51  if (type == "float")
52  {
53  ReadFloat(name, object.number_value());
54  }
55 
56  if (type == "bool")
57  {
58  ReadBool(name, object.bool_value());
59  }
60 
61  if (type == "vector2")
62  {
63  auto items = object.object_items();
64  D3DXVECTOR2 vector = D3DXVECTOR2(
65  (items.find("x")->second).number_value(),
66  (items.find("y")->second).number_value()
67  );
68  ReadVector2(name, vector);
69  }
70 
71  if (type == "color")
72  {
73  auto items = object.object_items();
74  D3DXVECTOR4 vector = D3DXVECTOR4(
75  (items.find("r")->second).number_value(),
76  (items.find("g")->second).number_value(),
77  (items.find("b")->second).number_value(),
78  (items.find("a")->second).number_value()
79  );
80  ReadColor(name, vector);
81  }
82  }

◆ ReadFloat()

void IncrementalEngine::Config::ReadFloat ( std::string  name,
float  object 
)
private

Definition at line 96 of file Config.cpp.

97  {
98  if (name == "ScreenDepth")
99  ScreenDepth = object;
100 
101  if (name == "ScreenNear")
102  ScreenNear = object;
103  }

◆ ReadInt()

void IncrementalEngine::Config::ReadInt ( std::string  name,
int  object 
)
private

Definition at line 92 of file Config.cpp.

93  {
94  }

◆ ReadString()

void IncrementalEngine::Config::ReadString ( std::string  name,
std::string  object 
)
private

Definition at line 84 of file Config.cpp.

85  {
86  if (name == "ApplicationName")
87  {
88  ApplicationName = object;
89  }
90  }

◆ ReadVector2()

void IncrementalEngine::Config::ReadVector2 ( std::string  name,
D3DXVECTOR2  object 
)
private

Definition at line 117 of file Config.cpp.

118  {
119  if (name == "WindowSize")
120  WindowSize = object;
121  }

Member Data Documentation

◆ ApplicationName

std::string IncrementalEngine::Config::ApplicationName

Definition at line 18 of file Config.h.

◆ BackgroundColor

D3DXVECTOR4 IncrementalEngine::Config::BackgroundColor

Definition at line 29 of file Config.h.

◆ Fullscreen

bool IncrementalEngine::Config::Fullscreen

Definition at line 20 of file Config.h.

◆ ScreenDepth

float IncrementalEngine::Config::ScreenDepth

Definition at line 23 of file Config.h.

◆ ScreenNear

float IncrementalEngine::Config::ScreenNear

Definition at line 24 of file Config.h.

◆ ShowCursor

bool IncrementalEngine::Config::ShowCursor

Definition at line 27 of file Config.h.

◆ VsyncEnabled

bool IncrementalEngine::Config::VsyncEnabled

Definition at line 25 of file Config.h.

◆ WindowSize

D3DXVECTOR2 IncrementalEngine::Config::WindowSize

Definition at line 21 of file Config.h.

IncrementalEngine::Config::ApplicationName
std::string ApplicationName
Definition: Config.h:18
IncrementalEngine::Config::WindowSize
D3DXVECTOR2 WindowSize
Definition: Config.h:21
IncrementalEngine::Config::ShowCursor
bool ShowCursor
Definition: Config.h:27
IncrementalEngine::Config::ReadColor
void ReadColor(std::string name, D3DXVECTOR4 object)
Definition: Config.cpp:123
IncrementalEngine::Config::ReadInt
void ReadInt(std::string name, int object)
Definition: Config.cpp:92
IncrementalEngine::Config::VsyncEnabled
bool VsyncEnabled
Definition: Config.h:25
IncrementalEngine::Config::Fullscreen
bool Fullscreen
Definition: Config.h:20
IncrementalEngine::Config::ReadFloat
void ReadFloat(std::string name, float object)
Definition: Config.cpp:96
IncrementalEngine::Config::ScreenNear
float ScreenNear
Definition: Config.h:24
IncrementalEngine::Config::ScreenDepth
float ScreenDepth
Definition: Config.h:23
IncrementalEngine::Config::ReadString
void ReadString(std::string name, std::string object)
Definition: Config.cpp:84
IncrementalEngine::Config::ReadBool
void ReadBool(std::string name, bool object)
Definition: Config.cpp:105
IncrementalEngine::Config::ReadVector2
void ReadVector2(std::string name, D3DXVECTOR2 object)
Definition: Config.cpp:117
IncrementalEngine::Config::ReadConfigElement
void ReadConfigElement(std::string name, std::string type, Json object)
Definition: Config.cpp:39
IncrementalEngine::Config::BackgroundColor
D3DXVECTOR4 BackgroundColor
Definition: Config.h:29