mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 14:03:26 +02:00
lua console and some changes
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#define COLOR_H
|
||||
|
||||
#include "types.h"
|
||||
#include <sstream>
|
||||
#include "tools.h"
|
||||
|
||||
typedef uint32 RGBA;
|
||||
|
||||
@@ -69,10 +69,19 @@ inline std::istream& operator>>(std::istream& in, Color& color)
|
||||
using namespace std;
|
||||
|
||||
if(in.get() == '#') {
|
||||
uint32 tmp;
|
||||
in >> hex >> tmp;
|
||||
color.setABGR(tmp);
|
||||
in >> dec;
|
||||
std::string tmp;
|
||||
in >> tmp;
|
||||
|
||||
if(tmp.length() == 6 || tmp.length() == 8) {
|
||||
color.setRed((uint8)fw::hex2dec(tmp.substr(0, 2)));
|
||||
color.setGreen((uint8)fw::hex2dec(tmp.substr(2, 2)));
|
||||
color.setBlue((uint8)fw::hex2dec(tmp.substr(4, 2)));
|
||||
if(tmp.length() == 8)
|
||||
color.setAlpha((uint8)fw::hex2dec(tmp.substr(6, 2)));
|
||||
else
|
||||
color.setAlpha(255);
|
||||
} else
|
||||
in.seekg(-tmp.length()-1, ios_base::cur);
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
@@ -1,19 +0,0 @@
|
||||
#include "logger.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
void Logger::log(LogLevel level, const std::string& message, std::string prettyFunction)
|
||||
{
|
||||
if(!prettyFunction.empty()) {
|
||||
prettyFunction = prettyFunction.substr(0, prettyFunction.find_first_of('('));
|
||||
if(prettyFunction.find_last_of(' ') != std::string::npos)
|
||||
prettyFunction = prettyFunction.substr(prettyFunction.find_last_of(' ') + 1);
|
||||
if(!prettyFunction.empty())
|
||||
std::cout << "[" << prettyFunction << "] ";
|
||||
}
|
||||
|
||||
std::cout << message << std::endl;
|
||||
|
||||
if(level == LogFatal)
|
||||
exit(-1);
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
#ifndef LOGGER_H
|
||||
#define LOGGER_H
|
||||
|
||||
#include "tools.h"
|
||||
|
||||
//TODO: a real logger
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
enum LogLevel {
|
||||
LogDebug = 0,
|
||||
LogInfo,
|
||||
LogWarning,
|
||||
LogError,
|
||||
LogFatal
|
||||
};
|
||||
static void log(LogLevel level, const std::string& message, std::string prettyFunction = "");
|
||||
};
|
||||
|
||||
// specialized logging
|
||||
#define logDebug(...) Logger::log(Logger::LogDebug, fw::mkstr(__VA_ARGS__))
|
||||
#define logInfo(...) Logger::log(Logger::LogInfo, fw::mkstr(__VA_ARGS__))
|
||||
#define logWarning(...) Logger::log(Logger::LogWarning, fw::mkstr(__VA_ARGS__))
|
||||
#define logError(...) Logger::log(Logger::LogError, fw::mkstr(__VA_ARGS__))
|
||||
#define logFatal(...) Logger::log(Logger::LogFatal, fw::mkstr(__VA_ARGS__))
|
||||
|
||||
#define logTrace() Logger::log(Logger::LogDebug, "", __PRETTY_FUNCTION__)
|
||||
#define logTraceDebug(...) Logger::log(Logger::LogDebug, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
|
||||
#define logTraceInfo(...) Logger::log(Logger::LogInfo, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
|
||||
#define logTraceWarning(...) log(Logger::LogWarning, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
|
||||
#define logTraceError(...) Logger::log(Logger::LogError, fw::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
|
||||
|
||||
#endif
|
@@ -197,7 +197,7 @@ R unsafe_cast(const T& t, R def = R()) {
|
||||
try {
|
||||
return safe_cast<R,T>(t);
|
||||
} catch(bad_cast& e) {
|
||||
println(e.what());
|
||||
println("CAST ERROR: ", e.what());
|
||||
return def;
|
||||
}
|
||||
}
|
||||
@@ -212,6 +212,21 @@ T fromstring(const std::string& str, T def = T()) {
|
||||
return unsafe_cast<T, std::string>(str, def);
|
||||
}
|
||||
|
||||
inline std::string dec2hex(unsigned int num) {
|
||||
std::string str;
|
||||
std::ostringstream o;
|
||||
o << std::hex << num;
|
||||
str = o.str();
|
||||
return str;
|
||||
}
|
||||
|
||||
inline unsigned int hex2dec(const std::string& str) {
|
||||
unsigned int num;
|
||||
std::istringstream i(str);
|
||||
i >> std::hex >> num;
|
||||
return num;
|
||||
}
|
||||
|
||||
// an empty string to use anywhere needed
|
||||
const static std::string empty_string;
|
||||
|
||||
|
Reference in New Issue
Block a user