@@ -5060,123 +5060,11 @@ bool Game_Interpreter::CommandManiacChangePictureId(lcf::rpg::EventCommand const
50605060 }
50615061
50625062 auto & pictures = *Main_Data::game_pictures;
5063- auto & windows = *Main_Data::game_windows;
50645063
50655064 auto isValidId = [](int id) {
50665065 return id > 0 ;
50675066 };
50685067
5069- // Helper to move a single picture from src to dst
5070- auto move_picture = [&](int src, int dst) {
5071- // Ensure existence in vectors to avoid reference invalidation during assignments
5072- int max_id = std::max (src, dst);
5073- pictures.GetPicture (max_id);
5074- windows.GetWindow (max_id);
5075-
5076- auto & src_pic = pictures.GetPicture (src);
5077- auto & dst_pic = pictures.GetPicture (dst);
5078-
5079- // If source is empty, erase destination
5080- if (!src_pic.Exists () && !src_pic.IsWindowAttached ()) {
5081- dst_pic.Erase ();
5082- return ;
5083- }
5084-
5085- // 1. Handle Window Data (String Pictures)
5086- if (src_pic.IsWindowAttached ()) {
5087- auto & src_win = windows.GetWindow (src);
5088- auto & dst_win = windows.GetWindow (dst);
5089- dst_win.data = src_win.data ;
5090- dst_win.data .ID = dst;
5091- src_win.Erase ();
5092- }
5093- else {
5094- // If overwriting a window picture with a normal one, clear the old window data
5095- // (Safe to call even if dst wasn't a window before)
5096- windows.GetWindow (dst).Erase ();
5097- }
5098-
5099- // 2. Handle Picture Data
5100- BitmapRef src_bmp = src_pic.sprite ? src_pic.sprite ->GetBitmap () : nullptr ;
5101- auto request_id = src_pic.request_id ;
5102- src_pic.request_id = nullptr ; // Prevent cancellation on Erase
5103-
5104- dst_pic.data = src_pic.data ;
5105- dst_pic.data .ID = dst;
5106- dst_pic.request_id = request_id;
5107-
5108- src_pic.Erase ();
5109-
5110- // 3. Refresh Sprite
5111- if (dst_pic.IsWindowAttached ()) {
5112- // Re-attach window to generate sprite
5113- bool async;
5114- windows.GetWindow (dst).Refresh (async);
5115- }
5116- else if (!dst_pic.data .name .empty ()) {
5117- if (!dst_pic.sprite ) dst_pic.CreateSprite ();
5118- if (src_bmp) {
5119- dst_pic.sprite ->SetBitmap (src_bmp);
5120- dst_pic.sprite ->OnPictureShow ();
5121- dst_pic.sprite ->SetVisible (true );
5122- }
5123- }
5124- else {
5125- dst_pic.sprite .reset ();
5126- }
5127- };
5128-
5129- // Helper to swap two pictures
5130- auto swap_picture = [&](int id1, int id2) {
5131- // Ensure existence in vectors to avoid reference invalidation during assignments
5132- int max_id = std::max (id1, id2);
5133- pictures.GetPicture (max_id);
5134- windows.GetWindow (max_id);
5135-
5136- auto & p1 = pictures.GetPicture (id1);
5137- auto & p2 = pictures.GetPicture (id2);
5138-
5139- // Swap Window Data
5140- auto & w1 = windows.GetWindow (id1);
5141- auto & w2 = windows.GetWindow (id2);
5142- std::swap (w1.data , w2.data );
5143- w1.data .ID = id1;
5144- w2.data .ID = id2;
5145-
5146- // Swap Picture Data
5147- BitmapRef b1 = p1.sprite ? p1.sprite ->GetBitmap () : nullptr ;
5148- BitmapRef b2 = p2.sprite ? p2.sprite ->GetBitmap () : nullptr ;
5149-
5150- using std::swap;
5151- swap (p1.data , p2.data );
5152- swap (p1.request_id , p2.request_id );
5153-
5154- p1.data .ID = id1;
5155- p2.data .ID = id2;
5156-
5157- // Refresh Sprites Helper
5158- auto refresh = [&](Game_Pictures::Picture& p, BitmapRef bmp) {
5159- if (p.IsWindowAttached ()) {
5160- bool async;
5161- windows.GetWindow (p.data .ID ).Refresh (async);
5162- }
5163- else if (!p.data .name .empty ()) {
5164- if (!p.sprite ) p.CreateSprite ();
5165- if (bmp) {
5166- p.sprite ->SetBitmap (bmp);
5167- p.sprite ->OnPictureShow ();
5168- p.sprite ->SetVisible (true );
5169- }
5170- }
5171- else {
5172- p.sprite .reset ();
5173- }
5174- };
5175-
5176- refresh (p1, b2);
5177- refresh (p2, b1);
5178- };
5179-
51805068 if (operation == 0 || operation == 2 ) {
51815069 // Move (0) or Slide (2)
51825070 int target2 = (operation == 0 ) ? arg3 : (target1 + arg3);
@@ -5220,7 +5108,7 @@ bool Game_Interpreter::CommandManiacChangePictureId(lcf::rpg::EventCommand const
52205108 }
52215109
52225110 if (src_id != dst_id) {
5223- move_picture (src_id, dst_id);
5111+ pictures. MovePictureId (src_id, dst_id);
52245112 }
52255113 }
52265114 }
@@ -5245,7 +5133,7 @@ bool Game_Interpreter::CommandManiacChangePictureId(lcf::rpg::EventCommand const
52455133 }
52465134
52475135 if (valid1 && valid2) {
5248- swap_picture (id1, id2);
5136+ pictures. SwapPictureId (id1, id2);
52495137 }
52505138 else if (valid1 && !valid2) {
52515139 // Valid swap with invalid -> erase valid
0 commit comments