31 const std::string &value)
37 const std::string &deflt)
const
40 return iter !=
mOptions.end() ? iter->second : deflt;
46 return iter !=
mOptions.end() ? atoi(iter->second.c_str()) : deflt;
53 return iter !=
mOptions.end() ? atol(iter->second.c_str()) : deflt;
60 return iter !=
mOptions.end() ? atof(iter->second.c_str()) : deflt;
105 && itdef->second->getType() == type)
107 return itdef->second;
110 Log::info(
"%s: No value in registry for key %s",
120 int defaultValue = 0;
126 defaultValue = ((
IntData*)vd)->getData();
130 defaultValue = atoi(iter->second.c_str());
138 std::string defaultValue;
147 defaultValue = iter->second;
156 float defaultValue = 0.0f;
161 defaultValue = ((
FloatData*)vd)->getData();
165 defaultValue = atof(iter->second.c_str());
173 bool defaultValue =
false;
178 defaultValue = ((
BoolData*)vd)->getData();
192 for (
auto node : parent_node.
children())
194 if (node.name() ==
"option")
196 std::string name = node.getProperty(
"name", std::string());
199 mOptions[name] = node.getProperty(
"value", std::string());
217 Log::info(
"Couldn't open configuration file: %s", filename.c_str());
221 if (rootNode.
name() !=
"configuration")
223 Log::warn(
"No configuration file (%s)", filename.c_str());
282 if (!color.
color.empty())
301static const char *serverTypeToString(
ServerType type)
417 auto serializeOption = [&](
const char *name,
auto member) {
418 serialize(writer,
Option { name,
config.*member, defaults.*member });
426 serialize(writer,
Option { name.c_str(), value, std::string() });
443 serialize(writer, outfit);
450 serialize(writer, color);
460 serialize(writer, state);
468 serialize(writer, server);
475 writer.
addAttribute(
"relation",
static_cast<int>(relation));
528 if (node.
name() ==
"connection") {
531 }
else if (node.
name() ==
"description") {
533 }
else if (node.
name() ==
"persistentIp") {
542 std::map<std::string, std::string> options;
545 if (node.
name() ==
"option") {
550 }
else if (node.
name() ==
"list") {
553 if (node.
name() ==
"player") {
554 std::string playerName;
558 if (node.
name() ==
"option") {
559 std::string optionName;
561 if (node.
attribute(
"name", optionName)) {
562 if (optionName ==
"name")
564 else if (optionName ==
"relation")
570 if (!playerName.empty())
574 }
else if (node.
name() ==
"key") {
579 }
else if (node.
name() ==
"itemshortcut") {
581 }
else if (node.
name() ==
"emoteshortcut") {
583 }
else if (node.
name() ==
"outfit") {
585 }
else if (node.
name() ==
"color") {
589 }
else if (node.
name() ==
"window") {
593 }
else if (node.
name() ==
"player") {
598 }
else if (node.
name() ==
"server") {
603 auto deserializeOption = [&](
const char *name,
auto member) {
604 auto it = options.find(name);
605 if (it == options.end())
std::string getValue(const std::string &key, const std::string &deflt) const
Gets a value as string.
std::map< std::string, std::string > mOptions
void clear()
Re-sets all data in the configuration.
void initFromXML(XML::Node node)
virtual ~ConfigurationObject()
void setValue(const std::string &key, const std::string &value)
Sets an option using a string value.
bool getBoolValue(const std::string &key) const
std::string getStringValue(const std::string &key) const
VariableData * getDefault(const std::string &key, VariableData::DataType type) const
float getFloatValue(const std::string &key) const
DefaultsData * mDefaultsData
Defaults of value for a given key.
std::string mConfigPath
Location of config file.
void setDefaultValues(DefaultsData *defaultsData)
Set the default values for each keys.
~Configuration() override
void cleanDefaults()
Clean up the default values member.
int getIntValue(const std::string &key) const
returns a value corresponding to the given key.
void init(const std::string &filename, bool useResManager=false)
Reads config file and parse all options into memory.
static ServerType parseType(const std::string &type)
A helper class for parsing an XML document, which also cleans it up again (RAII).
Node rootNode() const
Returns the root node of the document (or NULL if there was a load error).
std::string_view name() const
Children children() const
std::string_view textContent() const
bool attribute(const char *name, T &value) const
Helper class for writing out XML data.
void writeText(const std::string &text)
void startElement(const char *name)
void addAttribute(const char *name, const std::string &value)
Config config
Global settings (config.xml)
void deserialize(XML::Node node, ItemShortcutEntry &itemShortcut)
void serdeOptions(T option)
std::map< std::string, VariableData * > DefaultsData
EmoteShortcut * emoteShortcut
ItemShortcut * itemShortcut
void warn(const char *log_text,...) LOG_PRINTF_ATTR
void info(const char *log_text,...) LOG_PRINTF_ATTR
bool getBoolFromString(std::string text, bool def)
Returns a bool value depending on the given string value.
std::vector< Outfit > outfits
bool persistentPlayerList
std::map< std::string, PlayerRelation > players
std::map< std::string, WindowState > windows
std::vector< ItemShortcutEntry > itemShortcuts
std::map< std::string, std::string > unknownOptions
std::map< std::string, UserColor > colors
std::string playerIgnoreStrategy
std::string lastCharacter
std::string speechBubblecolor
std::map< std::string, std::string > keys
std::vector< EmoteShortcutEntry > emoteShortcuts
bool useScreenshotDirectorySuffix
std::string onlineServerList
bool showMonstersTakedDamage
unsigned defaultPlayerPermissions
std::string screenshotDirectory
std::string screenshotDirectorySuffix
Option(const char *name, const T &value, const T &defaultValue)
std::optional< int > delay
std::optional< int > height
std::optional< bool > visible
std::optional< bool > sticky
std::optional< int > width
void fromString(const char *str, FillMode &value)