The Alchemist Code Wiki

READ MORE

The Alchemist Code Wiki
The Alchemist Code Wiki

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

local render_item_icon   = require('Module:Render/Item')._icon
local model   = require('Module:Data').model

local p = {}

function p.table(frame)
  local args = require('Module:Arguments').getArgs(frame, {
    parentFirst = true,
    wrappers = {
      'Template:Recipe/Table',
    }
  })
  return p._table(args)
end

function p._table(args)
  local iname = args[1]
  local data = model.query('Recipe','cost,counts,mats',{where=(args.server and ('server="'..args.server..'" and ') or '')..'iname="'..iname..'"'})
  data = data[1] or {cost='???',counts={},mats={}}
  
  local root = mw.html.create()
  
  local renderList = function(t, cost, mats, counts)
    local row = t:tag('tr')
    row
      :tag('td')
        :tag('span')
          :cssText('background: darkgray; color: white; border-radius: 6px; padding: 4px')
          :wikitext(cost .. ' Zeni')
    local icons = mw.html.create('div'):cssText('display:flex; flex-wrap:wrap')
    for i, mat in ipairs(mats) do
      icons:wikitext(render_item_icon({mat, count=counts[i]}))
    end
    row:tag('td'):node(icons)
  end
  
  local tbl = root:tag('table')
  tbl:tag('tr')
    :tag('th'):cssText('background:lightgrey'):wikitext('Zeni'):done()
    :tag('th'):cssText('background:lightgrey'):wikitext('Materials'):done()
  renderList(tbl, data.cost, data.mats, data.counts)
  
  -- TODO From raw materials
  --table.insert(sb, '\n|-\n! colspan="2" style="background: lightgray" | From all raw materials')
  --renderList(data.cost, data.mats, data.counts)

--[=[
{{#vardefine: x|{{:Data:Recipe/CostTotal|{{{1|}}}}}}}{{#if: {{#var:x}}| 
{{!}}-
! colspan="2" style="background: lightgray" {{!}} From all raw materials
{{!}}-
{{!}} <span style="background: darkgray; color: white; border-radius: 6px; padding: 4px">{{#var: x}}&nbsp;Zeni</span>
{{!}} {{Item/List|{{:Data:Recipe/MatsTotal|{{{1|}}}}}|{{:Data:Recipe/CountsTotal|{{{1|}}}}}}}
}}
--]=]
  
  return tostring(root)
end

return p