?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. -- Merge layers
  2. -- Merges ayer l1 and layer l2 to layer l3
  3.  
  4. function main ()
  5.  local w = mappy.getValue(mappy.MAPWIDTH)
  6.  local h = mappy.getValue(mappy.MAPHEIGHT)
  7.  
  8.  if (w == 0) then
  9.   mappy.msgBox ("Merge layers", "You need to load or create a map first", mappy.MMB_OK, mappy.MMB_ICONINFO)
  10.  else
  11.  
  12.   mappy.msgBox ("Merge layers", "Merges two layers, in the next dialogue enter the source layers and the destination layer separated by commas. All layers must exist, the destination can be one of the source layers. Highest block number is used. You can undo this operation with ctrl+z if destination is current layer.", mappy.MMB_OK, mappy.MMB_ICONINFO)
  13.   local isok,l1,l2,l3 = mappy.doDialogue ("Merge layers", "Enter layer1,layer2,destlayer", "0,1,0", mappy.MMB_DIALOGUE2)
  14.   if isok == mappy.MMB_OK then
  15.  
  16.    l1 = tonumber (l1)
  17.    l2 = tonumber (l2)
  18.    l3 = tonumber (l3)
  19.  
  20.    mappy.copyLayer(mappy.getValue(mappy.CURLAYER),mappy.MPY_UNDO)
  21.  
  22.    local y = 0
  23.    while y < h do
  24.     local x = 0
  25.     while x < w do
  26.      local b1 = mappy.getBlock (x, y, l1)
  27.      local b2 = mappy.getBlock (x, y, l2)
  28.      if b2 > b1 and b2 ~= 0 then
  29.       b1 = b2
  30.      end
  31.      mappy.setBlock (x, y, b1, l3)
  32.      x = x + 1
  33.     end
  34.     y = y + 1
  35.    end
  36.  
  37.    mappy.updateScreen()
  38.  
  39.   end
  40.  end
  41. end
  42.  
  43. test, errormsg = pcall( main )
  44. if not test then
  45.     mappy.msgBox("Error ...", errormsg, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
  46. end
  47.