Module:Sandbox/Simonlc/Playfield: Difference between revisions

From TetrisWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 34: Line 34:


   local playfield = {
   local playfield = {
     '<table style="line-height: 10px; font-size: 0; border: 1px solid #999">\n<tr><td>'
     '<table style="line-height: 0; font-size: 0; border: 1px solid #999">\n<tr><td>'
   }
   }



Revision as of 06:08, 22 November 2020

Documentation for this module may be created at Module:Sandbox/Simonlc/Playfield/doc

local imgRoot = "/images/";
local graphicTable = {
    [" "] = "Tet.png", -- Blank
    ["."] = "Tet.png",
    ["T"] = "T_Sega_mino.svg",
    ["I"] = "I_Sega_mino.svg",
    ["O"] = "O_Sega_mino.svg",
    ["Z"] = "Z_Sega_mino.svg",
    ["S"] = "S_Sega_mino.svg",
    ["L"] = "L_Sega_mino.svg",
    ["J"] = "J_Sega_mino.svg",
    ["G"] = "GTet.png", -- garbage
    ["-"] = "-Tet.png", -- Line clear effect
    ["X"] = "XTet.png",
    ["B"] = "BTet.png",
    ["C"] = "CTet.png",
    ["P"] = "PTet.png",
    ["1"] = "1Tet.png",
    ["2"] = "2Tet.png",
    ["3"] = "3Tet.png",
    ["4"] = "4Tet.png",
    ["5"] = "5Tet.png",
    ["6"] = "6Tet.png",
    ["7"] = "7Tet.png",
    ["8"] = "8Tet.png",
    ["9"] = "9Tet.png",
};

local p = {}
function p.main(frame)
  local input = frame.args[1]
  local rows = mw.text.split(input, '\n' )
  local size = frame.args.size or 12

  local playfield = {
    '<table style="line-height: 0; font-size: 0; border: 1px solid #999">\n<tr><td>'
  }

  for row=1, #rows do
    table.insert(playfield, '<div>')
    for cell=1, #rows[row] do
      table.insert(playfield, '[[Image:' .. graphicTable[string.sub(rows[row], cell, cell):upper()] .. '|' .. size .. 'px]]')
    end
    table.insert(playfield, '</div>')
  end
  table.insert(playfield, '</td></tr></table>')

  return table.concat(playfield, '\n')
end
return p