-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathTreeGrowthConfiguration.cpp
63 lines (56 loc) · 2.5 KB
/
TreeGrowthConfiguration.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
#include "TreeGrowthConfiguration.h"
#include "StonesenseState.h"
void parseGrowthElement(TiXmlElement* elemGrowthSprite, MaterialMatcher<c_sprite> & growthTopConfigs, MaterialMatcher<c_sprite> & growthBottomConfigs, int basefile)
{
const char* spriteSheetIndexStr = elemGrowthSprite->Attribute("sheetIndex");
const char* spriteSpriteStr = elemGrowthSprite->Attribute("sprite");
const char* spriteIndexStr = elemGrowthSprite->Attribute("index");
if ((spriteSheetIndexStr == NULL || spriteSheetIndexStr[0] == 0) && (spriteSpriteStr == NULL || spriteSpriteStr[0] == 0) && (spriteIndexStr == NULL || spriteIndexStr[0] == 0)) {
contentError("Invalid or missing sprite attribute", elemGrowthSprite);
return; //nothing to work with
}
// make a base sprite
c_sprite sprite;
sprite.set_by_xml(elemGrowthSprite, basefile);
sprite.set_size(SPRITEWIDTH, (TILETOPHEIGHT + FLOORHEIGHT));
sprite.set_offset(0, (WALLHEIGHT));
bool bottomLayer = false;
const char* layerStr = elemGrowthSprite->Attribute("layer");
if (layerStr && layerStr[0])
bottomLayer = (strcmp(layerStr, "bottom") == 0);
//parse material elements
TiXmlElement* elemPart = elemGrowthSprite->FirstChildElement("part");
if (elemPart == NULL) {
//if none, there's nothing to be done with this color.
contentError("Invalid or missing part attribute", elemGrowthSprite);
return;
}
for (; elemPart; elemPart = elemPart->NextSiblingElement("part"))
{
const char* elemToken = elemPart->Attribute("token");
if (elemToken && elemToken[0])
{
if (bottomLayer)
growthBottomConfigs.set_growth(sprite, elemToken);
else
growthTopConfigs.set_growth(sprite, elemToken);
}
}
}
bool addSingleGrowthConfig(TiXmlElement* elemRoot)
{
int basefile = loadImgFromXML(elemRoot);
if (elemRoot->Attribute("file") != NULL && basefile == INVALID_INDEX)
return false;
std::string elementType = elemRoot->Value();
if (elementType.compare("growths") == 0) {
//parse colors
TiXmlElement* elemGrowth = elemRoot->FirstChildElement("growth");
while (elemGrowth) {
auto& contentLoader = stonesenseState.contentLoader;
parseGrowthElement(elemGrowth, stonesenseState.contentLoader->growthTopConfigs, contentLoader->growthBottomConfigs, basefile);
elemGrowth = elemGrowth->NextSiblingElement("growth");
}
}
return true;
}