xoreos  0.0.5
util.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/ustring.h"
26 
27 #include "src/aurora/gff3file.h"
28 
29 #include "src/engines/nwn2/util.h"
30 
31 namespace Engines {
32 
33 namespace NWN2 {
34 
35 bool readTint(const Aurora::GFF3Struct &gff, float t[3][4]) {
36  if (!gff.hasField("Tintable"))
37  return false;
38 
39  const Aurora::GFF3Struct &tintable = gff.getStruct("Tintable");
40  if (!tintable.hasField("Tint"))
41  return false;
42 
43  const Aurora::GFF3Struct &tint = tintable.getStruct("Tint");
44 
45  for (int i = 0; i < 3; i++) {
46  Common::UString index = Common::UString::format("%d", i + 1);
47  if (!tint.hasField(index))
48  continue;
49 
50  const Aurora::GFF3Struct &tintN = tint.getStruct(index);
51 
52  t[i][0] = tintN.getUint("r", t[i][0] * 255) / 255.0f;
53  t[i][1] = tintN.getUint("g", t[i][1] * 255) / 255.0f;
54  t[i][2] = tintN.getUint("b", t[i][2] * 255) / 255.0f;
55  t[i][3] = tintN.getUint("a", t[i][3] * 255) / 255.0f;
56  }
57 
58  return true;
59 }
60 
61 bool readTint(const Aurora::GFF3Struct &gff, const Common::UString &strct, float t[3][4]) {
62  if (!gff.hasField(strct))
63  return false;
64 
65  return readTint(gff.getStruct(strct), t);
66 }
67 
69  bool inBrace = false;
70 
71  Common::UString displayName;
72  for (Common::UString::iterator it = name.begin(); it != name.end(); ++it) {
73  if (*it == '{') {
74  inBrace = true;
75  continue;
76  }
77 
78  if (*it == '}') {
79  inBrace = false;
80  continue;
81  }
82 
83  if (!inBrace)
84  displayName += *it;
85  }
86 
87  return displayName;
88 }
89 
90 } // End of namespace NWN2
91 
92 } // End of namespace Engines
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
Neverwinter Nights 2 utility functions.
A class holding an UTF-8 string.
Definition: ustring.h:48
bool hasField(const Common::UString &field) const
Does this specific field exist?
Definition: gff3file.cpp:400
iterator begin() const
Definition: ustring.cpp:253
uint64 getUint(const Common::UString &field, uint64 def=0) const
Definition: gff3file.cpp:436
utf8::iterator< std::string::const_iterator > iterator
Definition: ustring.h:50
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
Unicode string handling.
A struct within a GFF3.
Definition: gff3file.h:164
bool readTint(const Aurora::GFF3Struct &gff, float t[3][4])
Definition: util.cpp:35
const GFF3Struct & getStruct(const Common::UString &field) const
Definition: gff3file.cpp:728
Common::UString createDisplayName(const Common::UString &name)
Strip text enclosed in {} from a string.
Definition: util.cpp:68
iterator end() const
Definition: ustring.cpp:257