Difference between revisions of "Module:HalidomMap"

From Dragalia Lost Wiki
Jump to navigation Jump to search
imported>Elaeagnifolia
imported>Elaeagnifolia
(No difference)

Revision as of 11:44, 26 October 2018

Documentation for this module may be created at Module:HalidomMap/doc

local p = {}

function split(str,pat)
   local tbl = {}
   str:gsub(pat, function(x) tbl[#tbl+1]=x end)
   return tbl
end

p._halidomMap = function (args)
  local tbl = mw.html.create('table'):css('text-align', 'center')

  for idx, row in ipairs(args) do
    local tr = tbl:tag('tr')
    local cellValues = split(row, ",")
    for idx2, cellValue in ipairs(cellValues) do
      local td = tr:tag('td')
        :css('width', '15px')
        :css('height', '15px')
        :css('background-color', getCellColor(cellValue))
    end
    --local td = tr:tag('td'):wikitext(row)
  end

  return tostring(tbl)
end

--- Function that converts months from text to numbers
-- @param n
-- @return The numerical value of the month provided
function getCellColor(value)
  local halidomValueToColor = {
    ["255"] = "#fff",
    ["0"] = "#000",
    ["1"] = "red",
    ["2"] = "orange",
    ["3"] = "yellow",
    ["4"] = "greenyellow",
    ["5"] = "green",
    ["6"] = "turquoise",
    ["7"] = "blue",
    ["8"] = "purple",
    ["9"] = "brown",
    ["10"] = "#808080",
    ["11"] = "#808080",
    ["101"] = "lightpink",
    ["102"] = "lightsalmon",
    ["103"] = "lightyellow",
    ["104"] = "#e0ffb3",
    ["105"] = "lightgreen",
    ["106"] = "#ccfeff",
    ["107"] = "lightblue",
    ["108"] = "#ffb3ff",
    ["109"] = "burlywood",
    ["110"] = "#d3d3d3",
    ["111"] = "#d3d3d3"
  }
  if halidomValueToColor[value] ~= nil then
    return halidomValueToColor[value]
  end
  return value
end

p.halidomMap = function (frame)
  local getArgs = require 'Module:Arguments'.getArgs
  return p._halidomMap(getArgs(frame, {wrappers = 'Template:HalidomMap'}))
end

return p