?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. -- Example smooth edges Placer script
  2. -- called when the mouse moves and a button pressed that is set to Placer.lua
  3. -- Stretch the Block Window so the blocks are aligned as detailed in the
  4. -- Auto smooth guide in the docs
  5.  
  6. edgetab = {
  7. 0, 0, 1, 1, 0, 0, 1, 1, -1, -1, 0, 0, -1, -1, 0, 0
  8. }
  9. invcorners = {
  10. 2, 3, 3, 2
  11. }
  12. rowlimits = {
  13. -1, 3, -1, 3, -1, 3
  14. }
  15. towrite = {
  16. 0, 0, 0, 0, 0, 0, 0, 0, 0
  17. }
  18.  
  19. function outlimit (blknum)
  20.  if (blknum < 0) then return -1 end
  21.  if (blknum < rowlimits[1] or (blknum > rowlimits[2] and blknum < rowlimits[3])) then return -1 end
  22.  if ((blknum > rowlimits[4] and blknum < rowlimits[5])) then return -1 end
  23.  if (blknum > rowlimits[6]) then return -1 end
  24.  return 0
  25. end
  26.  
  27. function edges (bx, by, blk)
  28.  local edgenum = 0
  29.  if outlimit(mappy.getBlock (bx, by-1)) == -1 then edgenum = edgenum + 1 end
  30.  if outlimit(mappy.getBlock (bx+1, by)) == -1 then edgenum = edgenum + 2 end
  31.  if outlimit(mappy.getBlock (bx, by+1)) == -1 then edgenum = edgenum + 4 end
  32.  if outlimit(mappy.getBlock (bx-1, by)) == -1 then edgenum = edgenum + 8 end
  33.  
  34. -- sort inverse corners
  35. if edgetab[edgenum+1] == 0 then
  36.   if outlimit(mappy.getBlock (bx+1, by+1)) == -1 then return invcorners[1] end
  37.   if outlimit(mappy.getBlock (bx-1, by+1)) == -1 then return invcorners[2] end
  38.   if outlimit(mappy.getBlock (bx-1, by-1)) == -1 then return invcorners[3] end
  39.   if outlimit(mappy.getBlock (bx+1, by-1)) == -1 then return invcorners[4] end
  40. end
  41.  
  42. return edgetab[edgenum+1]
  43. end
  44.  
  45. function main ()
  46. -- mappy.BLOCKSPERROW added in V1.4.22, if using with an earlier version, set
  47. --blocksperrow = 20
  48. -- or correct value for your graphics
  49. blocksperrow = mappy.getValue (mappy.BLOCKSPERROW)
  50. if blocksperrow < 5 then blocksperrow = 20 end
  51.  
  52. local x = mappy.getValue (mappy.MOUSEBLOCKX)
  53. local y = mappy.getValue (mappy.MOUSEBLOCKY)
  54.  
  55. local blk = mappy.getValue (mappy.CURANIM)
  56. if (blk == -1) then
  57.   blk = mappy.getValue (mappy.CURBLOCK)
  58. else
  59. -- setBlock need anims in the format below (ie: anim 1 should be a value of -2)
  60.   blk = -(blk+1)
  61. end
  62.  
  63. -- correct edgetab, invcorners and rowlimits
  64. edgetab[2] = edgetab[2] - blocksperrow
  65. edgetab[4] = edgetab[4] - blocksperrow
  66. edgetab[5] = edgetab[5] + blocksperrow
  67. edgetab[7] = edgetab[7] + blocksperrow
  68. edgetab[10] = edgetab[10] - blocksperrow
  69. edgetab[12] = edgetab[12] - blocksperrow
  70. edgetab[13] = edgetab[13] + blocksperrow
  71. edgetab[15] = edgetab[15] + blocksperrow
  72. invcorners[1] = invcorners[1] - blocksperrow
  73. invcorners[2] = invcorners[2] - blocksperrow
  74. rowlimits[1] = (rowlimits[1] - blocksperrow) + blk
  75. rowlimits[2] = (rowlimits[2] - blocksperrow) + blk
  76. rowlimits[3] = (rowlimits[3]) + blk
  77. rowlimits[4] = (rowlimits[4]) + blk
  78. rowlimits[5] = (rowlimits[5] + blocksperrow) + blk
  79. rowlimits[6] = (rowlimits[6] + blocksperrow) + blk
  80.  
  81. -- Place a '+' of blocks at current position
  82. towrite[5] = blk
  83. mappy.setBlock (x-1, y-1, blk)
  84. mappy.setBlock (x, y-1, blk)
  85. mappy.setBlock (x+1, y-1, blk)
  86. mappy.setBlock (x-1, y, blk)
  87. mappy.setBlock (x, y, blk)
  88. mappy.setBlock (x+1, y, blk)
  89. mappy.setBlock (x-1, y+1, blk)
  90. mappy.setBlock (x, y+1, blk)
  91. mappy.setBlock (x+1, y+1, blk)
  92.  
  93. -- sort edges before writing
  94. towrite[1] = edges (x-1, y-1, blk)
  95. towrite[2] = edges (x, y-1, blk)
  96. towrite[3] = edges (x+1, y-1, blk)
  97. towrite[4] = edges (x-1, y, blk)
  98. towrite[6] = edges (x+1, y, blk)
  99. towrite[7] = edges (x-1, y+1, blk)
  100. towrite[8] = edges (x, y+1, blk)
  101. towrite[9] = edges (x+1, y+1, blk)
  102.  
  103. -- write edges
  104. mappy.setBlock (x-1, y-1, blk+towrite[1])
  105. mappy.setBlock (x, y-1, blk+towrite[2])
  106. mappy.setBlock (x+1, y-1, blk+towrite[3])
  107. mappy.setBlock (x-1, y, blk+towrite[4])
  108. mappy.setBlock (x+1, y, blk+towrite[6])
  109. mappy.setBlock (x-1, y+1, blk+towrite[7])
  110. mappy.setBlock (x, y+1, blk+towrite[8])
  111. mappy.setBlock (x+1, y+1, blk+towrite[9])
  112. end
  113.  
  114. test, errormsg = pcall( main )
  115. if not test then
  116.     mappy.msgBox("Error ...", errormsg, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
  117. end
  118.