Disney Magic Kingdoms Wiki

The Sword in the Stone Part 3 Update has arrived! ✨
Visit this page to learn all about what's coming up in Disney Magic Kingdoms!

READ MORE

Disney Magic Kingdoms Wiki
No edit summary
No edit summary
Line 71: Line 71:
 
tLink = npcItem["N"]
 
tLink = npcItem["N"]
 
tDisp = tLink
 
tDisp = tLink
  +
end
  +
  +
if npcItem["D"] then
  +
tDisp = npcItem["D"]
 
end
 
end
   

Revision as of 14:49, 9 May 2021

Description

This module is the Lua back-end for {{NPC}}, to display information about Non-Playable Characters.

Usage

{{#invoke:NPC|getNPC|<parameter list>}}

For parameter details see Template:NPC/doc

direct invokation
{{#invoke:NPC|getNPCList|<parameter list>}}
{{#invoke:NPC|getFirstUse|<parameter list>}}


--[=[--
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
		     D = Descriptive/Display Name (Text Only)
		     T = Text Only NPC Name
		     A = Alternate Text (Parameter 3)
		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
<nowiki>
--]=]--

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("^[NEATDGLF]$") 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 = npcItem["D"]
            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 = "[[" .. tLink
        if tLink ~= tDisp then
        	nameLink = nameLink .. "|" .. tDisp
        end
        nameLink = nameLink .. "]]"
    elseif inclName == "A" then
        nameLink = "[[" .. tLink
        if altText ~= "" then
            nameLink = 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"
    end

	if inclName ~= "L" then
		if inclName ~= "E" then
		nameLink = nameLink .. "[[File:"
        .. tFile .. tSize .. tDisp
        .. "|link=" .. tLink .. "]]" .. bracket
        end
    end
    return nameLink
end

-- return all NPC in horizontal format

function p.getNPCList()
    local tIndex = {}

    for npcName, v in pairs(npcData) do
        if not v["X"] then
            -- include lower case name for sort comparison
            -- so that ALL CAPS names sort properly
            table.insert(tIndex, {string.lower(npcName), npcName})
        end
    end

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

    local outText = ""
    local sDot = ""

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

        sDot = " '''·''' "
    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["N"] or npcName,
			    	"|",
			    	npcItem["D"] or npcName,
			    	"]] first appeared during the ",
			    	require("Module:LTEvent").getLTE({npcItem["E"], "N", "D"}),
			    	".\n",
			    }
		end
	end
    return table.concat(outText)
end

return p