?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. -- GBA 16x16 table
  2.  
  3. function main ()
  4.  if mappy.msgBox ("GBA 16x16 table", "This will export the BG table and flip info of an 8x8 map made by 'Convert 16x16 blocks to 8x8' (as detailed in GBAMappy)\n\nRun the script (you will be prompted for a filename to save as)?", mappy.MMB_OKCANCEL, mappy.MMB_ICONQUESTION) == mappy.MMB_OK then
  5.  
  6.   local w = mappy.getValue(mappy.MAPWIDTH)
  7.   local h = mappy.getValue(mappy.MAPHEIGHT)
  8.  
  9.   if (w == 0) then
  10.    mappy.msgBox ("GBA 16x16 table", "You need to load or create a map first", mappy.MMB_OK, mappy.MMB_ICONINFO)
  11.   else
  12.  
  13.    local isok,asname = mappy.fileRequester (".", "Textfiles (*.txt)", "*.txt", mappy.MMB_SAVE)
  14.    if isok == mappy.MMB_OK then
  15.  
  16.     if (not (string.sub (string.lower (asname), -4) == ".txt")) then
  17.      asname = asname .. ".txt"
  18.     end
  19.  
  20.     outas = io.open (asname, "w")
  21.     outas:write ("const unsigned short tilelookup[] = {\n");
  22.     local blk = 0
  23.     local maxblk = mappy.getValue (mappy.NUMBLOCKSTR)
  24.     while blk < maxblk do
  25.      local blkval = mappy.getBlockValue (blk, mappy.BLKBG)
  26.      if mappy.getBlockValue (blk, mappy.BLKFLAG7) == 1 then
  27.       blkval = blkval + 1024
  28.      end
  29.      if mappy.getBlockValue (blk, mappy.BLKFLAG8) == 1 then
  30.       blkval = blkval + 2048
  31.      end
  32.      if blk == (maxblk-1) then
  33.       outas:write (blkval)
  34.      else
  35.       outas:write (blkval..",")
  36.       if (mappy.andVal (blk, 15) == 15) then
  37.        outas:write ("\n")
  38.       end
  39.      end
  40.      blk = blk + 1
  41.     end
  42.     outas:write ("\n};\n")
  43.     outas:close ()
  44.  
  45.    end
  46.   end
  47.  end
  48. end
  49.  
  50. test, errormsg = pcall( main )
  51. if not test then
  52.     mappy.msgBox("Error ...", errormsg, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
  53. end
  54.