ManaPlus
Functions
PaletteDB Namespace Reference

Functions

void load ()
 
void unload ()
 
void loadPalette ()
 
const DyeColorgetColor (const std::string &name)
 

Function Documentation

◆ getColor()

const DyeColor * PaletteDB::getColor ( const std::string &  name)

Definition at line 109 of file palettedb.cpp.

110 {
111  const std::map<std::string, DyeColor>::const_iterator it =
112  mColors.find(name);
113  if (it != mColors.end())
114  return &(*it).second;
115  return nullptr;
116 }
std::map< std::string, DyeColor > mColors
Definition: palettedb.cpp:37

References anonymous_namespace{palettedb.cpp}::mColors.

Referenced by DyePalette::DyePalette().

◆ load()

void PaletteDB::load ( )

Definition at line 40 of file palettedb.cpp.

41 {
42  if (mLoaded)
43  unload();
44 
45  logger->log1("Initializing palette database...");
46  loadPalette();
47 }
void log1(const char *const log_text)
Definition: logger.cpp:238
Logger * logger
Definition: logger.cpp:89
void unload()
Definition: net.cpp:180
void loadPalette()
Definition: palettedb.cpp:49

References loadPalette(), Logger::log1(), logger, anonymous_namespace{palettedb.cpp}::mLoaded, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadPalette()

void PaletteDB::loadPalette ( )

Definition at line 49 of file palettedb.cpp.

50 {
51  mLoaded = true;
52  StringVect lines;
54  paths.getStringValue("defaultPaletteFile"),
55  lines);
56  StringVectCIter it = lines.begin();
57  if (it == lines.end())
58  {
59  logger->log("missing GIMP palette file");
60  return;
61  }
62  if (*it != "GIMP Palette")
63  {
64  reportAlways("wrong GIMP palette file")
65  return;
66  }
67  ++ it;
68  // skip header
69  while (it != lines.end())
70  {
71  const std::string line = *it;
72  if (!line.empty() && line[0] == '#')
73  break;
74  ++ it;
75  }
76 
77  char name[101];
78 
79  // process colors and ignore commets
80  while (it != lines.end())
81  {
82  const std::string line = *it;
83  ++ it;
84 
85  if (line.empty() || line[0] == '#')
86  continue;
87 
88  unsigned int r;
89  unsigned int g;
90  unsigned int b;
91 
92  if (sscanf(line.c_str(), "%10u %10u %10u\t%100s",
93  &r, &g, &b, name) == 4)
94  {
95  name[100] = 0;
96  mColors[name] = DyeColor(CAST_U8(r),
97  CAST_U8(g),
98  CAST_U8(b));
99  }
100  }
101 }
#define CAST_U8
Definition: cast.h:27
#define reportAlways(...)
Definition: checkutils.h:253
std::string getStringValue(const std::string &key) const
void log(const char *const log_text,...)
Definition: logger.cpp:269
Configuration paths
bool loadTextFile(const std::string &fileName, StringVect &lines)
Definition: tools.cpp:137
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:31
std::vector< std::string > StringVect
Definition: stringvector.h:29

References CAST_U8, Configuration::getStringValue(), VirtFs::loadTextFile(), Logger::log(), logger, anonymous_namespace{palettedb.cpp}::mColors, anonymous_namespace{palettedb.cpp}::mLoaded, paths, and reportAlways.

Referenced by load().

◆ unload()

void PaletteDB::unload ( )

Definition at line 103 of file palettedb.cpp.

104 {
105  logger->log1("Unloading palette database...");
106  mColors.clear();
107 }

References Logger::log1(), logger, and anonymous_namespace{palettedb.cpp}::mColors.

Referenced by DbManager::unloadDb().