Don't crash on startup if recent map can't be loaded. Write logs to porymap.log file

This commit is contained in:
Marcus Huderle 2018-12-20 17:30:35 -06:00
parent 761c25ee4c
commit 40257193a4
20 changed files with 198 additions and 90 deletions

View file

@ -4,7 +4,6 @@
#include <QString>
#include <QPixmap>
#include <QMap>
#include <QDebug>
class EventType
{

View file

@ -13,7 +13,6 @@ public:
friend QDebug operator<<(QDebug debug, const HealLocation &hl);
public:
//QString group;
QString name;
int index;
uint16_t x;

View file

@ -11,7 +11,6 @@
#include <QPixmap>
#include <QObject>
#include <QDebug>
#include <QGraphicsPixmapItem>
#include <math.h>

View file

@ -2,7 +2,6 @@
#define MAPCONNECTION_H
#include <QString>
#include <QDebug>
class MapConnection {
public:

View file

@ -39,7 +39,8 @@ public:
void save();
void undo();
void redo();
void setMap(QString map_name);
void closeProject();
bool setMap(QString map_name);
void displayMap();
void displayMetatileSelector();
void displayMapMetatiles();

22
include/log.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef LOG_H
#define LOG_H
#include <QApplication>
#include <QtDebug>
#include <QFile>
#include <QTextStream>
#include <QString>
#include <QDebug>
enum LogType {
LOG_ERROR,
LOG_WARN,
LOG_INFO,
};
void logInfo(QString message);
void logWarn(QString message);
void logError(QString message);
void log(QString message, LogType type);
#endif // LOG_H

View file

@ -150,13 +150,13 @@ private:
Layout = 2,
} mapSortOrder;
void setMap(QString, bool scrollTreeView = false);
bool setMap(QString, bool scrollTreeView = false);
void redrawMapScene();
void loadDataStructures();
void populateMapList();
void sortMapList();
QString getExistingDirectory(QString);
void openProject(QString dir);
bool openProject(QString dir);
QString getDefaultMap();
void setRecentMap(QString map_name);
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
@ -168,6 +168,7 @@ private:
void displayMapProperties();
void checkToolButtons();
void initWindow();
void initCustomUI();
void initExtraShortcuts();
void initExtraSignals();
@ -175,7 +176,7 @@ private:
void initMiscHeapObjects();
void initMapSortOrder();
void loadUserSettings();
void openRecentProject();
bool openRecentProject();
void updateTilesetEditor();
bool isProjectOpen();

View file

@ -69,7 +69,7 @@ public:
QList<QStringList>* getLabelMacros(QList<QStringList>*, QString);
QStringList* getLabelValues(QList<QStringList>*, QString);
void readMapHeader(Map*);
bool readMapHeader(Map*);
void readMapLayoutsTable();
void readAllMapLayouts();
QStringList* readLayoutValues(QString layoutName);

View file

@ -50,7 +50,8 @@ SOURCES += src/core/block.cpp \
src/main.cpp \
src/mainwindow.cpp \
src/project.cpp \
src/settings.cpp
src/settings.cpp \
src/log.cpp
HEADERS += include/core/block.h \
include/core/blockdata.h \
@ -89,7 +90,8 @@ HEADERS += include/core/block.h \
include/editor.h \
include/mainwindow.h \
include/project.h \
include/settings.h
include/settings.h \
include/log.h
FORMS += forms/mainwindow.ui \
forms/eventpropertiesframe.ui \

View file

@ -5,7 +5,6 @@
#include "imageproviders.h"
#include <QTime>
#include <QDebug>
#include <QPainter>
#include <QImage>
#include <QRegularExpression>
@ -379,6 +378,10 @@ void Map::redo() {
}
void Map::commit() {
if (!layout) {
return;
}
if (layout->blockdata) {
HistoryItem *item = metatileHistory.current();
bool atCurrentHistory = item

View file

@ -1,6 +1,6 @@
#include "log.h"
#include "parseutil.h"
#include <QDebug>
#include <QRegularExpression>
#include <QStack>
@ -96,7 +96,7 @@ QList<Token> ParseUtil::tokenizeExpression(QString expression, QMap<QString, int
while (!expression.isEmpty()) {
QRegularExpressionMatch match = re.match(expression);
if (!match.hasMatch()) {
qDebug() << "Failed to tokenize expression: " << expression;
logWarn(QString("Failed to tokenize expression: '%1'").arg(expression));
break;
}
for (QString tokenType : tokenTypes) {
@ -109,7 +109,7 @@ QList<Token> ParseUtil::tokenizeExpression(QString expression, QMap<QString, int
token = actualToken;
tokenType = "decimal";
} else {
qDebug() << "Unknown identifier found in expression: " << token;
logError(QString("Unknown identifier found in expression: '%1'").arg(token));
}
}
@ -153,7 +153,7 @@ QList<Token> ParseUtil::generatePostfix(QList<Token> tokens) {
// pop the left parenthesis token
operatorStack.pop();
} else {
qDebug() << "Mismatched parentheses detected in expression!";
logError("Mismatched parentheses detected in expression!");
}
} else {
// token is an operator
@ -168,7 +168,7 @@ QList<Token> ParseUtil::generatePostfix(QList<Token> tokens) {
while (!operatorStack.isEmpty()) {
if (operatorStack.top().value == "(" || operatorStack.top().value == ")") {
qDebug() << "Mismatched parentheses detected in expression!";
logError("Mismatched parentheses detected in expression!");
} else {
output.append(operatorStack.pop());
}
@ -205,7 +205,7 @@ int ParseUtil::evaluatePostfix(QList<Token> postfix) {
} else if (token.value == "|") {
result = op1 | op2;
} else {
qDebug() << "Unsupported postfix operator: " << token.value;
logError(QString("Unsupported postfix operator: '%1'").arg(token.value));
}
stack.push(Token(QString("%1").arg(result), "decimal"));
} else {

View file

@ -4,7 +4,6 @@
#include <QPainter>
#include <QImage>
#include <QDebug>
Tileset::Tileset()
{

View file

@ -1,6 +1,7 @@
#include "editor.h"
#include "event.h"
#include "imageproviders.h"
#include "log.h"
#include "mapconnection.h"
#include "currentselectedmetatilespixmapitem.h"
#include "mapsceneeventfilter.h"
@ -48,6 +49,13 @@ void Editor::redo() {
}
}
void Editor::closeProject() {
if (this->project) {
delete this->project;
this->project = nullptr;
}
}
void Editor::setEditingMap() {
current_view = map_item;
if (map_item) {
@ -398,16 +406,24 @@ void Editor::setConnectionsVisibility(bool visible) {
}
}
void Editor::setMap(QString map_name) {
bool Editor::setMap(QString map_name) {
if (map_name.isNull()) {
return;
return false;
}
if (project) {
map = project->loadMap(map_name);
Map *loadedMap = project->loadMap(map_name);
if (!loadedMap) {
return false;
}
map = loadedMap;
selected_events->clear();
displayMap();
updateSelectedEvents();
}
return true;
}
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
@ -783,7 +799,7 @@ void Editor::updateConnectionOffset(int offset) {
void Editor::setConnectionMap(QString mapName) {
if (!mapName.isEmpty() && !project->mapNames->contains(mapName)) {
qDebug() << "Invalid map name " << mapName << " specified for connection.";
logError(QString("Invalid map name '%1' specified for connection.").arg(mapName));
return;
}
if (!selected_connection_item)
@ -926,7 +942,7 @@ void Editor::updateEmergeMap(QString mapName) {
void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
if (!mapName.isEmpty() && !project->mapNamesToMapConstants->contains(mapName)) {
qDebug() << "Invalid " << direction << " map connection: " << mapName;
logError(QString("Invalid %1 connection map name: '%2'").arg(direction).arg(mapName));
return;
}
@ -1001,7 +1017,6 @@ void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
this->editor->selectMapEvent(this, mouse->modifiers() & Qt::ControlModifier);
this->editor->updateSelectedEvents();
selectingEvent = true;
//qDebug() << QString("(%1, %2)").arg(event->get("x")).arg(event->get("y"));
}
void DraggablePixmapItem::move(int x, int y) {
@ -1025,7 +1040,6 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
}
last_x = x;
last_y = y;
//qDebug() << QString("(%1, %2)").arg(event->get("x")).arg(event->get("x"));
}
}
}

38
src/log.cpp Normal file
View file

@ -0,0 +1,38 @@
#include "log.h"
#include <QDateTime>
void logInfo(QString message) {
log(message, LogType::LOG_INFO);
}
void logWarn(QString message) {
log(message, LogType::LOG_WARN);
}
void logError(QString message) {
log(message, LogType::LOG_ERROR);
}
void log(QString message, LogType type) {
QString now = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
QString typeString = "";
switch (type)
{
case LogType::LOG_INFO:
typeString = " [INFO]";
break;
case LogType::LOG_WARN:
typeString = " [WARN]";
break;
case LogType::LOG_ERROR:
typeString = "[ERROR]";
break;
}
message = QString("%1 %2 %3").arg(now).arg(typeString).arg(message);
qDebug() << message;
QFile outFile("porymap.log");
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << message << endl;
}

View file

@ -1,13 +1,13 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "project.h"
#include "log.h"
#include "editor.h"
#include "eventpropertiesframe.h"
#include "ui_eventpropertiesframe.h"
#include "bordermetatilespixmapitem.h"
#include "currentselectedmetatilespixmapitem.h"
#include <QDebug>
#include <QFileDialog>
#include <QStandardItemModel>
#include <QShortcut>
@ -34,15 +34,13 @@ MainWindow::MainWindow(QWidget *parent) :
QCoreApplication::setApplicationName("porymap");
QApplication::setApplicationDisplayName("porymap");
QApplication::setWindowIcon(QIcon(":/icons/porymap-icon-1.ico"));
ui->setupUi(this);
this->initCustomUI();
this->initExtraSignals();
this->initExtraShortcuts();
this->initEditor();
this->initMiscHeapObjects();
this->initMapSortOrder();
this->openRecentProject();
this->initWindow();
if (!this->openRecentProject()) {
// Re-initialize everything to a blank slate if opening the recent project failed.
this->initWindow();
}
on_toolButton_Paint_clicked();
}
@ -52,6 +50,15 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::initWindow() {
this->initCustomUI();
this->initExtraSignals();
this->initExtraShortcuts();
this->initEditor();
this->initMiscHeapObjects();
this->initMapSortOrder();
}
void MainWindow::initExtraShortcuts() {
new QShortcut(QKeySequence("Ctrl+Shift+Z"), this, SLOT(redo()));
new QShortcut(QKeySequence("Ctrl+0"), this, SLOT(resetMapViewScale()));
@ -167,25 +174,28 @@ void MainWindow::loadUserSettings() {
mapSortOrder = static_cast<MapSortOrder>(settings.value("map_sort_order").toInt());
}
void MainWindow::openRecentProject() {
bool MainWindow::openRecentProject() {
QSettings settings;
QString key = "recent_projects";
if (settings.contains(key)) {
QString default_dir = settings.value(key).toStringList().last();
if (!default_dir.isNull()) {
qDebug() << QString("default_dir: '%1'").arg(default_dir);
openProject(default_dir);
logInfo(QString("Opening recent project: '%1'").arg(default_dir));
return openProject(default_dir);
}
}
return true;
}
void MainWindow::openProject(QString dir) {
bool MainWindow::openProject(QString dir) {
if (dir.isNull()) {
return;
return false;
}
this->statusBar()->showMessage(QString("Opening project %1").arg(dir));
bool success = true;
bool already_open = isProjectOpen() && (editor->project->root == dir);
if (!already_open) {
editor->project = new Project;
@ -193,14 +203,20 @@ void MainWindow::openProject(QString dir) {
setWindowTitle(editor->project->getProjectTitle());
loadDataStructures();
populateMapList();
setMap(getDefaultMap(), true);
success = setMap(getDefaultMap(), true);
} else {
setWindowTitle(editor->project->getProjectTitle());
loadDataStructures();
populateMapList();
}
this->statusBar()->showMessage(QString("Opened project %1").arg(dir));
if (success) {
this->statusBar()->showMessage(QString("Opened project %1").arg(dir));
} else {
this->statusBar()->showMessage(QString("Failed to open project %1").arg(dir));
}
return success;
}
bool MainWindow::isProjectOpen() {
@ -263,15 +279,21 @@ void MainWindow::on_action_Open_Project_triggered()
}
}
void MainWindow::setMap(QString map_name, bool scrollTreeView) {
qDebug() << QString("setMap(%1)").arg(map_name);
bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
logInfo(QString("Setting map to '%1'").arg(map_name));
if (map_name.isNull()) {
return;
return false;
}
if (!editor->setMap(map_name)) {
logError(QString("Failed to set map to '%1'").arg(map_name));
return false;
}
if (editor->map != nullptr && !editor->map->name.isNull()) {
ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), false);
}
editor->setMap(map_name);
redrawMapScene();
displayMapProperties();
@ -292,6 +314,7 @@ void MainWindow::setMap(QString map_name, bool scrollTreeView) {
setRecentMap(map_name);
updateMapList();
updateTilesetEditor();
return true;
}
void MainWindow::redrawMapScene()
@ -336,7 +359,7 @@ void MainWindow::redrawMapScene()
void MainWindow::openWarpMap(QString map_name, QString warp_num) {
// Ensure valid destination map name.
if (!editor->project->mapNames->contains(map_name)) {
qDebug() << QString("Invalid warp destination map name '%1'").arg(map_name);
logError(QString("Invalid warp destination map name '%1'").arg(map_name));
return;
}
@ -344,12 +367,15 @@ void MainWindow::openWarpMap(QString map_name, QString warp_num) {
bool ok;
int warpNum = warp_num.toInt(&ok, 0);
if (!ok) {
qDebug() << QString("Invalid warp number '%1' for destination map '%2'").arg(warp_num).arg(map_name);
logError(QString("Invalid warp number '%1' for destination map '%2'").arg(warp_num).arg(map_name));
return;
}
// Open the destination map, and select the target warp event.
setMap(map_name, true);
if (!setMap(map_name, true)) {
return;
}
QList<Event*> warp_events = editor->map->events["warp_event_group"];
if (warp_events.length() > warpNum) {
Event *warp_event = warp_events.at(warpNum);
@ -1151,7 +1177,7 @@ void MainWindow::on_toolButton_deleteObject_clicked()
editor->selected_events->removeOne(item);
}
else { // don't allow deletion of heal locations
qDebug() << "Cannot delete event of type " << item->event->get("event_type");
logWarn(QString("Cannot delete event of type '%1'").arg(item->event->get("event_type")));
}
}
updateSelectedObjects();
@ -1246,7 +1272,9 @@ void MainWindow::checkToolButtons() {
}
void MainWindow::onLoadMapRequested(QString mapName, QString fromMapName) {
setMap(mapName, true);
if (!setMap(mapName, true)) {
return;
}
editor->setSelectedConnectionFromMap(fromMapName);
}

View file

@ -1,12 +1,12 @@
#include "project.h"
#include "history.h"
#include "historyitem.h"
#include "log.h"
#include "parseutil.h"
#include "tile.h"
#include "tileset.h"
#include "event.h"
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QTextStream>
@ -64,13 +64,14 @@ Map* Project::loadMap(QString map_name) {
map->setName(map_name);
}
readMapHeader(map);
if (!readMapHeader(map))
return nullptr;
readMapLayout(map);
readMapEvents(map);
loadMapConnections(map);
map->commit();
map->metatileHistory.save();
map_cache->insert(map_name, map);
return map;
}
@ -104,7 +105,7 @@ void Project::loadMapConnections(Map *map) {
connection->map_name = mapConstantsToMapNames->value(mapConstant);
map->connections.append(connection);
} else {
qDebug() << QString("Failed to find connected map for map constant '%1'").arg(mapConstant);
logError(QString("Failed to find connected map for map constant '%1'").arg(mapConstant));
}
}
}
@ -161,9 +162,9 @@ QStringList* Project::getLabelValues(QList<QStringList> *list, QString label) {
return values;
}
void Project::readMapHeader(Map* map) {
bool Project::readMapHeader(Map* map) {
if (!map->isPersistedToFile) {
return;
return true;
}
QString label = map->name;
@ -171,7 +172,7 @@ void Project::readMapHeader(Map* map) {
QString header_text = readTextFile(root + "/data/maps/" + label + "/header.inc");
if (header_text.isNull()) {
return;
return false;
}
QStringList *header = getLabelValues(parser->parseAsm(header_text), label);
map->layout_label = header->value(0);
@ -187,6 +188,7 @@ void Project::readMapHeader(Map* map) {
map->unknown = header->value(10);
map->show_location = header->value(11);
map->battle_scene = header->value(12);
return true;
}
QString Project::readMapLayoutId(QString map_name) {
@ -278,7 +280,7 @@ void Project::saveMapConnections(Map *map) {
.arg(mapNamesToMapConstants->value(connection->map_name));
numValidConnections++;
} else {
qDebug() << QString("Failed to write map connection. %1 not a valid map name").arg(connection->map_name);
logError(QString("Failed to write map connection. '%1' is not a valid map name").arg(connection->map_name));
}
}
text += QString("\n");
@ -363,7 +365,7 @@ QStringList* Project::readLayoutValues(QString layoutLabel) {
layoutValues->append(blockdataPath);
if (layoutValues->size() != 8) {
qDebug() << "Error: Unexpected number of properties in layout '" << layoutLabel << "'";
logError(QString("Error: Unexpected number of properties in layout '%1'").arg(layoutLabel));
return nullptr;
}
@ -627,7 +629,7 @@ void Project::saveTilesetMetatileAttributes(Tileset *tileset) {
}
attrs_file.write(data);
} else {
qDebug() << QString("Could not save tileset metatile attributes file '%1'").arg(tileset->metatile_attrs_path);
logError(QString("Could not save tileset metatile attributes file '%1'").arg(tileset->metatile_attrs_path));
}
}
@ -649,7 +651,7 @@ void Project::saveTilesetMetatiles(Tileset *tileset) {
metatiles_file.write(data);
} else {
tileset->metatiles = new QList<Metatile*>;
qDebug() << QString("Could not open tileset metatiles file '%1'").arg(tileset->metatiles_path);
logError(QString("Could not open tileset metatiles file '%1'").arg(tileset->metatiles_path));
}
}
@ -690,6 +692,9 @@ Tileset* Project::loadTileset(QString label, Tileset *tileset) {
ParseUtil *parser = new ParseUtil;
QString headers_text = readTextFile(root + "/data/tilesets/headers.inc");
if (headers_text.isNull()) {
return nullptr;
}
QStringList *values = getLabelValues(parser->parseAsm(headers_text), label);
if (tileset == nullptr) {
tileset = new Tileset;
@ -762,7 +767,7 @@ void Project::writeBlockdata(QString path, Blockdata *blockdata) {
QByteArray data = blockdata->serialize();
file.write(data);
} else {
qDebug() << "Failed to open blockdata file for writing: '" << path << "'";
logError(QString("Failed to open blockdata file for writing: '%1'").arg(path));
}
}
@ -780,12 +785,12 @@ void Project::saveMap(Map *map) {
if (!map->isPersistedToFile) {
QString newMapDataDir = QString(root + "/data/maps/%1").arg(map->name);
if (!QDir::root().mkdir(newMapDataDir)) {
qDebug() << "Error: failed to create directory for new map. " << newMapDataDir;
logError(QString("Error: failed to create directory for new map: '%1'").arg(newMapDataDir));
}
QString newLayoutDir = QString(root + "/data/layouts/%1").arg(map->name);
if (!QDir::root().mkdir(newLayoutDir)) {
qDebug() << "Error: failed to create directory for new layout. " << newLayoutDir;
logError(QString("Error: failed to create directory for new layout: '%1'").arg(newLayoutDir));
}
// TODO: In the future, these files needs more structure to allow for proper parsing/saving.
@ -916,7 +921,7 @@ void Project::loadTilesetAssets(Tileset* tileset) {
for (int j = 0; j < 16; j++) {
QStringList rgb = lines[j + 3].split(QRegExp(" "), QString::SkipEmptyParts);
if (rgb.length() != 3) {
qDebug() << QString("Invalid tileset palette RGB value: '%1'").arg(lines[j + 3]);
logWarn(QString("Invalid tileset palette RGB value: '%1'").arg(lines[j + 3]));
palette.append(qRgb((j - 3) * 16, (j - 3) * 16, (j - 3) * 16));
} else {
int red = rgb[0].toInt();
@ -927,7 +932,7 @@ void Project::loadTilesetAssets(Tileset* tileset) {
}
}
} else {
qDebug() << QString("Invalid JASC-PAL palette file for tileset.");
logError(QString("Invalid JASC-PAL palette file for tileset: '%1'").arg(path));
for (int j = 0; j < 16; j++) {
palette.append(qRgb(j * 16, j * 16, j * 16));
}
@ -936,7 +941,7 @@ void Project::loadTilesetAssets(Tileset* tileset) {
for (int j = 0; j < 16; j++) {
palette.append(qRgb(j * 16, j * 16, j * 16));
}
qDebug() << QString("Could not open palette path '%1'").arg(path);
logError(QString("Could not open tileset palette path '%1'").arg(path));
}
palettes->append(palette);
@ -982,7 +987,7 @@ void Project::loadTilesetMetatiles(Tileset* tileset) {
tileset->metatiles = metatiles;
} else {
tileset->metatiles = new QList<Metatile*>;
qDebug() << QString("Could not open tileset metatiles file '%1'").arg(tileset->metatiles_path);
logError(QString("Could not open tileset metatiles file '%1'").arg(tileset->metatiles_path));
}
QFile attrs_file(tileset->metatile_attrs_path);
@ -991,7 +996,7 @@ void Project::loadTilesetMetatiles(Tileset* tileset) {
int num_metatiles = tileset->metatiles->count();
int num_metatileAttrs = data.length() / 2;
if (num_metatiles != num_metatileAttrs) {
qDebug() << QString("Metatile count %1 does not match metatile attribute count %2 in %3").arg(num_metatiles).arg(num_metatileAttrs).arg(tileset->name);
logWarn(QString("Metatile count %1 does not match metatile attribute count %2 in %3").arg(num_metatiles).arg(num_metatileAttrs).arg(tileset->name));
if (num_metatileAttrs > num_metatiles)
num_metatileAttrs = num_metatiles;
}
@ -1001,7 +1006,7 @@ void Project::loadTilesetMetatiles(Tileset* tileset) {
tileset->metatiles->at(i)->layerType = (value & 0xF000) >> 12;
}
} else {
qDebug() << QString("Could not open tileset metatile attributes file '%1'").arg(tileset->metatile_attrs_path);
logError(QString("Could not open tileset metatile attributes file '%1'").arg(tileset->metatile_attrs_path));
}
}
@ -1015,7 +1020,7 @@ Blockdata* Project::readBlockdata(QString path) {
blockdata->addBlock(word);
}
} else {
qDebug() << "Failed to open blockdata path '" << path << "'";
logError(QString("Failed to open blockdata path '%1'").arg(path));
}
return blockdata;
@ -1047,8 +1052,7 @@ Tileset* Project::getTileset(QString label, bool forceLoad) {
QString Project::readTextFile(QString path) {
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
//QMessageBox::information(0, "Error", QString("Could not open '%1': ").arg(path) + file.errorString());
qDebug() << QString("Could not open '%1': ").arg(path) + file.errorString();
logError(QString("Could not open '%1': ").arg(path) + file.errorString());
return QString();
}
QTextStream in(&file);
@ -1064,7 +1068,7 @@ void Project::saveTextFile(QString path, QString text) {
if (file.open(QIODevice::WriteOnly)) {
file.write(text.toUtf8());
} else {
qDebug() << QString("Could not open '%1' for writing: ").arg(path) + file.errorString();
logError(QString("Could not open '%1' for writing: ").arg(path) + file.errorString());
}
}
@ -1073,14 +1077,14 @@ void Project::appendTextFile(QString path, QString text) {
if (file.open(QIODevice::Append)) {
file.write(text.toUtf8());
} else {
qDebug() << QString("Could not open '%1' for appending: ").arg(path) + file.errorString();
logError(QString("Could not open '%1' for appending: ").arg(path) + file.errorString());
}
}
void Project::deleteFile(QString path) {
QFile file(path);
if (file.exists() && !file.remove()) {
qDebug() << QString("Could not delete file '%1': ").arg(path) + file.errorString();
logError(QString("Could not delete file '%1': ").arg(path) + file.errorString());
}
}
@ -1224,13 +1228,13 @@ QMap<QString, QStringList> Project::getTilesets() {
// Advance to command specifying whether or not it is a secondary tileset
i += 2;
if (commands->at(i).at(0) != ".byte") {
qDebug() << "Unexpected command found for secondary tileset flag in tileset" << tilesetLabel << ". Expected '.byte', but found: " << commands->at(i).at(0);
logWarn(QString("Unexpected command found for secondary tileset flag in tileset '%1'. Expected '.byte', but found: '%2'").arg(tilesetLabel).arg(commands->at(i).at(0)));
continue;
}
QString secondaryTilesetValue = commands->at(i).at(1);
if (secondaryTilesetValue != "TRUE" && secondaryTilesetValue != "FALSE" && secondaryTilesetValue != "0" && secondaryTilesetValue != "1") {
qDebug() << "Unexpected secondary tileset flag found. Expected \"TRUE\", \"FALSE\", \"0\", or \"1\", but found: " << secondaryTilesetValue;
logWarn(QString("Unexpected secondary tileset flag found. Expected \"TRUE\", \"FALSE\", \"0\", or \"1\", but found: '%1'").arg(secondaryTilesetValue));
continue;
}
@ -1300,7 +1304,7 @@ void Project::readTilesetProperties() {
if (error)
{
qDebug() << "Some global tileset values could not be loaded. Using default values";
logError("Some global tileset values could not be loaded. Using default values instead.");
}
}
}
@ -1383,7 +1387,7 @@ void Project::readMetatileBehaviors() {
this->metatileBehaviorMapInverse.insert(this->metatileBehaviorMap[defineName], defineName);
}
} else {
qDebug() << "Failed to read C defines file: " << filepath;
logError(QString("Failed to read C defines file: '%1'").arg(filepath));
}
}
@ -1400,7 +1404,7 @@ void Project::readCDefinesSorted(QString filepath, QStringList prefixes, QString
}
*definesToSet = definesInverse.values();
} else {
qDebug() << "Failed to read C defines file: " << filepath;
logError(QString("Failed to read C defines file: '%1'").arg(filepath));
}
}
@ -1433,7 +1437,7 @@ void Project::saveMapsWithConnections() {
if (mapNamesToMapConstants->contains(mapName)) {
text += QString("\t.include \"data/maps/%1/connections.inc\"\n").arg(mapName);
} else {
qDebug() << QString("Failed to write connection include. %1 not a valid map name").arg(mapName);
logError(QString("Failed to write connection include. %1 not a valid map name").arg(mapName));
}
}
saveTextFile(path, text);
@ -1694,7 +1698,7 @@ void Project::readMapEvents(Map *map) {
warp->put("event_type", EventType::Warp);
map->events["warp_event_group"].append(warp);
} else {
qDebug() << QString("Destination map constant '%1' is invalid for warp").arg(mapConstant);
logError(QString("Destination map constant '%1' is invalid for warp").arg(mapConstant));
}
}
}

View file

@ -1,6 +1,6 @@
#include "imageproviders.h"
#include "log.h"
#include <QPainter>
#include <QDebug>
QImage getCollisionMetatileImage(Block block) {
return getCollisionMetatileImage(block.collision, block.elevation);
@ -53,7 +53,7 @@ QImage getMetatileImage(uint16_t tile, Tileset *primaryTileset, Tileset *seconda
tile_image.setColor(j, palette.value(j));
}
} else {
qDebug() << "Tile is referring to invalid palette number: " << tile_.palette;
logWarn(QString("Tile '%1' is referring to invalid palette number: '%2'").arg(tile_.tile).arg(tile_.palette));
}
// The top layer of the metatile has its first color displayed at transparent.

View file

@ -1,4 +1,5 @@
#include "mappixmapitem.h"
#include "log.h"
#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
@ -436,7 +437,7 @@ void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) {
selection.append(QPoint(x, y));
}
}
qDebug() << QString("selected (%1, %2) -> (%3, %4)").arg(x1).arg(y1).arg(x2).arg(y2);
logInfo(QString("selected (%1, %2) -> (%3, %4)").arg(x1).arg(y1).arg(x2).arg(y2));
}
}
}

View file

@ -1,6 +1,5 @@
#include "neweventtoolbutton.h"
#include <QMenu>
#include <QDebug>
// Custom QToolButton which has a context menu that expands to allow
// selection of different types of map events.

View file

@ -1,8 +1,8 @@
#include "tileseteditor.h"
#include "ui_tileseteditor.h"
#include "log.h"
#include "imageproviders.h"
#include <QFileDialog>
#include <QDebug>
#include <QMessageBox>
#include <QDialogButtonBox>
#include <QCloseEvent>
@ -328,7 +328,7 @@ void TilesetEditor::importTilesetTiles(Tileset *tileset, bool primary) {
return;
}
qDebug() << QString("Importing %1 tileset tiles '%2'").arg(descriptor).arg(filepath);
logInfo(QString("Importing %1 tileset tiles '%2'").arg(descriptor).arg(filepath));
// Validate image dimensions.
QImage image = QImage(filepath);