mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-17 21:51:20 +02:00
Print messages to stdout even if the console is open
The idea behind not calling GameModel::Log in tpt.log is that that would not only print the message to stdout but also add it to GameView's list of log entries, which the console doesn't want. Sadly, this meant that messages also didn't make it to stdout when the console was open.
This commit is contained in:
@@ -1159,10 +1159,17 @@ const GameSave *GameModel::GetTransformedPlaceSave() const
|
||||
|
||||
void GameModel::Log(String message, bool printToFile)
|
||||
{
|
||||
if (logSink)
|
||||
{
|
||||
logSink(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
consoleLog.push_front(message);
|
||||
if(consoleLog.size()>100)
|
||||
consoleLog.pop_back();
|
||||
notifyLogChanged(message);
|
||||
}
|
||||
if (printToFile)
|
||||
std::cout << format::CleanString(message, false, true, false).ToUtf8() << std::endl;
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <functional>
|
||||
#include <array>
|
||||
|
||||
constexpr auto NUM_TOOLINDICES = 4;
|
||||
@@ -276,7 +277,10 @@ public:
|
||||
void SetClipboard(std::unique_ptr<GameSave> save);
|
||||
void SetPlaceSave(std::unique_ptr<GameSave> save);
|
||||
void TransformPlaceSave(Mat2<int> transform, Vec2<int> nudge);
|
||||
|
||||
std::function<void (String)> logSink;
|
||||
void Log(String message, bool printToFile);
|
||||
|
||||
std::deque<String> GetLog();
|
||||
const GameSave *GetClipboard() const;
|
||||
const GameSave *GetPlaceSave() const;
|
||||
|
@@ -138,16 +138,6 @@ static int flog(lua_State *L)
|
||||
}
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
if (lsi->currentCommand)
|
||||
{
|
||||
auto lastError = lsi->GetLastError();
|
||||
if (lsi->luacon_hasLastError)
|
||||
lastError += "; ";
|
||||
lastError += text;
|
||||
lsi->SetLastError(lastError);
|
||||
lsi->luacon_hasLastError = true;
|
||||
}
|
||||
else
|
||||
lsi->Log(CommandInterface::LogNotice, text);
|
||||
return 0;
|
||||
}
|
||||
|
@@ -507,7 +507,15 @@ int CommandInterface::Command(String command)
|
||||
else
|
||||
{
|
||||
int level = lua_gettop(L), ret = -1;
|
||||
lsi->currentCommand = true;
|
||||
lsi->gameModel->logSink = [this](String text) {
|
||||
auto *lsi = static_cast<LuaScriptInterface *>(this);
|
||||
auto lastError = GetLastError();
|
||||
if (lsi->luacon_hasLastError)
|
||||
lastError += "; ";
|
||||
lastError += text;
|
||||
SetLastError(lastError);
|
||||
lsi->luacon_hasLastError = true;
|
||||
};
|
||||
if (lsi->lastCode.length())
|
||||
lsi->lastCode += "\n";
|
||||
lsi->lastCode += command;
|
||||
@@ -564,7 +572,7 @@ int CommandInterface::Command(String command)
|
||||
|
||||
}
|
||||
}
|
||||
lsi->currentCommand = false;
|
||||
lsi->gameModel->logSink = nullptr;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@@ -102,7 +102,6 @@ public:
|
||||
bool luacon_hasLastError = false;
|
||||
String lastCode;
|
||||
|
||||
bool currentCommand = false;
|
||||
int textInputRefcount = 0;
|
||||
long unsigned int luaExecutionStart = 0;
|
||||
|
||||
|
Reference in New Issue
Block a user