Update: Translations from eints
[openttd-github.git] / src / script / api / script_log.cpp
blobbb6fb0060ff666d9528d5ef30c26ade86ebcacdc
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file script_log.cpp Implementation of ScriptLog. */
10 #include "../../stdafx.h"
11 #include "script_log_types.hpp"
12 #include "script_log.hpp"
13 #include "../../core/alloc_func.hpp"
14 #include "../../debug.h"
15 #include "../../window_func.h"
16 #include "../../string_func.h"
18 #include "../../safeguards.h"
20 /* static */ void ScriptLog::Info(const std::string &message)
22 ScriptLog::Log(ScriptLogTypes::LOG_INFO, message);
25 /* static */ void ScriptLog::Warning(const std::string &message)
27 ScriptLog::Log(ScriptLogTypes::LOG_WARNING, message);
30 /* static */ void ScriptLog::Error(const std::string &message)
32 ScriptLog::Log(ScriptLogTypes::LOG_ERROR, message);
35 /* static */ void ScriptLog::Log(ScriptLogTypes::ScriptLogType level, const std::string &message)
37 ScriptLogTypes::LogData &logdata = ScriptObject::GetLogData();
39 /* Limit the log to 400 lines. */
40 if (logdata.size() >= 400U) logdata.pop_front();
42 auto &line = logdata.emplace_back();
43 line.type = level;
45 /* Cut string after first \n */
46 line.text = message.substr(0, message.find_first_of('\n'));
48 char logc;
50 switch (level) {
51 case ScriptLogTypes::LOG_SQ_ERROR: logc = 'S'; break;
52 case ScriptLogTypes::LOG_ERROR: logc = 'E'; break;
53 case ScriptLogTypes::LOG_SQ_INFO: logc = 'P'; break;
54 case ScriptLogTypes::LOG_WARNING: logc = 'W'; break;
55 case ScriptLogTypes::LOG_INFO: logc = 'I'; break;
56 default: logc = '?'; break;
59 /* Also still print to debug window */
60 Debug(script, level, "[{}] [{}] {}", (uint)ScriptObject::GetRootCompany(), logc, line.text);
61 InvalidateWindowClassesData(WC_SCRIPT_DEBUG, ScriptObject::GetRootCompany());