2021-08-04 16:18:52 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <optional>
|
2021-08-21 00:23:14 +01:00
|
|
|
#include <spdlog/fmt/fmt.h>
|
2021-08-04 16:18:52 +01:00
|
|
|
|
|
|
|
enum class ERROR_MODE
|
|
|
|
{
|
|
|
|
SILENT,
|
|
|
|
WARN,
|
|
|
|
TERMINATE
|
|
|
|
};
|
2021-08-21 00:13:44 +01:00
|
|
|
|
|
|
|
void SetScriptErrorMode(ERROR_MODE mode);
|
|
|
|
ERROR_MODE GetScriptErrorMode();
|
2021-08-21 00:23:14 +01:00
|
|
|
|
2021-08-06 16:43:01 +01:00
|
|
|
void ScriptWarn(std::string const& msg);
|
2021-08-04 16:18:52 +01:00
|
|
|
|
|
|
|
bool ScriptAssert(bool cond, std::string const& msg, std::optional<ERROR_MODE> forceMode = std::nullopt);
|
|
|
|
|
2021-08-21 00:23:14 +01:00
|
|
|
template <typename ... Ts> bool ScriptAssertF(bool cond, std::string_view str, Ts...args)
|
|
|
|
{
|
|
|
|
if (!cond)
|
|
|
|
{
|
|
|
|
auto msg = fmt::format(str, args...);
|
|
|
|
auto mode = GetScriptErrorMode();
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case ERROR_MODE::WARN:
|
|
|
|
TENLog(msg, LogLevel::Error, LogConfig::All);
|
|
|
|
break;
|
|
|
|
case ERROR_MODE::TERMINATE:
|
|
|
|
TENLog(msg, LogLevel::Error, LogConfig::All);
|
|
|
|
throw TENScriptException(msg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cond;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ... Ts> bool ScriptAssertTerminateF(bool cond, std::string_view str, Ts...args)
|
|
|
|
{
|
|
|
|
if (!cond)
|
|
|
|
{
|
|
|
|
auto msg = fmt::format(str, args...);
|
|
|
|
TENLog(msg, LogLevel::Error, LogConfig::All);
|
|
|
|
throw TENScriptException(msg);
|
|
|
|
}
|
|
|
|
return cond;
|
|
|
|
}
|
|
|
|
|