Module:NPC

--[=[-- Lua script to get NPC Detail

getNPC: get generic NPC infomation Parameters: 1: NPC = NPC name 2: Include Name/Text Link (Optional) N = NPC Name with image F = File Name E = NPC Name only L = NPC Name Link only X = NPC/Display Name with image D = Descriptive/Display Name (Text Only) T = Text Only NPC Name A = Alternate Text (Parameter 3) Z = File Name ONLY 3: Alternate Text (Optional) 4: Size in pixels (Optional) default 25 5: Event Version (Optional) -- The list of available NPCs is kept in the module data -- Unknown is returned if NPC is not in data.

getNPCList: get a List of NPC in horizontal format Parameters: None

getFirstUse: get the fixed format text about first LTE using the NPC Parameters: 1:	NPC Name --]=]--

local p = {}

local npcData = mw.loadData( 'Module:NPC/data' ) local util = require('Module:Utility')

function p.getNPC(frame) local tArgs = util.getArgs(frame) local keyName = tArgs[1] or "" local inclName = tArgs[2] or "" local altText = tArgs[3] or "" local size    = tArgs[4] or "" local version = string.lower(tArgs[5] or "")

if inclName ~= "" then if not inclName:match("^[NEATDXGLFZ]$") then inclName = "N" end end

if size == "" then size = "25" end

local outText = "" local tFile = "work_in_progress" local tSize = ".png|x" .. size .. "px|" local tDisp = keyName local tLink = "Work In Progress"

if npcData[keyName] then local npcItem = npcData[keyName] tFile = "npc-" .. string.lower(keyName) tSize = ".png|x" .. size .. "px|" tDisp = keyName tLink = keyName if npcItem["N"] then tLink = npcItem["N"] tDisp = tLink end if npcItem["D"] then tDisp = npcItem["D"] end

if npcItem["I"] then tFile = npcItem["I"] end if npcItem["L"] then tLink = npcItem["L"] end if inclName == "G" then version = npcItem["G"] end

if version ~= "" and npcItem["V"] and npcItem["V"][version] then local text = ""

text = npcItem["V"][version][2] if text and text ~= "" then tLink = "Gold Coins" else tLink = keyName end text = npcItem["V"][version][1] if inclName == "F" then if npcItem["V"][version][4] and npcItem["V"][version][4] ~= "" then tDisp = npcItem["V"][version][4] else tDisp = ":Category:" .. text .. "|" .. text end elseif text and text ~= "" then tDisp = text .. " themed " .. tLink end

if text and text == "Disney Magic Kingdoms" then tFile = "npc-" .. string.lower(tLink) else tFile = "npc-" .. string.lower(tLink) .. "-" .. (npcItem["V"][version][3] or version) end end end

local nameLink = "" local bracket = ""

if inclName == "N" then nameLink = "" .. tLink .. " ("       bracket = ")" elseif inclName == "L" then nameLink = "" .. tDisp       end        nameLink = nameLink .. "" elseif inclName == "X" then nameLink = "" .. tDisp       end        nameLink = nameLink .. " ("        bracket = ")" elseif inclName == "A" then nameLink = "" .. altText       end        nameLink = nameLink .. " ("        bracket = ")" elseif inclName == "E" then nameLink = tLink elseif inclName == "T" then nameLink = tLink .. " ("       bracket = ")" elseif inclName == "D" then nameLink = tDisp .. " ("       bracket = ")" elseif inclName == "F" then return tFile .. ".png|" .. tDisp .. " themed gold trophy\n" elseif inclName == "Z" then return tFile .. ".png" end

if inclName ~= "L" then if inclName ~= "E" then nameLink = nameLink .. ""       .. tFile .. tSize .. tDisp        .. "" .. bracket end end return nameLink end

function p.getEventNPC(frame) local tArgs = util.getArgs(frame) local eName = mw.ustring.lower(tArgs[1] or "") local eType = tArgs[2] or ""

local tIndex = {}

for npcName, v in pairs(npcData) do       if eType == "T" then if v["TC"] and v["TC"] == eName then table.insert(tIndex, {string.lower(npcName), npcName}) end elseif v["E"] and v["E"] == eName then table.insert(tIndex, {string.lower(npcName), npcName}) end end

table.sort(tIndex, function (a,b) return a[1] < b[1] end)

local outText = "" local space = ""

for _, name in ipairs(tIndex) do       outText = outText .. space .. "" .. name[2] .. " " space = " " end

return outText end

function p.getFirstUse(frame) local tArgs = util.getArgs(frame)

local npcName = tArgs[1] or "" npcName = npcName:gsub("^%s*(.-)%s*$", "%1") or ''

local outText = {}

if npcData[npcName] then local npcItem = npcData[npcName] -- assemble output string if LTE name present if npcData[npcName]["E"] then outText = { "* ",			   	npcItem["D"] or npcName,			    	" first appeared during the ", require("Module:LTEvent").getLTE({npcItem["E"], "N", "D"}), ".\n", }		end end return table.concat(outText) end

function p.hasTokens(npcName) return (npcData[npcName] and npcData[npcName].T) end

return p