Prevent paste exceeding object limit, warn when copying healspots

This commit is contained in:
GriffinR 2022-07-05 14:38:23 -04:00
parent 2051127815
commit d9b37ecb0b
3 changed files with 19 additions and 12 deletions

View file

@ -151,6 +151,7 @@ public:
void shouldReselectEvents();
void scaleMapView(int);
void openInTextEditor(const QString &path, int lineNum = 0) const;
bool eventLimitReached(QString event_type);
public slots:
void openMapScripts() const;
@ -176,7 +177,6 @@ private:
void updateEncounterFields(EncounterFields newFields);
QString getMovementPermissionText(uint16_t collision, uint16_t elevation);
QString getMetatileDisplayMessage(uint16_t metatileId);
bool eventLimitReached(Map *, QString);
bool startDetachedProcess(const QString &command,
const QString &workingDirectory = QString(),
qint64 *pid = nullptr) const;

View file

@ -2031,7 +2031,7 @@ void Editor::duplicateSelectedEvents() {
for (int i = 0; i < selected_events->length(); i++) {
Event *original = selected_events->at(i)->event;
QString eventType = original->get("event_type");
if (eventLimitReached(map, eventType)) {
if (eventLimitReached(eventType)) {
logWarn(QString("Skipping duplication, the map limit for events of type '%1' has been reached.").arg(eventType));
continue;
}
@ -2045,7 +2045,7 @@ void Editor::duplicateSelectedEvents() {
}
DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
if (project && map && !event_type.isEmpty() && !eventLimitReached(map, event_type)) {
if (project && map && !event_type.isEmpty() && !eventLimitReached(event_type)) {
Event *event = Event::createNewEvent(event_type, map->name, project);
event->put("map_name", map->name);
if (event_type == EventType::HealLocation) {
@ -2061,7 +2061,7 @@ DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
}
// Currently only object events have an explicit limit
bool Editor::eventLimitReached(Map *map, QString event_type)
bool Editor::eventLimitReached(QString event_type)
{
if (project && map && !event_type.isEmpty()) {
if (Event::typeToGroup(event_type) == EventGroup::Object)

View file

@ -1516,6 +1516,7 @@ void MainWindow::copy() {
if (type == EventType::HealLocation) {
// no copy on heal locations
logWarn(QString("Copying events of type '%1' is not allowed.").arg(type));
continue;
}
@ -1527,11 +1528,11 @@ void MainWindow::copy() {
eventsArray.append(eventJson);
}
if (!eventsArray.isEmpty()) {
copyObject["events"] = eventsArray;
setClipboardData(copyObject);
logInfo("Copied currently selected events to clipboard");
}
break;
}
}
@ -1616,6 +1617,11 @@ void MainWindow::paste() {
// paste the event to the map
QString type = event["event_type"].toString();
if (editor->eventLimitReached(type)) {
logWarn(QString("Skipping paste, the map limit for events of type '%1' has been reached.").arg(type));
continue;
}
Event *pasteEvent = Event::createNewEvent(type, editor->map->name, editor->project);
for (auto key : event.toObject().keys())
@ -1647,9 +1653,10 @@ void MainWindow::paste() {
newEvents.append(pasteEvent);
}
if (!newEvents.isEmpty()) {
editor->map->editHistory.push(new EventPaste(this->editor, editor->map, newEvents));
updateObjects();
}
break;
}
}