Module:Sandbox/Simonlc/Playfield: Difference between revisions

From TetrisWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 45: Line 45:
     table.insert(playfield, '<div>')
     table.insert(playfield, '<div>')
     for cell=1, #rows[row] do
     for cell=1, #rows[row] do
       table.insert(playfield, '<img src="' .. imgRoot .. tetrisTable[string.sub(rows[row], 1, 1):upper()] .. '" alt="">')
       table.insert(playfield, '<img src="' .. imgRoot .. graphicTable[string.sub(rows[row], 1, 1):upper()] .. '" alt="">')
     end
     end
     table.insert(playfield, '</div>')
     table.insert(playfield, '</div>')

Revision as of 01:19, 22 November 2020

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

local imgRoot = "/images/";
local graphicTable = {
    [" "] = "1/18/Tet.png", -- Blank
    ["."] = "1/18/Tet.png",

    -- Pieces
    ["T"] = "2/20/TTet.png",
    ["I"] = "1/19/ITet.png",
    ["O"] = "2/20/OTet.png",
    ["Z"] = "c/c6/ZTet.png",
    ["S"] = "b/bc/STet.png",
    ["L"] = "5/51/LTet.png",
    ["J"] = "8/85/JTet.png",
    ["G"] = "8/88/GTet.png", -- garbage

    -- Line clear effect
    ["-"] = "3/38/-Tet.png",

    ["X"] = "0/04/XTet.png",
    ["B"] = "6/6d/BTet.png",
    ["C"] = "4/42/CTet.png",
    ["P"] = "9/9a/PTet.png",

    ["1"] = "9/9f/1Tet.png",
    ["2"] = "4/4f/2Tet.png",
    ["3"] = "0/08/3Tet.png",
    ["4"] = "0/0d/4Tet.png",
    ["5"] = "9/93/5Tet.png",
    ["6"] = "e/e7/6Tet.png",
    ["7"] = "c/cd/7Tet.png",
    ["8"] = "e/e6/8Tet.png",
    ["9"] = "c/c8/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, '<img src="' .. imgRoot .. graphicTable[string.sub(rows[row], 1, 1):upper()] .. '" alt="">')
    end
    table.insert(playfield, '</div>')
  end
  table.insert(playfield, '</td></tr></table>')

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