3131#include " changemapobjectsorder.h"
3232#include " changeproperties.h"
3333#include " changeselectedarea.h"
34+ #include " changeworld.h"
3435#include " containerhelpers.h"
3536#include " editablemap.h"
3637#include " editor.h"
6061#include " tilelayer.h"
6162#include " tilesetdocument.h"
6263#include " transformmapobjects.h"
64+ #include " world.h"
65+ #include " worlddocument.h"
66+ #include " worldmanager.h"
6367
6468#include < QFileInfo>
6569#include < QRect>
@@ -395,7 +399,7 @@ void MapDocument::resizeMap(QSize size, QPoint offset, bool removeObjects)
395399 const QPointF pixelOffset = origin - newOrigin;
396400
397401 // Resize the map and each layer
398- QUndoCommand * command = new QUndoCommand (tr (" Resize Map" ));
402+ auto command = new QUndoCommand (tr (" Resize Map" ));
399403
400404 QList<MapObject *> objectsToRemove;
401405 QList<MapObject *> objectsToMove;
@@ -404,12 +408,12 @@ void MapDocument::resizeMap(QSize size, QPoint offset, bool removeObjects)
404408 while (Layer *layer = iterator.next ()) {
405409 switch (layer->layerType ()) {
406410 case Layer::TileLayerType: {
407- TileLayer * tileLayer = static_cast <TileLayer*>(layer);
411+ auto tileLayer = static_cast <TileLayer*>(layer);
408412 new ResizeTileLayer (this , tileLayer, size, offset, command);
409413 break ;
410414 }
411415 case Layer::ObjectGroupType: {
412- ObjectGroup * objectGroup = static_cast <ObjectGroup*>(layer);
416+ auto objectGroup = static_cast <ObjectGroup*>(layer);
413417
414418 for (MapObject *o : objectGroup->objects ()) {
415419 // Remove objects that will fall outside of the map
@@ -450,6 +454,23 @@ void MapDocument::resizeMap(QSize size, QPoint offset, bool removeObjects)
450454 new ResizeMap (this , size, command);
451455 new ChangeSelectedArea (this , movedSelection, command);
452456
457+ // Adjust world position if this map is part of any loaded worlds
458+ if (!pixelOffset.isNull ()) {
459+ const QString &mapName = fileName ();
460+ const QPoint offsetPixels = pixelOffset.toPoint ();
461+
462+ for (const auto &worldDocument : WorldManager::instance ().worlds ()) {
463+ auto world = worldDocument->world ();
464+ const int mapIdx = world->mapIndex (mapName);
465+ if (mapIdx < 0 )
466+ continue ; // also skips maps matched via pattern
467+
468+ const QPoint prevPos = world->mapRect (mapName).topLeft ();
469+ const QPoint newPos = prevPos - offsetPixels;
470+ new SetMapPosInLoadedWorld (worldDocument->fileName (), mapName, prevPos, newPos, command);
471+ }
472+ }
473+
453474 undoStack ()->push (command);
454475
455476 // TODO: Handle layers that don't match the map size correctly
@@ -460,8 +481,7 @@ void MapDocument::autocropMap()
460481 if (!mCurrentLayer || !mCurrentLayer ->isTileLayer ())
461482 return ;
462483
463- TileLayer *tileLayer = static_cast <TileLayer*>(mCurrentLayer );
464-
484+ auto tileLayer = static_cast <TileLayer*>(mCurrentLayer );
465485 const QRect bounds = tileLayer->region ().boundingRect ();
466486 if (bounds.isNull ())
467487 return ;
@@ -1072,12 +1092,12 @@ void MapDocument::paintTileLayers(const Map &map, bool mergeable,
10721092 if (!mMap ->infinite () && !target->rect ().intersects (source->bounds ()))
10731093 continue ;
10741094
1075- PaintTileLayer * paintCommand = new PaintTileLayer (this ,
1076- target,
1077- source->x (),
1078- source->y (),
1079- source,
1080- paintRegion);
1095+ auto paintCommand = new PaintTileLayer (this ,
1096+ target,
1097+ source->x (),
1098+ source->y (),
1099+ source,
1100+ paintRegion);
10811101
10821102 if (missingTilesets && !missingTilesets->isEmpty ()) {
10831103 for (const SharedTileset &tileset : std::as_const (*missingTilesets)) {
@@ -1615,7 +1635,7 @@ void MapDocument::checkIssues()
16151635
16161636 LayerIterator it (map ());
16171637 for (Layer *layer : map ()->objectGroups ()) {
1618- ObjectGroup * objectGroup = static_cast <ObjectGroup*>(layer->asObjectGroup ());
1638+ auto objectGroup = static_cast <ObjectGroup*>(layer->asObjectGroup ());
16191639 for (MapObject *mapObject : *objectGroup) {
16201640 if (const ObjectTemplate *objectTemplate = mapObject->objectTemplate ())
16211641 if (!objectTemplate->object ())
0 commit comments