Module:CharacterToken

--[=[ --LUA script replacement for wikitext template -- --   t-.png -- -- --Parameters: --   1: Token = (character,token type,count) --           count is optional --           Separate multiple items with exclamation mark "!" --           if the item is blank or "&", line break " " --                 will be inserted instead. --   2: Size in pixels --       optional, defaults to 25 -- --The list of available tokens is kept in the module data -- --Unknown Token is returned if Token Type is not in data. --]=]

local p = {}

local util = require("Module:Utility")

---[==[ local tokenData = mw.loadData('Module:CharacterToken/data') --[===[]==] local tokenData = { -- Toy Story -- ["ip-ts"] = { ["F"] = "ip-toy story", ["0"] = {"Pixar Ball"} },   ["jessie"] = { ["2"] = {"Lasso"}, ["3"] = {"Jessie Ears Hat"} },   ["sarge"] = { ["2"] = {"Sarge's Bucket"}, ["3"] = {"Sarge Ears Hat"} },   ["woody"] = { ["2"] = {"Sheriff Star"}, ["3"] = {"Woody Ears Hat"} }, } --]===]

local function oneToken(token, size) token = mw.ustring.gsub(mw.ustring.lower(token),               "^%s*(.-)%s*$", "%1") or ''

local tokenFileAll = "" local space = ""

for tok in mw.text.gsplit(token, "%s*[!%$]%s*") do       if tok == "" or tok == "&" then tokenFileAll = tokenFileAll .. " "           space = "" else local tokenFile local tokenLink local cName, tokenType, count = mw.ustring.match(tok,                                "^([^,]-)%s*,%s*(%d+)%s*,*%s*([\/%d]*)$") if not cName then cName, count = mw.ustring.match(tok, "^([^,]-)%s*,%s*,*%s*([\/%d]*)$") if not cName then cName = tok end end if not tokenType or tokenType == "" then tokenType = "0" end if tokenData[cName] and tokenData[cName][tokenType] then if tokenData[cName]["F"] then tokenFile = "[[File:t-" .. tokenData[cName]["F"]               else                    tokenFile = "[[File:t-" .. cName                end                tokenFile = mw.ustring.gsub(tokenFile, " ", "_")                tokenLink = "|" .. tokenData[cName][tokenType][1]                    .. " Token|link="                    .. tokenData[cName][tokenType][1]                    .. " Token]]"            else                tokenFile = "work_in_progress"                tokenLink = ""                tokenType = "0"            end            if tokenType ~= "0" then                tokenFile = tokenFile .. "-" .. tokenType            end            tokenFileAll = tokenFileAll .. space                .. tokenFile .. ".png|x"                .. size                .. "px"                .. tokenLink            if count and count ~= "" then                tokenFileAll = tokenFileAll .. "" .. count .. ""            end            space = " "        end    end    return tokenFileAll end

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

local token = tArgs[1] or "" local size = tArgs[2] or "25"

local multi, rarity = token:match("^(multi)(%d*)$")

return oneToken(token, size) end

return p

-- --