diff --git a/editor.cpp b/editor.cpp index 1afbf783..8bafbb4d 100755 --- a/editor.cpp +++ b/editor.cpp @@ -1145,8 +1145,8 @@ void MapPixmapItem::paintSmartPath(int x, int y) { int openTile = map->selected_metatiles->at(4); // Fill the region with the open tile. - for (int i = -1; i <= 1; i++) - for (int j = -1; j <= 1; j++) { + for (int i = 0; i <= 1; i++) + for (int j = 0; j <= 1; j++) { // Check if in map bounds. if (!(i + x < map->getWidth() && i + x >= 0 && j + y < map->getHeight() && j + y >= 0)) continue; @@ -1160,14 +1160,14 @@ void MapPixmapItem::paintSmartPath(int x, int y) { } // Go back and resolve the edge tiles - for (int i = -2; i <= 2; i++) - for (int j = -2; j <= 2; j++) { + for (int i = -1; i <= 2; i++) + for (int j = -1; j <= 2; j++) { // Check if in map bounds. if (!(i + x < map->getWidth() && i + x >= 0 && j + y < map->getHeight() && j + y >= 0)) continue; // Ignore the corners, which can't possible be affected by the smart path. - if ((i == -2 && j == -2) || (i == 2 && j == -2) || - (i == -2 && j == 2) || (i == 2 && j == 2)) + if ((i == -1 && j == -1) || (i == 2 && j == -1) || + (i == -1 && j == 2) || (i == 2 && j == 2)) continue; // Ignore tiles that aren't part of the smart path set. @@ -1659,6 +1659,7 @@ QList *Editor::getObjects() { void Editor::redrawObject(DraggablePixmapItem *item) { if (item) { item->setPixmap(item->event->pixmap); + item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape); if (selected_events && selected_events->contains(item)) { QImage image = item->pixmap().toImage(); QPainter painter(&image); diff --git a/editor.h b/editor.h index 0bc22ddb..4bfbfb23 100755 --- a/editor.h +++ b/editor.h @@ -133,6 +133,7 @@ private: void updateMirroredConnection(Connection*, QString, QString, bool isDelete = false); Event* createNewObjectEvent(); Event* createNewWarpEvent(); + Event* createNewHealLocationEvent(); Event* createNewCoordScriptEvent(); Event* createNewCoordWeatherEvent(); Event* createNewSignEvent(); @@ -176,10 +177,8 @@ public: int last_x; int last_y; void updatePosition() { - int x = event->x() * 16; - int y = event->y() * 16; - x -= pixmap().width() / 32 * 16; - y -= pixmap().height() - 16; + int x = event->getPixelX(); + int y = event->getPixelY(); setX(x); setY(y); setZValue(event->y()); @@ -195,6 +194,7 @@ public: objects.append(event); event->pixmap = QPixmap(); editor->project->loadEventPixmaps(objects); + this->updatePosition(); editor->redrawObject(this); emit spriteChanged(event->pixmap); } diff --git a/event.cpp b/event.cpp index e26b4540..a1c6f5e4 100755 --- a/event.cpp +++ b/event.cpp @@ -1,4 +1,5 @@ #include "event.h" +#include "map.h" QString EventType::Object = "event_object"; QString EventType::Warp = "event_warp"; @@ -7,9 +8,12 @@ QString EventType::CoordWeather = "event_trap_weather"; QString EventType::Sign = "event_sign"; QString EventType::HiddenItem = "event_hidden_item"; QString EventType::SecretBase = "event_secret_base"; +QString EventType::HealLocation = "event_heal_location"; Event::Event() { + this->spriteWidth = 16; + this->spriteHeight = 16; } Event* Event::createNewEvent(QString event_type, QString map_name) @@ -19,6 +23,8 @@ Event* Event::createNewEvent(QString event_type, QString map_name) event = createNewObjectEvent(); } else if (event_type == EventType::Warp) { event = createNewWarpEvent(map_name); + } else if (event_type == EventType::HealLocation) { + event = createNewHealLocationEvent(map_name); } else if (event_type == EventType::CoordScript) { event = createNewCoordScriptEvent(); } else if (event_type == EventType::CoordWeather) { @@ -64,6 +70,15 @@ Event* Event::createNewWarpEvent(QString map_name) return event; } +Event* Event::createNewHealLocationEvent(QString map_name) +{ + Event *event = new Event; + event->put("event_group_type", "heal_event_group"); + event->put("event_type", EventType::HealLocation); + event->put("loc_name", QString(Map::mapConstantFromName(map_name)).remove(0,4)); + return event; +} + Event* Event::createNewCoordScriptEvent() { Event *event = new Event; @@ -113,6 +128,16 @@ Event* Event::createNewSecretBaseEvent() return event; } +int Event::getPixelX() +{ + return (this->x() * 16) - qMax(0, (this->spriteWidth - 16) / 2); +} + +int Event::getPixelY() +{ + return (this->y() * 16) - qMax(0, this->spriteHeight - 16); +} + QString Event::buildObjectEventMacro(int item_index) { int radius_x = this->getInt("radius_x"); @@ -150,6 +175,21 @@ QString Event::buildWarpEventMacro(QMap *mapNamesToMapConstant return text; } +HealLocation Event::buildHealLocation() +{ + HealLocation hl; + hl.name = this->get("loc_name"); + try { + hl.index = this->get("index").toInt(); + } + catch(...) { + hl.index = 0; + } + hl.x = this->get("x").toInt(); + hl.y = this->get("y").toInt(); + return hl; +} + QString Event::buildCoordScriptEventMacro() { QString text = ""; @@ -208,3 +248,13 @@ QString Event::buildSecretBaseEventMacro() text += "\n"; return text; } + +void Event::setPixmapFromSpritesheet(QImage spritesheet, int spriteWidth, int spriteHeight) +{ + // Set first palette color fully transparent. + QImage img = spritesheet.copy(0, 0, spriteWidth, spriteHeight); + img.setColor(0, qRgba(0, 0, 0, 0)); + pixmap = QPixmap::fromImage(img); + this->spriteWidth = spriteWidth; + this->spriteHeight = spriteHeight; +} diff --git a/event.h b/event.h index 03313d27..fc71e8a7 100755 --- a/event.h +++ b/event.h @@ -1,6 +1,7 @@ #ifndef EVENT_H #define EVENT_H +#include "heallocation.h" #include #include #include @@ -16,6 +17,7 @@ public: static QString Sign; static QString HiddenItem; static QString SecretBase; + static QString HealLocation; }; class Event @@ -54,6 +56,7 @@ public: static Event* createNewEvent(QString, QString); static Event* createNewObjectEvent(); static Event* createNewWarpEvent(QString); + static Event* createNewHealLocationEvent(QString); static Event* createNewCoordScriptEvent(); static Event* createNewCoordWeatherEvent(); static Event* createNewSignEvent(); @@ -62,14 +65,20 @@ public: QString buildObjectEventMacro(int); QString buildWarpEventMacro(QMap*); + HealLocation buildHealLocation(); QString buildCoordScriptEventMacro(); QString buildCoordWeatherEventMacro(); QString buildSignEventMacro(); QString buildHiddenItemEventMacro(); QString buildSecretBaseEventMacro(); + void setPixmapFromSpritesheet(QImage, int, int); + int getPixelX(); + int getPixelY(); QMap values; QPixmap pixmap; + int spriteWidth; + int spriteHeight; }; #endif // EVENT_H diff --git a/heallocation.cpp b/heallocation.cpp new file mode 100644 index 00000000..7652b96a --- /dev/null +++ b/heallocation.cpp @@ -0,0 +1,19 @@ +#include "heallocation.h" + +//HealLocation::HealLocation() {} + +HealLocation::HealLocation(QString map, int i, size_t x0, size_t y0) { + + name = map; + index = i; + x = x0; + y = y0; + +} + +QDebug operator<<(QDebug debug, const HealLocation &hl) { + + debug << "HealLocation_" + hl.name << "(" << hl.x << ',' << hl.y << ")"; + return debug; + +} diff --git a/heallocation.h b/heallocation.h new file mode 100644 index 00000000..bf01b30a --- /dev/null +++ b/heallocation.h @@ -0,0 +1,23 @@ +#ifndef HEALLOCATION_H +#define HEALLOCATION_H + +#include +#include + +class HealLocation { + +public: + HealLocation()=default; + HealLocation(QString, int, size_t, size_t); + friend QDebug operator<<(QDebug debug, const HealLocation &hl); + +public: + //QString group; + QString name; + int index; + size_t x; + size_t y; + +}; + +#endif // HEALLOCATION_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 85dd6403..daf19ceb 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -15,10 +15,14 @@ #include #include #include +#include #include #include #include #include +#include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -556,6 +560,12 @@ void MainWindow::redo() { editor->redo(); } +// Open current map scripts in system default editor for .inc files +void MainWindow::openInTextEditor() { + QString path = QDir::cleanPath("file://" + editor->project->root + QDir::separator() + "data/maps/" + editor->map->name + "/scripts.inc"); + QDesktopServices::openUrl(QUrl(path)); +} + void MainWindow::on_action_Save_triggered() { editor->save(); updateMapList(); @@ -684,9 +694,12 @@ void MainWindow::updateSelectedObjects() { QString event_type = item->event->get("event_type"); QString event_group_type = item->event->get("event_group_type"); QString map_name = item->event->get("map_name"); + int event_offs; + if (event_type == "event_warp") { event_offs = 0; } + else { event_offs = 1; } frame->ui->label_name->setText( QString("%1: %2 %3") - .arg(editor->project->getMap(map_name)->events.value(event_group_type).indexOf(item->event) + 1) + .arg(editor->project->getMap(map_name)->events.value(event_group_type).indexOf(item->event) + event_offs) .arg(map_name) .arg(event_type) ); @@ -744,8 +757,8 @@ void MainWindow::updateSelectedObjects() { fields << "sight_radius_tree_id"; } else if (event_type == EventType::Warp) { - fields << "destination_warp"; fields << "destination_map_name"; + fields << "destination_warp"; } else if (event_type == EventType::CoordScript) { fields << "script_label"; @@ -899,17 +912,27 @@ void MainWindow::on_toolButton_deleteObject_clicked() if (editor && editor->selected_events) { if (editor->selected_events->length()) { for (DraggablePixmapItem *item : *editor->selected_events) { - editor->deleteEvent(item->event); - if (editor->scene->items().contains(item)) { - editor->scene->removeItem(item); + if (item->event->get("event_type") != EventType::HealLocation) { + editor->deleteEvent(item->event); + if (editor->scene->items().contains(item)) { + editor->scene->removeItem(item); + } + editor->selected_events->removeOne(item); + } + else { // don't allow deletion of heal locations + qDebug() << "Cannot delete event of type " << item->event->get("event_type"); } - editor->selected_events->removeOne(item); } updateSelectedObjects(); } } } +void MainWindow::on_toolButton_Open_Scripts_clicked() +{ + openInTextEditor(); +} + void MainWindow::on_toolButton_Paint_clicked() { editor->map_edit_mode = "paint"; diff --git a/mainwindow.h b/mainwindow.h index b8f9169d..b2c74610 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -38,6 +38,7 @@ private slots: void redo(); void toggleEditModeMove(); + void openInTextEditor(); void onLoadMapRequested(QString, QString); void onMapChanged(Map *map); @@ -65,6 +66,7 @@ private slots: void on_actionBetter_Cursors_triggered(); void on_toolButton_deleteObject_clicked(); + void on_toolButton_Open_Scripts_clicked(); void addNewEvent(QString); void updateSelectedObjects(); diff --git a/mainwindow.ui b/mainwindow.ui index 160b223c..65b1adfd 100755 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -351,7 +351,7 @@ 0 0 - 492 + 462 599 @@ -840,7 +840,7 @@ 8 0 - 293 + 323 368 @@ -1356,6 +1356,29 @@ + + + + Open Map Scripts + + + false + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + diff --git a/map.h b/map.h index 550e6a9b..b41c97c4 100755 --- a/map.h +++ b/map.h @@ -129,6 +129,7 @@ public: QString layout_id; QString location; QString requiresFlash; + QString isFlyable; // TODO: implement this QString weather; QString type; QString unknown; diff --git a/neweventtoolbutton.cpp b/neweventtoolbutton.cpp index 51d4ee2b..cfd0adab 100644 --- a/neweventtoolbutton.cpp +++ b/neweventtoolbutton.cpp @@ -23,6 +23,12 @@ void NewEventToolButton::initButton() this->newWarpAction->setIcon(QIcon(":/icons/add.ico")); connect(this->newWarpAction, SIGNAL(triggered(bool)), this, SLOT(newWarp())); + /* // disable this functionality for now + this->newHealLocationAction = new QAction("New Heal Location", this); + this->newHealLocationAction->setIcon(QIcon(":/icons/add.ico")); + connect(this->newHealLocationAction, SIGNAL(triggered(bool)), this, SLOT(newHealLocation())); + */ + this->newCoordScriptAction = new QAction("New Coord Script", this); this->newCoordScriptAction->setIcon(QIcon(":/icons/add.ico")); connect(this->newCoordScriptAction, SIGNAL(triggered(bool)), this, SLOT(newCoordScript())); @@ -46,6 +52,7 @@ void NewEventToolButton::initButton() QMenu *alignMenu = new QMenu(); alignMenu->addAction(this->newObjectAction); alignMenu->addAction(this->newWarpAction); + //alignMenu->addAction(this->newHealLocationAction); alignMenu->addAction(this->newCoordScriptAction); alignMenu->addAction(this->newCoordWeatherAction); alignMenu->addAction(this->newSignAction); @@ -72,6 +79,12 @@ void NewEventToolButton::newWarp() emit newEventAdded(this->selectedEventType); } +void NewEventToolButton::newHealLocation() +{ + this->selectedEventType = EventType::HealLocation; + emit newEventAdded(this->selectedEventType); +} + void NewEventToolButton::newCoordScript() { this->selectedEventType = EventType::CoordScript; diff --git a/neweventtoolbutton.h b/neweventtoolbutton.h index f4bb7f55..d75be3b4 100644 --- a/neweventtoolbutton.h +++ b/neweventtoolbutton.h @@ -14,6 +14,7 @@ public: public slots: void newObject(); void newWarp(); + void newHealLocation(); void newCoordScript(); void newCoordWeather(); void newSign(); @@ -25,6 +26,7 @@ private: QString selectedEventType; QAction *newObjectAction; QAction *newWarpAction; + QAction *newHealLocationAction; QAction *newCoordScriptAction; QAction *newCoordWeatherAction; QAction *newSignAction; diff --git a/parseutil.cpp b/parseutil.cpp index 9b481159..15c24b16 100755 --- a/parseutil.cpp +++ b/parseutil.cpp @@ -68,6 +68,24 @@ int ParseUtil::evaluateDefine(QString define, QMap* knownDefines) return evaluatePostfix(postfixExpression); } +// arg here is the text in the file src/data/heal_locations.h +// returns a list of HealLocations (mapname, x, y) +QList* ParseUtil::parseHealLocs(QString text) { + QList *parsed = new QList; + QStringList lines = text.split('\n'); + + int i = 1; + for (auto line : lines){ + if (line.contains("MAP_GROUP")){ + QList li = line.replace(" ","").chopped(2).remove('{').split(','); + HealLocation hloc = HealLocation(li[1].remove("MAP_NUM(").remove(")"), i, li[2].toInt(), li[3].toInt()); + parsed->append(hloc); + i++; + } + } + return parsed; +} + QList ParseUtil::tokenizeExpression(QString expression, QMap* knownIdentifiers) { QList tokens; diff --git a/parseutil.h b/parseutil.h index dfd52c16..23e095fc 100755 --- a/parseutil.h +++ b/parseutil.h @@ -1,6 +1,8 @@ #ifndef PARSEUTIL_H #define PARSEUTIL_H +#include "heallocation.h" + #include #include #include @@ -35,6 +37,7 @@ public: void strip_comment(QString*); QList* parseAsm(QString); int evaluateDefine(QString, QMap*); + QList* parseHealLocs(QString); private: QList tokenizeExpression(QString expression, QMap* knownIdentifiers); QList generatePostfix(QList tokens); diff --git a/pretmap.pro b/pretmap.pro index 96014047..9d3ae04e 100755 --- a/pretmap.pro +++ b/pretmap.pro @@ -1,52 +1,54 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2016-08-31T15:19:13 -# -#------------------------------------------------- - -QT += core gui - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = pretmap -TEMPLATE = app - - -SOURCES += main.cpp\ - mainwindow.cpp \ - project.cpp \ - map.cpp \ - blockdata.cpp \ - block.cpp \ - tileset.cpp \ - tile.cpp \ - event.cpp \ - editor.cpp \ - objectpropertiesframe.cpp \ - graphicsview.cpp \ - parseutil.cpp \ - neweventtoolbutton.cpp \ - noscrollcombobox.cpp \ - noscrollspinbox.cpp - -HEADERS += mainwindow.h \ - project.h \ - map.h \ - blockdata.h \ - block.h \ - tileset.h \ - tile.h \ - event.h \ - editor.h \ - objectpropertiesframe.h \ - graphicsview.h \ - parseutil.h \ - neweventtoolbutton.h \ - noscrollcombobox.h \ - noscrollspinbox.h - -FORMS += mainwindow.ui \ - objectpropertiesframe.ui - -RESOURCES += \ - resources/images.qrc +#------------------------------------------------- +# +# Project created by QtCreator 2016-08-31T15:19:13 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = pretmap +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp \ + project.cpp \ + map.cpp \ + blockdata.cpp \ + block.cpp \ + tileset.cpp \ + tile.cpp \ + event.cpp \ + editor.cpp \ + objectpropertiesframe.cpp \ + graphicsview.cpp \ + parseutil.cpp \ + neweventtoolbutton.cpp \ + noscrollcombobox.cpp \ + noscrollspinbox.cpp \ + heallocation.cpp + +HEADERS += mainwindow.h \ + project.h \ + map.h \ + blockdata.h \ + block.h \ + tileset.h \ + tile.h \ + event.h \ + editor.h \ + objectpropertiesframe.h \ + graphicsview.h \ + parseutil.h \ + neweventtoolbutton.h \ + noscrollcombobox.h \ + noscrollspinbox.h \ + heallocation.h + +FORMS += mainwindow.ui \ + objectpropertiesframe.ui + +RESOURCES += \ + resources/images.qrc diff --git a/project.cpp b/project.cpp index fd352dfa..5bd0d2bb 100755 --- a/project.cpp +++ b/project.cpp @@ -501,6 +501,73 @@ void Project::saveMapConstantsHeader() { saveTextFile(root + "/include/constants/maps.h", text); } +// saves heal location coords in root + /src/data/heal_locations.h +// and indexes as defines in root + /include/constants/heal_locations.h +void Project::saveHealLocationStruct(Map *map) { + QString tab = QString(" "); + + QString data_text = QString("static const struct HealLocation sHealLocations[] =\n{\n"); + + QString constants_text = QString("#ifndef GUARD_CONSTANTS_HEAL_LOCATIONS_H\n"); + constants_text += QString("#define GUARD_CONSTANTS_HEAL_LOCATIONS_H\n\n"); + + QMap flyableMapsDupes; + QSet flyableMapsUnique; + + // set flyableMapsDupes and flyableMapsUnique + for (auto it = flyableMaps.begin(); it != flyableMaps.end(); it++) { + HealLocation loc = *it; + QString xname = loc.name; + if (flyableMapsUnique.contains(xname)) { + flyableMapsDupes[xname] = 1; + } + flyableMapsUnique.insert(xname); + } + + // set new location in flyableMapsList + if (map->events["heal_event_group"].length() > 0) { + for (Event *heal : map->events["heal_event_group"]) { + HealLocation hl = heal->buildHealLocation(); + flyableMaps[hl.index - 1] = hl; + } + } + + int i = 1; + + for (auto map_in : flyableMaps) { + data_text += QString(" {MAP_GROUP(%1), MAP_NUM(%1), %2, %3},\n") + .arg(map_in.name) + .arg(map_in.x) + .arg(map_in.y); + + QString ending = QString(""); + + // must add _1 / _2 for maps that have duplicates + if (flyableMapsDupes.keys().contains(map_in.name)) { + // map contains multiple heal locations + ending += QString("_%1").arg(flyableMapsDupes[map_in.name]); + flyableMapsDupes[map_in.name]++; + } + if (map_in.index != 0) { + constants_text += QString("#define HEAL_LOCATION_%1 %2\n") + .arg(map_in.name + ending) + .arg(map_in.index); + } + else { + constants_text += QString("#define HEAL_LOCATION_%1 %2\n") + .arg(map_in.name + ending) + .arg(i); + } + i++; + } + + data_text += QString("};\n"); + constants_text += QString("\n#endif // GUARD_CONSTANTS_HEAL_LOCATIONS_H\n"); + + saveTextFile(root + "/src/data/heal_locations.h", data_text); + saveTextFile(root + "/include/constants/heal_locations.h", constants_text); +} + void Project::loadMapTilesets(Map* map) { if (map->layout->has_unsaved_changes) { return; @@ -947,6 +1014,11 @@ void Project::readMapGroups() { groupNames = groups; groupedMapNames = groupedMaps; mapNames = maps; + + QString hltext = readTextFile(root + QString("/src/data/heal_locations.h")); + QList* hl = parser->parseHealLocs(hltext); + flyableMaps = *hl; + delete hl; } Map* Project::addNewMapToGroup(QString mapName, int groupNum) { @@ -1212,6 +1284,9 @@ void Project::loadEventPixmaps(QList objects) { if (!object->pixmap.isNull()) { continue; } + + object->spriteWidth = 16; + object->spriteHeight = 16; QString event_type = object->get("event_type"); if (event_type == EventType::Object) { object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(0, 0, 16, 16); @@ -1221,22 +1296,39 @@ void Project::loadEventPixmaps(QList objects) { object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(32, 0, 16, 16); } else if (event_type == EventType::Sign || event_type == EventType::HiddenItem || event_type == EventType::SecretBase) { object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(48, 0, 16, 16); + } else if (event_type == EventType::HealLocation) { + object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(64, 0, 16, 16); } if (event_type == EventType::Object) { int sprite_id = constants.value(object->get("sprite")); QString info_label = pointers.value(sprite_id).replace("&", ""); - QString pic_label = readCArray(info_text, info_label).value(14); + QStringList gfx_info = readCArray(info_text, info_label); + QString pic_label = gfx_info.value(14); + QString dimensions_label = gfx_info.value(11); + QString subsprites_label = gfx_info.value(12); QString gfx_label = readCArray(pic_text, pic_label).value(0); gfx_label = gfx_label.section(QRegExp("[\\(\\)]"), 1, 1); QString path = readCIncbin(assets_text, gfx_label); if (!path.isNull()) { path = fixGraphicPath(path); - QPixmap pixmap(root + "/" + path); - if (!pixmap.isNull()) { - object->pixmap = pixmap; + QImage spritesheet(root + "/" + path); + if (!spritesheet.isNull()) { + // Infer the sprite dimensions from the OAM labels. + int spriteWidth = spritesheet.width(); + int spriteHeight = spritesheet.height(); + QRegularExpression re("\\S+_(\\d+)x(\\d+)"); + QRegularExpressionMatch dimensionMatch = re.match(dimensions_label); + if (dimensionMatch.hasMatch()) { + QRegularExpressionMatch oamTablesMatch = re.match(subsprites_label); + if (oamTablesMatch.hasMatch()) { + spriteWidth = dimensionMatch.captured(1).toInt(); + spriteHeight = dimensionMatch.captured(2).toInt(); + } + } + object->setPixmapFromSpritesheet(spritesheet, spriteWidth, spriteHeight); } } } @@ -1309,6 +1401,15 @@ void Project::saveMapEvents(Map *map) { .arg(bgEventsLabel); saveTextFile(path, text); + + // save heal event changes + if (map->events["heal_event_group"].length() > 0) { + for (Event *heal : map->events["heal_event_group"]) { + HealLocation hl = heal->buildHealLocation(); + flyableMaps[hl.index - 1] = hl; + } + } + saveHealLocationStruct(map); } void Project::readMapEvents(Map *map) { @@ -1379,6 +1480,29 @@ void Project::readMapEvents(Map *map) { } } + map->events["heal_event_group"].clear(); + + for (auto it = flyableMaps.begin(); it != flyableMaps.end(); it++) { + + HealLocation loc = *it; + + //if TRUE map is flyable / has healing location + if (loc.name == QString(mapNamesToMapConstants->value(map->name)).remove(0,4)) { + Event *heal = new Event; + heal->put("map_name", map->name); + heal->put("x", loc.x); + heal->put("y", loc.y); + heal->put("loc_name", loc.name); + heal->put("index", loc.index); + heal->put("elevation", 3); // TODO: change this? + heal->put("destination_map_name", mapConstantsToMapNames->value(map->name)); + heal->put("event_group_type", "heal_event_group"); + heal->put("event_type", EventType::HealLocation); + map->events["heal_event_group"].append(heal); + } + + } + QList *coords = getLabelMacros(parseAsm(text), coordEventsLabel); map->events["coord_event_group"].clear(); for (QStringList command : *coords) { @@ -1455,6 +1579,7 @@ void Project::readMapEvents(Map *map) { void Project::setNewMapEvents(Map *map) { map->events["object_event_group"].clear(); map->events["warp_event_group"].clear(); + map->events["heal_event_group"].clear(); map->events["coord_event_group"].clear(); map->events["bg_event_group"].clear(); } diff --git a/project.h b/project.h index 90796295..49e348b2 100755 --- a/project.h +++ b/project.h @@ -3,6 +3,7 @@ #include "map.h" #include "blockdata.h" +#include "heallocation.h" #include #include @@ -17,6 +18,7 @@ public: QMap *map_groups; QList groupedMapNames; QStringList *mapNames = NULL; + QList flyableMaps; QMap* mapConstantsToMapNames; QMap* mapNamesToMapConstants; QList mapLayoutsTable; @@ -77,6 +79,7 @@ public: void saveAllMapLayouts(); void saveMapGroupsTable(); void saveMapConstantsHeader(); + void saveHealLocationStruct(Map*); QList* parseAsm(QString text); QStringList getSongNames(); diff --git a/resources/images/Entities_16x16.png b/resources/images/Entities_16x16.png index db480f6e..2d35d31d 100755 Binary files a/resources/images/Entities_16x16.png and b/resources/images/Entities_16x16.png differ