forked from DFHack/stonesense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorConfiguration.cpp
113 lines (102 loc) · 3.98 KB
/
ColorConfiguration.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "ColorConfiguration.h"
#include "ContentLoader.h"
#include <set>
ColorMaterialConfiguration::ColorMaterialConfiguration()
{
color = al_map_rgb(255,255,255);
colorSet = 0;
}
ColorConfiguration::ColorConfiguration()
{
color = al_map_rgb(255,255,255);
colorSet = 0;
}
ColorConfiguration::~ColorConfiguration()
{
colorMaterials.clear();
}
void parseColorElement( TiXmlElement* elemColor, vector<ColorConfiguration> & configTable)
{
const char* colorRedStr = elemColor->Attribute("red");
if(colorRedStr == NULL || colorRedStr[0] == 0) {
contentError("Invalid or missing color attribute",elemColor);
return; //nothing to work with
}
const char* colorGreenStr = elemColor->Attribute("green");
if(colorGreenStr == NULL || colorGreenStr[0] == 0) {
contentError("Invalid or missing color attribute",elemColor);
return; //nothing to work with
}
const char* colorBlueStr = elemColor->Attribute("blue");
if(colorBlueStr == NULL || colorBlueStr[0] == 0) {
contentError("Invalid or missing color attribute",elemColor);
return; //nothing to work with
}
int red = atoi(colorRedStr);
int green = atoi(colorGreenStr);
int blue = atoi(colorBlueStr);
ALLEGRO_COLOR color = al_map_rgb(red, green, blue);
//parse material elements
TiXmlElement* elemMaterial = elemColor->FirstChildElement("material");
if(elemMaterial == NULL) {
//if none, there's nothing to be done with this color.
contentError("Invalid or missing material attribute",elemColor);
return;
}
for( ; elemMaterial; elemMaterial = elemMaterial->NextSiblingElement("material")) {
// get material type
int elemIndex = lookupMaterialType(elemMaterial->Attribute("value"));
if (elemIndex == INVALID_INDEX) {
contentError("Invalid or missing value attribute",elemMaterial);
continue;
}
// parse subtype elements
TiXmlElement* elemSubtype = elemMaterial->FirstChildElement("subtype");
if (elemSubtype == NULL) {
// add the configurations
if (configTable.size() <= (uint32_t)elemIndex) {
//increase size if needed
configTable.resize(elemIndex+1);
}
if(configTable.at(elemIndex).colorSet == false) {
configTable.at(elemIndex).color = color;
configTable.at(elemIndex).colorSet = true;
}
return;
}
for ( ; elemSubtype; elemSubtype = elemSubtype ->NextSiblingElement("subtype")) {
// get subtype
int subtypeId = lookupMaterialIndex( elemIndex,elemSubtype->Attribute("value"));
if (subtypeId == INVALID_INDEX) {
contentError("Invalid or missing value attribute",elemSubtype);
continue;
}
// add the configurations
if (configTable.size() <= (uint32_t)elemIndex) {
//increase size if needed
configTable.resize(elemIndex+1);
}
if (configTable.at(elemIndex).colorMaterials.size() <= (uint32_t)subtypeId) {
//increase size if needed
configTable.at(elemIndex).colorMaterials.resize(subtypeId+1);
}
if (configTable.at(elemIndex).colorMaterials.at(subtypeId).colorSet == false) {
configTable.at(elemIndex).colorMaterials.at(subtypeId).color = color;
configTable.at(elemIndex).colorMaterials.at(subtypeId).colorSet = true;
}
}
}
}
bool addSingleColorConfig( TiXmlElement* elemRoot)
{
string elementType = elemRoot->Value();
if(elementType.compare( "colors" ) == 0) {
//parse colors
TiXmlElement* elemColor = elemRoot->FirstChildElement("color");
while( elemColor ) {
parseColorElement( elemColor, contentLoader->colorConfigs);
elemColor = elemColor->NextSiblingElement("color");
}
}
return true;
}