Module:UnitSkins

local model = require('Module:Data').model

local p = {}

local skinDirList = {'UnitImages', 'UnitImages2', 'PortraitsM', 'Portraits', 'UnitEyeImages'}

local getUnitData = function(iname) return model.query("Unit", 'skins,img,mdl', {where = 'iname="'..iname..'" and server = "gl"'})[1] or {} end

local getUnitSkinArtifacts = function(img) return model.query("Artifact", '_pageName,asset,iname', {where = '(iname LIKE "AF_SKIN_'..string.upper(img)..'%" or iname LIKE "AF_SK_'..string.upper(img)..'%") and asset != "unique" and server = "gl"'}) or {} end

function p._unitSkinList(iname) if iname == nil then return 'Invalid parameter' end

local unitData = getUnitData(iname) local output = {} if unitData.img then local customSkins = false table.insert(output, "==Skins==\n") local skinList = {} skinList['Default Skin'] = {img = unitData.img} local skinSourceList = mw.loadData("Module:Data/Extra/Skin") unitSkinArtifacts = getUnitSkinArtifacts(unitData.img) for ignore, tempSkinData in pairs(unitSkinArtifacts) do           local skinName = model.getLoc(tempSkinData._pageName, 'name') skinList[skinName] = { img = (unitData.img..'_'..tempSkinData.asset) } if skinSourceList[tempSkinData.iname] and skinSourceList[tempSkinData.iname]['source'] then skinList[skinName]['source'] = skinSourceList[tempSkinData.iname]['source'] end customSkins = true end for skinDesc, skinData in pairs(skinList) do           table.insert(output, '==='..skinDesc.."===\n") if skinData['source'] and skinData['source'] ~= '' then table.insert(output, "Source: "..skinData['source'].."\n\n") end for i, tempSkinDir in pairs(skinDirList) do               table.insert(output, ' ') end table.insert(output, "\n") end -- TODO: demospace. if mw.title.getCurrentTitle.namespace == 0 then if customSkins then table.insert(output, '') end end end return table.concat(output) end

return p