-
Notifications
You must be signed in to change notification settings - Fork 54
/
TreeGrowthConfiguration.cpp
70 lines (62 loc) · 2.59 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
64
65
66
67
68
69
70
#include "TreeGrowthConfiguration.h"
using namespace std;
using namespace DFHack;
using namespace df::enums;
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 = INVALID_INDEX;
const char* filename = elemRoot->Attribute("file");
if (filename != NULL && filename[0] != 0) {
basefile = loadConfigImgFile((char*)filename, elemRoot);
if (basefile == -1) {
return false;
}
}
string elementType = elemRoot->Value();
if (elementType.compare("growths") == 0) {
//parse colors
TiXmlElement* elemGrowth = elemRoot->FirstChildElement("growth");
while (elemGrowth) {
parseGrowthElement(elemGrowth, contentLoader->growthTopConfigs, contentLoader->growthBottomConfigs, basefile);
elemGrowth = elemGrowth->NextSiblingElement("growth");
}
}
return true;
}