Module:Sandbox/Simonlc/Playfield

From TetrisWiki
Revision as of 03:16, 22 November 2020 by Simonlc (talk | contribs)
Jump to navigation Jump to search

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 playfield = {
    '<table style="line-height: 10px; 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()] .. '|12px]]')
    end
    table.insert(playfield, '</div>')
  end
  table.insert(playfield, '</td></tr></table>')

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