Show bonus/malus timer text if available
[ryzomcore.git] / nel / src / ligo / primitive_utils.cpp
blobf97e46ea0c4bc463b259007cb531cbbcf81a88c1
1 // NeL - MMORPG Framework <https://wiki.ryzom.dev/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdligo.h"
18 #include "nel/ligo/primitive_utils.h"
21 namespace NLLIGO
24 std::string buildPrimPath(const IPrimitive *prim)
26 std::string path;
28 while (prim != NULL)
30 std::string name;
31 prim->getPropertyByName("name", name);
32 if (path.empty())
33 path = name;
34 else
35 path = name + "." + path;
37 prim = prim->getParent();
39 return path;
42 void selectPrimByPath(IPrimitive *rootNode, const std::string &path, TPrimitiveSet &result)
44 std::vector<std::string> parts;
45 NLMISC::explode(path, std::string("."), parts, false);
46 // IPrimitive * tmpChild;
48 result.clear();
50 if (parts.empty())
51 return;
53 // handle a special case
54 if (parts.size() > 1 && parts[1] == "primitive")
56 parts[0] += ".primitive";
57 parts.erase(parts.begin()+1);
60 TPrimitiveSet candidats, nextStep;
61 candidats.push_back(rootNode);
63 // check root validity
64 std::string name;
65 rootNode->getPropertyByName("name", name);
66 if (name != parts.front())
67 return;
69 for (uint i=1; i<parts.size(); ++i)
71 for (uint j=0; j<candidats.size(); ++j)
73 for (uint k=0; k<candidats[j]->getNumChildren(); ++k)
75 std::string name;
76 IPrimitive *child;
77 candidats[j]->getChild(child, k);
79 child->getPropertyByName("name", name);
81 if (name == parts[i])
83 nextStep.push_back(child);
88 candidats.swap(nextStep);
89 nextStep.clear();
92 result.swap(candidats);
94 // for (uint i=0; i<parts.size(); ++i)
95 // {
96 // for (uint j=0; j<candidats.size(); ++j)
97 // {
98 // std::string tmpName;
99 // std::vector<std::string> name;
100 // candidats[j]->getPropertyByName("name", tmpName);
101 // NLMISC::explode(tmpName,".",name);
103 // bool test=false;
104 // for(uint k=0;k<name.size();k++)
105 // {
106 // if (name.at(k)==parts[i+k])
107 // test=true;
108 // else
109 // {
110 // test=false;
111 // break;
112 // }
113 // }
114 // if (test)
115 // {
116 // if (i == parts.size()-1)
117 // {
118 // }
119 // else
120 // {
121 // for(uint k=0;k<candidats[j]->getNumChildren();k++)
122 // {
123 // candidats[j]->getChild(tmpChild,k);
124 // nextStep.push_back(tmpChild);
125 // }
126 // }
127 //// result.clear();
128 //// result.push_back(candidats[j]);
129 // i+=name.size()-1;
130 // break;
131 // }
133 // }
135 // candidats.swap(nextStep);
136 // nextStep.clear();
138 // if (candidats.empty())
139 // return;
140 // }
142 // store the result
143 // result.swap(candidats);
144 //result.push_back(candidats.at(0)->getParent());
147 } // namespace NLLIGO