The Alchemist Code Wiki

READ MORE

The Alchemist Code Wiki
Register
Advertisement

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

local util_cargo = require('Module:CargoUtil')
local jobPageName = require('Module:Data/Extra/JobPageName')
local linkUtils = require('Module:LinkUtils')

local p = {}
local h = {}

function p.icon(frame)
    local args = require('Module:Arguments').getArgs(frame, {
        parentFirst = true,
        wrappers = {
            'Template:Job/Icon',
        }
    })
    return p._icon(args)
end

function p._icon(args)
  local iname = args[1]
  local jobpage = util_cargo.queryAndCast{
  	tables = 'Pages',
  	fields = 'iname',
  	where = 'type = "Job" AND _pageName = "' .. iname .. '" OR iname = "' .. iname .. '"',
  }[1]
  if jobpage then
  	iname = jobpage.iname
  end
  local data = args.data or util_cargo.queryAndCast{
  	tables='Job',
  	fields='_pageName,server,ac2d,mdl',
  	where='iname="'..iname..'"',
  	limit = 1,
  }[1] or {}

  local jobIconDir = (args['size'] == 'large' and 'JobIconM,') or 'JobIcon,'

  local icon = 'ItemIcon,IT_UNKNOWN'
  if data.ac2d and data.ac2d ~= '' then
    icon = jobIconDir..data.ac2d
  elseif data.mdl and data.mdl ~= '' then
    icon = jobIconDir..data.mdl
  end

  local name = h.getName(data._pageName)
  
  local link = nil
  if args['link'] ~= 'none' then
    if data._pageName ~= nil then
        link = (util_cargo.queryAndCast{tables='Pages',fields='_pageName',where='type="Job" and iname="'..iname..'"',limit=1}[1] or {_pageName = jobPageName[iname] or linkUtils.wikiSafeName(name)})._pageName or nil
    end
  end

  local displayName = args['name'] ~= 'none' and (name and name ~= '' and (link and '[['..link..'|'..name..']]') or name) or nil
  
  local size = (args['size'] == 'large' and 128) or (args['size'] == 'small' and 32) or 64

  local rarity = 0

  -- Generate the image
  local imageOutput = {}
  table.insert(imageOutput, '[[File:Game,'..icon..'.png|'..size..'px')
  if name and name ~= '' then
    table.insert(imageOutput,'|'..name)
    if link and link ~= '' then
        table.insert(imageOutput, '|link='..link)
    end
  end
  table.insert(imageOutput, ']]')
  
  -- Generate the container around the image
  local output = {}
  if args['size'] == 'small' then
    table.insert(output, table.concat(imageOutput))
    if displayName then
        table.insert(output, ' '..displayName)
    end
  else
    local iconBackground = 'x-'..rarity..' y-2'
    local classList = args['classes'] ~= nil and ' '..args['classes'] or ''
    if args['float'] ~= nil and args['float'] ~= '' then
        classList = classList..' float'..args['float']
    end
    
    table.insert(output, '<div class="item-icon'..classList..'" style="width: '..size..'px">'.."\n")
    table.insert(output, '<div class="img '..iconBackground..'">')
    table.insert(output, table.concat(imageOutput))
    table.insert(output, '</div>')
    if displayName then
        table.insert(output, "\n<div>"..displayName..'</div>')
    end
    table.insert(output, "\n</div>")
  end
  
  return table.concat(output)
end

-- Non cargo version
function p._icon2(args)
	local data = args.data or {}
	local iname = data.iname
	if not iname then return end

	local jobIconDir = args.size == 'large' and 'JobIconM,' or 'JobIcon,'

	local icon = 'ItemIcon,IT_UNKNOWN'
	if data.icon then
		icon = jobIconDir..data.icon
	end

  	local name = data.name
  
  	local link = nil
  	if args['link'] ~= 'none' then
		link = data._pageName or linkUtils.wikiSafeName(name) or nil
  	end

  	local displayName = args.name ~= 'none' and (name and name ~= '' and (link and '[['..link..'|'..name..']]') or name) or nil
  	local size = (args.size == 'large' and 128) or (args.size == 'small' and 32) or 64
	local rarity = 0

  	-- Generate the image
  	local imageOutput = {}
  	table.insert(imageOutput, '[[File:Game,'..icon..'.png|'..size..'px')
  	if name and name ~= '' then
		table.insert(imageOutput,'|'..name)
		if link and link ~= '' then
			table.insert(imageOutput, '|link='..link)
		end
	end
  	table.insert(imageOutput, ']]')
  
	-- Generate the container around the image
	local output = {}
	if args['size'] == 'small' then
		table.insert(output, table.concat(imageOutput))
		if displayName then
			table.insert(output, '&nbsp;'..displayName)
		end
	else
		local iconBackground = 'x-'..rarity..' y-2'
		local classList = args['classes'] ~= nil and ' '..args['classes'] or ''
		if args['float'] ~= nil and args.float ~= '' then
			classList = classList..' float'..args['float']
		end
		table.insert(output, '<div class="item-icon'..classList..'" style="width: '..size..'px">'.."\n")
		table.insert(output, '<div class="img '..iconBackground..'">')
		table.insert(output, table.concat(imageOutput))
		table.insert(output, '</div>')
		if displayName then
			table.insert(output, "\n<div>"..displayName..'</div>')
		end
		table.insert(output, "\n</div>")
	end
	return table.concat(output)
end

function p.pageName(frame)
    local args = require('Module:Arguments').getArgs(frame, {
        parentFirst = true,
        wrappers = {
            'Template:Job/Name',
        }
    })
    return p._pageName(args)
end

function p._pageName(args)
  local iname = args[1]
  local data = args.data or util_cargo.queryAndCast{tables='Job',fields='_pageName,server',where='iname="'..iname..'"'}[1] or {}

  local name = h.getName(data._pageName)
  
  local link = nil
  if data._pageName ~= nil then
    link = (util_cargo.queryAndCast{tables='Pages',fields='_pageName',where='type="Job" and iname="'..iname..'"'}[1] or {_pageName = jobPageName[iname] or linkUtils.wikiSafeName(name)})._pageName or nil
  end

  local displayName = (name and name ~= '' and (link and '[['..link..'|'..name..']]') or name) or iname
  
  return displayName
end

function h.getName(_pageName, lang)
	if _pageName == nil then return '???' end
	local rows = util_cargo.queryAndCast{
		tables = 'JobLoc',
		fields = 'name,lang',
		where = ('_pageName=%q AND name<>""'):format(_pageName)
	}
	local names = {}
	for i, row in ipairs(rows) do
		names[row.lang] = row.name
	end
	return names[lang] or names.english or names.japanese or ''
end

return p
Advertisement