xoreos  0.0.5
tileset.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/scopedptr.h"
26 #include "src/common/error.h"
27 #include "src/common/configfile.h"
28 #include "src/common/readstream.h"
29 
30 #include "src/aurora/types.h"
31 #include "src/aurora/resman.h"
32 #include "src/aurora/talkman.h"
33 
35 
36 namespace Engines {
37 
38 namespace NWN {
39 
42  if (!setFile)
43  throw Common::Exception("No such tileset \"%s\"", resRef.c_str());
44 
46 
47  set.load(*setFile);
48 
49  load(set);
50 }
51 
53 }
54 
56  return _name;
57 }
58 
60  return _environmentMap;
61 }
62 
63 float Tileset::getTilesHeight() const {
64  return _tilesHeight;
65 }
66 
67 const Tileset::Tile &Tileset::getTile(size_t n) const {
68  if (n >= _tiles.size())
69  throw Common::Exception("Tileset has no tile %u", (uint)n);
70 
71  return _tiles[n];
72 }
73 
75  const Common::ConfigDomain *general = set.getDomain("GENERAL");
76  if (!general)
77  throw Common::Exception("Tileset has no \"GENERAL\" domain");
78 
79  loadGeneral(*general);
80 
81  const Common::ConfigDomain *tiles = set.getDomain("TILES");
82  if (!tiles)
83  throw Common::Exception("Tileset has no \"TILES\" domain");
84 
85  _tiles.resize(tiles->getUint("Count"));
86 
87  for (size_t i = 0; i < _tiles.size(); i++)
88  loadTile(set, i, _tiles[i]);
89 }
90 
92  _name = TalkMan.getString(general.getUint("DisplayName", Aurora::kStrRefInvalid));
93 
94  _tilesHeight = general.getUint("Transition");
95  _environmentMap = general.getString("EnvMap");
96 }
97 
98 void Tileset::loadTile(const Common::ConfigFile &set, uint i, Tile &tile) {
99  Common::UString domainName = Common::UString::format("TILE%u", i);
100  const Common::ConfigDomain *domain = set.getDomain(domainName);
101  if (!domain)
102  throw Common::Exception("Tileset has no \"%s\" domain", domainName.c_str());
103 
104  tile.model = domain->getString("Model");
105 }
106 
107 } // End of namespace NWN
108 
109 } // End of namespace Engines
void load(const Common::ConfigFile &set)
Definition: tileset.cpp:74
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
This class allows reading/writing INI style config files.
Definition: configfile.h:113
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
A class holding an UTF-8 string.
Definition: ustring.h:48
void loadGeneral(const Common::ConfigDomain &general)
Definition: tileset.cpp:91
Common::UString model
Definition: tileset.h:45
std::vector< Tile > _tiles
Definition: tileset.h:66
void load(SeekableReadStream &stream)
Definition: configfile.cpp:283
Common::UString _environmentMap
Definition: tileset.h:62
UString getString(const UString &key, const UString &def="") const
Definition: configfile.cpp:63
Exception that provides a stack of explanations.
Definition: error.h:36
A simple scoped smart pointer template.
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
A class storing a basic configuration file.
static const uint32 kStrRefInvalid
Definition: types.h:444
StackException Exception
Definition: error.h:59
const Common::UString & getEnvironmentMap() const
Definition: tileset.cpp:59
Basic reading stream interfaces.
void loadTile(const Common::ConfigFile &set, uint i, Tile &tile)
Definition: tileset.cpp:98
Tileset.
Definition: types.h:82
A tileset in Neverwinter Nights.
Tileset(const Common::UString &resRef)
Definition: tileset.cpp:40
const Common::UString & getName() const
Definition: tileset.cpp:55
Basic type definitions to handle files used in BioWare&#39;s Aurora engine.
Accessor for a domain (section) in a config file.
Definition: configfile.h:46
The global talk manager for Aurora strings.
Common::UString _name
Definition: tileset.h:60
float getTilesHeight() const
Definition: tileset.cpp:63
const Tile & getTile(size_t n) const
Definition: tileset.cpp:67
uint getUint(const UString &key, uint def=0) const
Definition: configfile.cpp:101
The global resource manager for Aurora resources.
unsigned int uint
Definition: types.h:211