Modül:GiftsByItem

Stardew Valley Wiki sitesinden
Margotbean (mesaj | katkılar) tarafından oluşturulmuş 02.22, 18 Ocak 2023 tarihli sürüm
Gezinti kısmına atla Arama kısmına atla

Description

This module takes a comma-separated list of villager names and transforms it into a bullet-separated list of villager icons + links to villager pages.

This module performs tasks that were formerly performed by arrays (sorting, translating, and formatting) in Template:GiftsByItem.

This module can be copy/pasted into all languages without alteration.

Please report any problems or issues with the module on the discussion page for Template:GiftsByItem.


--[[This module currently takes a comma-separated list of villager names and
    transforms it into a bullet-separated list of links to villager pages.
    The next step is to pre-pend icons to the links.
    This will replace the arrays in Template:GiftsByItem
]]
local p = {}
local lang = string.upper(mw.getContentLanguage().code)	

--ts = translate & sort
function p.ts(frame)
    local villagerlist = frame.args[1]
    local villagertable = {}

    if villagerlist ~= nil then
        local values = mw.text.split(villagerlist, ",", true)
        for i = 1, #values do
            local v = mw.text.trim(values[i])
            if v ~= "" then
                table.insert(villagertable, v)
            end
        end
    end  

    if lang == "DE" then
            for k,v in pairs(villagertable) do
                if v == "Dwarf" then
                    table.insert(villagertable, "Zwerg")
                    table.remove(villagertable, k)
                end
                if v == "Wizard" then
                    table.insert(villagertable, "Zauberer")
                    table.remove(villagertable, k)
                end                  
            end
    elseif lang == "TR" then
            for k,v in pairs(villagertable) do
                if v == "Dwarf" then
                    table.insert(villagertable, "Cüce")
                    table.remove(villagertable, k)
                    --v.gsub(v, "Dwarf", "Cüce")
                end
                if v == "Wizard" then
                    table.insert(villagertable, "Büyücü")
                    table.remove(villagertable, k)
                end                  
            end
    end
    
    table.sort(villagertable)
    

    --mw.text.listToText(villagertable,  " • ")

    --put the table "villagertable" back into a string blob
    villagerlist = ""
    for i=1, (#villagertable-1) do
        villagerlist = villagerlist .. "[[" .. villagertable[i] .. "]]  • "
    end
    --We don't want a trailing bullet at the end of the list
    villagerlist = villagerlist .. "[[" .. villagertable[#villagertable] .. "]]"

    return villagerlist
end

return p