fixed level editor copy/paste using Ctrl-c/v for custom/group/DF elements
authorHolger Schemel <info@artsoft.org>
Wed, 27 Feb 2019 21:02:12 +0000 (22:02 +0100)
committerHolger Schemel <info@artsoft.org>
Wed, 27 Feb 2019 21:14:11 +0000 (22:14 +0100)
Before, all custom/group elements were mapped to first custom/group
element when copying them to the clipboard (as this was fine for level
sketches, which do not use any custom artwork anyway), but of course
this breaks copying level playfields in the level editor.

This bug was fixed (which will require updating/extending the level
sketch images for the R'n'D web forum).

Besides this, level sketches from level playfields that contain game
elements with a higher element number than 999 are changed to use a
format of always four digits for all game elements (which will also
require updating/extending the level sketch images for the forum).

Last but not least, while level sketches with four-digit element
number were already created, they were not parsed correctly when
reading them back from the clipboard, which was fixed, too.

src/editor.c

index 5eed006605c50a65ef0d33629739fe6e5018f797..bb2f43b55681e4c2031eb281fb6fad03778a17c7 100644 (file)
@@ -11996,27 +11996,28 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
     char text[MAX_CB_TEXT_SIZE + 1] = "";
     int width  = (draw_with_brush ? brush_width  : lev_fieldx);
     int height = (draw_with_brush ? brush_height : lev_fieldy);
     char text[MAX_CB_TEXT_SIZE + 1] = "";
     int width  = (draw_with_brush ? brush_width  : lev_fieldx);
     int height = (draw_with_brush ? brush_height : lev_fieldy);
+    char *format = "%s%03d";
+
+    for (y = 0; y < height; y++)
+      for (x = 0; x < width; x++)
+       if ((draw_with_brush ? brush_buffer[x][y] : Feld[x][y]) > 999)
+         format = "%s%04d";
 
     for (y = 0; y < height; y++)
     {
       for (x = 0; x < width; x++)
       {
        int element = (draw_with_brush ? brush_buffer[x][y] : Feld[x][y]);
 
     for (y = 0; y < height; y++)
     {
       for (x = 0; x < width; x++)
       {
        int element = (draw_with_brush ? brush_buffer[x][y] : Feld[x][y]);
-       int element_mapped = element;
        char *prefix = (mode == CB_DUMP_BRUSH ||
                        mode == CB_BRUSH_TO_CLIPBOARD ? "`" : "¸");
 
        char *prefix = (mode == CB_DUMP_BRUSH ||
                        mode == CB_BRUSH_TO_CLIPBOARD ? "`" : "¸");
 
-       if (IS_CUSTOM_ELEMENT(element))
-         element_mapped = EL_CUSTOM_START;
-       else if (IS_GROUP_ELEMENT(element))
-         element_mapped = EL_GROUP_START;
-       else if (element >= NUM_FILE_ELEMENTS)
-         element_mapped = EL_UNKNOWN;
+       if (element >= NUM_FILE_ELEMENTS)
+         element = EL_UNKNOWN;
 
        // copy brush to level sketch text buffer for the R'n'D forum:
 
        // copy brush to level sketch text buffer for the R'n'D forum:
-       // - large tiles: `xxx (0x60 ASCII)
-       // - small tiles: ¸xxx (0xb8 ISO-8859-1, 0xc2b8 UTF-8)
-       snprintf(part, MAX_CB_PART_SIZE + 1, "%s%03d", prefix, element_mapped);
+       // - large tiles: `xxx or `xxxx (0x60 ASCII)
+       // - small tiles: ¸xxx or ¸xxxx (0xb8 ISO-8859-1, 0xc2b8 UTF-8)
+       snprintf(part, MAX_CB_PART_SIZE + 1, format, prefix, element);
        strcat(text, part);
       }
 
        strcat(text, part);
       }
 
@@ -12098,7 +12099,7 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
        }
       }
 
        }
       }
 
-      // check if prefix found and followed by three numbers
+      // check if prefix found and followed by (at least) three digits
       if (prefix_found &&
          strlen(ptr) >= 3 &&
          ptr[0] >= '0' && ptr[0] <= '9' &&
       if (prefix_found &&
          strlen(ptr) >= 3 &&
          ptr[0] >= '0' && ptr[0] <= '9' &&
@@ -12111,6 +12112,13 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
 
        ptr += 3;
 
 
        ptr += 3;
 
+       // level sketch element number might consist of four digits
+       if (ptr[0] >= '0' && ptr[0] <= '9')
+       {
+         element = element * 10 + (ptr[0] - '0');
+         ptr++;
+       }
+
        if (element >= NUM_FILE_ELEMENTS)
          element = EL_UNKNOWN;
 
        if (element >= NUM_FILE_ELEMENTS)
          element = EL_UNKNOWN;