?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. -- Export Flash actionscript
  2. -- Thanks to Andre Michelle for the idea
  3.  
  4.  
  5. function main ()
  6.  if mappy.msgBox ("Export Flash actionscript", "This will export the current layer as an actionscript (anims are replaced with block 0)\n\nRun the script (you will be prompted for a filename to save as)?", mappy.MMB_OKCANCEL, mappy.MMB_ICONQUESTION) == mappy.MMB_OK then
  7.  
  8.   local w = mappy.getValue(mappy.MAPWIDTH)
  9.   local h = mappy.getValue(mappy.MAPHEIGHT)
  10.  
  11.   if (w == 0) then
  12.    mappy.msgBox ("Export Flash actionscript", "You need to load or create a map first", mappy.MMB_OK, mappy.MMB_ICONINFO)
  13.   else
  14.  
  15.    local isok,asname = mappy.fileRequester (".", "Flash actionscript (*.as)", "*.as", mappy.MMB_SAVE)
  16.    if isok == mappy.MMB_OK then
  17.  
  18.     if (not (string.sub (string.lower (asname), -3) == ".as")) then
  19.      asname = asname .. ".as"
  20.     end
  21.  
  22.     local isok,adjust = mappy.doDialogue ("Export Flash actionscript", "Adjust exported values by:", "0", mappy.MMB_DIALOGUE1)
  23.     if isok == mappy.MMB_OK then
  24.  
  25.      adjust = tonumber (adjust)
  26.      outas = io.open (asname, "w")
  27.      outas:write ("var map = [\n");
  28.      local y = 0
  29.      while y < h do
  30.       outas:write ("[")
  31.       local x = 0
  32.       while x < w do
  33.        local mapval = mappy.getBlockValue (mappy.getBlock (x, y), mappy.BLKBG)
  34.        mapval = mapval + adjust
  35.        if mapval < 0 then
  36.         mapval = 0
  37.        end
  38.        outas:write (tostring(mapval))
  39.        if x < (w-1) then
  40.         outas:write (",")
  41.        else
  42.         if y < (h-1) then
  43.          outas:write ("],\n")
  44.         else
  45.          outas:write ("]\n")
  46.          end
  47.        end
  48.       x = x + 1
  49.       end
  50.       y = y + 1
  51.      end
  52.      outas:write ("]\n")
  53.      outas:close ()
  54.  
  55.     end
  56.    end
  57.   end
  58.  end
  59. end
  60.  
  61. test, errormsg = pcall( main )
  62. if not test then
  63.     mappy.msgBox("Error ...", errormsg, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
  64. end
  65.