Module:Sandbox/Simonlc/Playfield: Difference between revisions

From TetrisWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(33 intermediate revisions by the same user not shown)
Line 1: Line 1:
local imgRoot = "/images/";
local imgRoot = "/images/";
local graphicTable = {
local themes = {
     [" "] = "1/18/Tet.png", -- Blank
  sega = {
     ["."] = "1/18/Tet.png",
     [" "] = "Blank_Sega_mino.svg", -- Blank
 
     ["."] = "Blank_Sega_mino.svg",
     -- Pieces
    ["T"] = "T_Sega_mino.svg",
     ["T"] = "2/20/TTet.png",
    ["I"] = "I_Sega_mino.svg",
     ["I"] = "1/19/ITet.png",
    ["O"] = "O_Sega_mino.svg",
     ["O"] = "2/20/OTet.png",
    ["Z"] = "Z_Sega_mino.svg",
     ["Z"] = "c/c6/ZTet.png",
    ["S"] = "S_Sega_mino.svg",
     ["S"] = "b/bc/STet.png",
    ["L"] = "L_Sega_mino.svg",
     ["L"] = "5/51/LTet.png",
    ["J"] = "J_Sega_mino.svg",
     ["J"] = "8/85/JTet.png",
    ["G"] = "G_Sega_mino.svg", -- garbage
     ["G"] = "8/88/GTet.png", -- garbage
    ["-"] = "-Tet.png", -- Line clear effect
 
    ["X"] = "XTet.png",
     -- Line clear effect
     ["B"] = "BTet.png",
     ["-"] = "3/38/-Tet.png",
     ["C"] = "CTet.png",
 
     ["P"] = "PTet.png",
     ["X"] = "0/04/XTet.png",
    ["1"] = "1Tet.png",
     ["B"] = "6/6d/BTet.png",
     ["2"] = "2Tet.png",
     ["C"] = "4/42/CTet.png",
    ["3"] = "3Tet.png",
     ["P"] = "9/9a/PTet.png",
     ["4"] = "4Tet.png",
 
     ["5"] = "5Tet.png",
     ["1"] = "9/9f/1Tet.png",
     ["6"] = "6Tet.png",
     ["2"] = "4/4f/2Tet.png",
     ["7"] = "7Tet.png",
     ["3"] = "0/08/3Tet.png",
    ["8"] = "8Tet.png",
     ["4"] = "0/0d/4Tet.png",
     ["9"] = "9Tet.png",
     ["5"] = "9/93/5Tet.png",
  },
     ["6"] = "e/e7/6Tet.png",
  flat = {
     ["7"] = "c/cd/7Tet.png",
    [" "] = "Blank_Flat_mino.svg", -- Blank
     ["8"] = "e/e6/8Tet.png",
    ["."] = "Blank_Flat_mino.svg",
     ["9"] = "c/c8/9Tet.png",
    ["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 = {}
local p = {}
Line 37: Line 59:
   local input = frame.args[1]
   local input = frame.args[1]
   local rows = mw.text.split(input, '\n' )
   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 = {
   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;' .. (frameless and ' border-collapse: collapse;' or ' border: 1px solid #999;') .. '">\n<tr><td style="padding: 0;">'
   }
   }


Line 45: 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, '<img src="' .. imgRoot .. tetrisTable[rows[row][cell]:upper()] .. '" alt="">')
       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>')
Line 51: Line 77:
   table.insert(playfield, '</td></tr></table>')
   table.insert(playfield, '</td></tr></table>')


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

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