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, '[[Image:' .. graphicTable[string.sub(rows[row], cell, cell+1):upper()] .. ']]')
       table.insert(playfield, '[[Image:' .. graphicTable[string.sub(rows[row], cell, cell):upper()] .. ']]')
     end
     end
     table.insert(playfield, '</div>')
     table.insert(playfield, '</div>')

Revision as of 01:37, 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",

    -- Pieces
    ["T"] = "TTet.png",
    ["I"] = "ITet.png",
    ["O"] = "OTet.png",
    ["Z"] = "ZTet.png",
    ["S"] = "STet.png",
    ["L"] = "LTet.png",
    ["J"] = "JTet.png",
    ["G"] = "GTet.png", -- garbage

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

    ["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()] .. ']]')
    end
    table.insert(playfield, '</div>')
  end
  table.insert(playfield, '</td></tr></table>')

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