1 | #include "yamltexbindings.h"
|
---|
2 |
|
---|
3 | namespace genesis
|
---|
4 | {
|
---|
5 | /* TODO: Migrate to Godot
|
---|
6 | *
|
---|
7 | static const std::string
|
---|
8 | gsKeyNamesPlural("names"),
|
---|
9 | gsKeyName("name"),
|
---|
10 | gsKeyTexture("texture");
|
---|
11 |
|
---|
12 | YAMLTexBindingsReader::YAMLTexBindingsReader(std::istream & input)
|
---|
13 | : _pParser(new YAML::Parser(input)) {}
|
---|
14 |
|
---|
15 | YAMLTexBindingsReader::~YAMLTexBindingsReader()
|
---|
16 | {
|
---|
17 | delete _pParser;
|
---|
18 | }
|
---|
19 |
|
---|
20 | bool YAMLTexBindingsReader::load( ITextureBinder * pMatBind )
|
---|
21 | {
|
---|
22 | while (*_pParser)
|
---|
23 | {
|
---|
24 | YAML::Node ndDoc;
|
---|
25 | ITextureBinder::Category enmbcCategory;
|
---|
26 |
|
---|
27 | _pParser->GetNextDocument(ndDoc);
|
---|
28 |
|
---|
29 | if (ndDoc.GetTag() == "!minclass")
|
---|
30 | enmbcCategory = ITextureBinder::MineralClasses;
|
---|
31 | else if (ndDoc.GetTag() == "!mineral")
|
---|
32 | enmbcCategory = ITextureBinder::Minerals;
|
---|
33 | else
|
---|
34 | throw YAML::RepresentationException(ndDoc.GetMark(), "Invalid tag type: " + ndDoc.GetTag());
|
---|
35 |
|
---|
36 | if (ndDoc.GetType() != YAML::CT_MAP)
|
---|
37 | throw YAML::RepresentationException(ndDoc.GetMark(), "Expected map");
|
---|
38 |
|
---|
39 | for (YAML::Iterator i = ndDoc.begin(); i != ndDoc.end(); ++i)
|
---|
40 | if (i.first() == "group")
|
---|
41 | pMatBind->setGroup(enmbcCategory, i.second());
|
---|
42 | else if (i.first() == "default")
|
---|
43 | pMatBind->setDefaultTexture(enmbcCategory, i.second());
|
---|
44 | else if (i.first() == "bindings")
|
---|
45 | for (YAML::Iterator j = i.second().begin(); j != i.second().end(); ++j)
|
---|
46 | readBinding(enmbcCategory, pMatBind, &*j);
|
---|
47 | else
|
---|
48 | throw YAML::RepresentationException(ndDoc.GetMark(), "Unrecognized key");
|
---|
49 | }
|
---|
50 |
|
---|
51 | return true;
|
---|
52 | }
|
---|
53 |
|
---|
54 | void YAMLTexBindingsReader::readBinding( const ITextureBinder::Category enmbcCategory, ITextureBinder * pMatBind, const YAML::Node * pNode)
|
---|
55 | {
|
---|
56 | size_t c = 0;
|
---|
57 | for (YAML::Iterator i = pNode->begin(); i != pNode->end(); ++i, ++c)
|
---|
58 | {
|
---|
59 | if (c > 2)
|
---|
60 | throw YAML::RepresentationException(pNode->GetMark(), "Too many declarations");
|
---|
61 |
|
---|
62 | if (i.first() == gsKeyNamesPlural)
|
---|
63 | {
|
---|
64 | std::string sMaterial = (*pNode)[gsKeyTexture];
|
---|
65 | for (YAML::Iterator j = i.second().begin(); j != i.second().end(); ++j)
|
---|
66 | pMatBind->bind(enmbcCategory, *j, sMaterial);
|
---|
67 | break;
|
---|
68 | } else if (i.first() == gsKeyName)
|
---|
69 | pMatBind->bind(enmbcCategory, i.second(), (*pNode)[gsKeyTexture]);
|
---|
70 | else if (i.first() == gsKeyTexture)
|
---|
71 | pMatBind->bind(enmbcCategory, (*pNode)[gsKeyName], i.second());
|
---|
72 | else
|
---|
73 | throw YAML::RepresentationException(pNode->GetMark(), "Unrecognized binding declaration");
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | */
|
---|
78 | }
|
---|