Module:Sandbox/Simonlc/Playfield: Difference between revisions

From TetrisWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 2: Line 2:
local themes = {
local themes = {
   sega = {
   sega = {
     [" "] = "Tet.png", -- Blank
     [" "] = "Blank_Sega_mino.svg", -- Blank
     ["."] = "Tet.png",
     ["."] = "Blank_Sega_mino.svg",
     ["T"] = "T_Sega_mino.svg",
     ["T"] = "T_Sega_mino.svg",
     ["I"] = "I_Sega_mino.svg",
     ["I"] = "I_Sega_mino.svg",
Line 70: Line 70:
     table.insert(playfield, '<div>')
     table.insert(playfield, '<div>')
     for cell=1, #rows[row] do
     for cell=1, #rows[row] do
       table.insert(playfield, '[[Image:' .. themes[theme][string.sub(rows[row], cell, cell):upper()] .. '|' .. size .. 'px]]')
       local image = '[[Image:' .. themes[theme][string.sub(rows[row], cell, cell):upper()] .. '|' .. size .. 'px|link=]]'
      table.insert(playfield, image)
     end
     end
     table.insert(playfield, '</div>')
     table.insert(playfield, '</div>')

Latest revision as of 07:22, 5 December 2020

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

local imgRoot = "/images/";
local themes = {
  sega = {
    [" "] = "Blank_Sega_mino.svg", -- Blank
    ["."] = "Blank_Sega_mino.svg",
    ["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"] = "G_Sega_mino.svg", -- 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",
  },
  flat = {
    [" "] = "Blank_Flat_mino.svg", -- Blank
    ["."] = "Blank_Flat_mino.svg",
    ["T"] = "T_Flat_mino.svg",
    ["I"] = "I_Flat_mino.svg",
    ["O"] = "O_Flat_mino.svg",
    ["Z"] = "Z_Flat_mino.svg",
    ["S"] = "S_Flat_mino.svg",
    ["L"] = "L_Flat_mino.svg",
    ["J"] = "J_Flat_mino.svg",
    ["G"] = "G_Flat_mino.svg", -- garbage
    ["-"] = "-_Flat_mino.svg", -- 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 frameless = frame.args.frameless or false
  local theme = frame.args.theme or 'flat'

  local playfield = {
    '<table style="line-height: 0; font-size: 0;' .. (frameless and ' border-collapse: collapse;' or ' border: 1px solid #999;') .. '">\n<tr><td style="padding: 0;">'
  }

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

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