Skip to content

Commit

Permalink
Merge pull request #166 from gfgtdf/wml_message
Browse files Browse the repository at this point in the history
add "to_chat" parameter to wml_message
  • Loading branch information
gfgtdf committed May 20, 2014
2 parents 1e16b9a + 7c69fcb commit e422aa6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/game_events/action_wml.cpp
Expand Up @@ -593,8 +593,9 @@ void handle_wml_log_message(const config& cfg)
{
const std::string& logger = cfg["logger"];
const std::string& msg = cfg["message"];
bool in_chat = cfg["to_chat"].to_bool(true);

put_wml_message(logger,msg);
put_wml_message(logger,msg,in_chat);
}


Expand Down
24 changes: 15 additions & 9 deletions src/game_events/pump.cpp
Expand Up @@ -373,6 +373,16 @@ namespace { // Support functions
show_wml_messages(wml_messages_stream, caption, false);
}

void put_wml_message(lg::logger& logger, const std::string& prefix, const std::string& message, bool in_chat)
{
logger(log_wml) << message << "\n";
if (in_chat)
{
wml_messages_stream << prefix << message << "\n";
}
}


} // end anonymous namespace (support functions)


Expand Down Expand Up @@ -401,20 +411,16 @@ context::scoped::~scoped()
* Helper function which determines whether a wml_message text can
* really be pushed into the wml_messages_stream, and does it.
*/
void put_wml_message(const std::string& logger, const std::string& message)
void put_wml_message(const std::string& logger, const std::string& message, bool in_chat)
{
if (logger == "err" || logger == "error") {
ERR_WML << message << "\n";
wml_messages_stream << _("Error: ") << message << "\n";
put_wml_message(lg::err, _("Error: "), message, in_chat );
} else if (logger == "warn" || logger == "wrn" || logger == "warning") {
WRN_WML << message << "\n";
wml_messages_stream << _("Warning: ") << message << "\n";
put_wml_message(lg::warn, _("Warning: "), message, in_chat );
} else if ((logger == "debug" || logger == "dbg") && !lg::debug.dont_log(log_wml)) {
DBG_WML << message << "\n";
wml_messages_stream << _("Debug: ") << message << "\n";
put_wml_message(lg::debug, _("Debug: "), message, in_chat );
} else if (!lg::info.dont_log(log_wml)) {
LOG_WML << message << "\n";
wml_messages_stream << _("Info: ") << message << "\n";
put_wml_message(lg::info, _("Info: "), message, in_chat );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/game_events/pump.hpp
Expand Up @@ -97,7 +97,7 @@ namespace game_events

/// Helper function which determines whether a wml_message text can
/// really be pushed into the wml_messages_stream, and does it.
void put_wml_message(const std::string& logger, const std::string& message);
void put_wml_message(const std::string& logger, const std::string& message, bool in_chat);

/**
* Directly runs the lua command(s) @a lua_code
Expand Down

0 comments on commit e422aa6

Please sign in to comment.