« Module:Cost » : différence entre les versions

De Inkipédia
m (Suppression de la catégorie Category:Templates et ajout de Catégorie:Modèles par un robot)
(modèle:cost)
 
(Une version intermédiaire par le même utilisateur non affichée)
Ligne 1 : Ligne 1 :
local p = {}
local p = {}


-- Main for Cost module with the wiki template args
-- Translation table for currency link texts in French
local frenchLinkText = {
    cash = "Argent",
    pe = "Œuf de poisson",
    sss = "Super coquillage",
 
    ge = "Œuf doré",
    sard = "Sardinium",
 
    ac = "Fragment de bonus",
    cqp = "Points Curbit",
 
    sl = "Brevet Cartouche",
    gsl = "Brevet Cartouche",
 
    bs = "Écaille de poisson",
    ss = "Écaille de poisson",
    gs = "Écaille de poisson",
   
    mb = "Poulpèzes",
    pl = "Péperles"
}
 
-- Main function for Cost module with the wiki template args
function p.main(frame)
function p.main(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
Ligne 16 : Ligne 39 :


-- Get the full name of a currency type from its abbreviation.
-- Get the full name of a currency type from its abbreviation.
-- Remember in Lua you do not have to specify all parameters.
-- If default is not specified then 'nil' is used and returned if not found.
function p.getNameFromAbbreviation(abbreviation, default)
function p.getNameFromAbbreviation(abbreviation, default)
    -- Use the default English names for constructing file names
     local currencyTypes = {
     local currencyTypes = {
         cash = "Cash",
         cash = "Cash",
Ligne 45 : Ligne 67 :


-- Get the link text of a currency type from its abbreviation.
-- Get the link text of a currency type from its abbreviation.
-- If default is not specified then 'nil' is used and returned if not found.
function p.getLinkFromAbbreviation(abbreviation, default)
function p.getLinkFromAbbreviation(abbreviation, default)
    local currencyTypes = {
     return frenchLinkText[abbreviation] or default
        cash = "Cash",
        pe = "Power Egg",
        sss = "Super Sea Snail",
 
        ge = "Golden Egg",
        sard = "Sardinium Shadow",
 
        ac = "Ability chunk",
        cqp = "CQ-80#CQ Points",
 
        sl = "Sheldon License",
        gsl = "Sheldon License",
 
        bs = "Fish scale",
        ss = "Fish scale",
        gs = "Fish scale",
       
        mb = "Membux",
        pl = "Prlz"
    }
 
     return currencyTypes[abbreviation] or default
end
end


-- Function to get the cost details
function p.getCost(game, quantity, currencyType, size, linkDisplay, widthStyle)
function p.getCost(game, quantity, currencyType, size, linkDisplay, widthStyle)
game = string.upper(game)
game = string.upper(game)
Ligne 129 : Ligne 129 :


return p
return p
[[Catégorie:Modèles]]

Dernière version du 23 juin 2024 à 15:26

Displays an inline currency icon with a text link.

Usage

{{Cost|<game>|<price>|<currency>|<size>|<link>|<textwidth>}}

game Unnamed, required The game that the cost belongs to. Must be one of the following:
  • S for Splatoon
  • S2 for Splatoon 2
  • S3 for Splatoon 3
price Unnamed, required (may be empty) The quantity to show as the cost.
If set empty, the template will show the icon only.
Note that this template also accepts space (' ') which handles differently to empty.
Use 0 or Free for free items.
currency Unnamed, optional The currency to use.
The default value is cash.
Must be one of the following: S S2 S3
cash Cash Cash Cash
pe Power Eggs Power Eggs Power Egg Alternas
sss Super Sea Snails Super Sea Snails Super Sea Snails
ge Golden Eggs
sard Sardinium Shadow
ac Ability Chunks
cqp CQ Points
sl Sheldon Licenses
gsl Gold Sheldon Licenses
bs Bronze Fish Scales
ss Silver Fish Scales
gs Gold Fish Scales
mb Membuxs
pl Prlzs
size Unnamed, optional The icon size for the currency icon. The default is 24.
link Unnamed, optional If present, the amount text will be a link to the currency's page.
textwidth Unnamed, optional Requries size and link to both be present.
If specified, the label will be set inside a right-aligned rectangle of the specified width

Markup

*{{Cost|S|200}}
*{{Cost|S2|200}}
*{{Cost|S3|200}}
*{{Cost|S|}}
*{{Cost|S|1|sss}}
*{{Cost|S2||ac}}
*{{Cost|S3|160|bs}}
*{{Cost|S|200|cash|48}}
*{{Cost|S|200|cash|link}}
*{{Cost|S|200|cash|48|link}}
*{{Cost|S|200|cash|24|link|60}}
*{{Cost|S|200|cash|24| |60}}

Output

  • Cash 200
  • Cash 200
  • Cash 200
  • Cash
  • Super Sea Snail 1
  • Ability Chunks
  • Bronze Fish Scales 160
  • Cash 200
  • Cash 200
  • Cash 200
  • Cash 200
  • Cash 200

local p = {}

-- Translation table for currency link texts in French
local frenchLinkText = {
    cash = "Argent",
    pe = "Œuf de poisson",
    sss = "Super coquillage",

    ge = "Œuf doré",
    sard = "Sardinium",

    ac = "Fragment de bonus",
    cqp = "Points Curbit",

    sl = "Brevet Cartouche",
    gsl = "Brevet Cartouche",

    bs = "Écaille de poisson",
    ss = "Écaille de poisson",
    gs = "Écaille de poisson",
    
    mb = "Poulpèzes",
    pl = "Péperles"
}

-- Main function for Cost module with the wiki template args
function p.main(frame)
    local args = frame:getParent().args
	
	local game = args[1] or 'S'
    local quantity = args[2]
    local currencyType = args[3] or args['currency']
    local size = tonumber(args[4])
    local linkDisplay = args[5] or args[4]
    local widthStyle = args[6] and ("width:" .. args[6] .. "px;")
	
    return p.getCost(game, quantity, currencyType, size, linkDisplay, widthStyle)
end

-- Get the full name of a currency type from its abbreviation.
function p.getNameFromAbbreviation(abbreviation, default)
    -- Use the default English names for constructing file names
    local currencyTypes = {
        cash = "Cash",
        pe = "Power Egg",
        sss = "Super Sea Snail",

        ge = "Golden Egg",
        sard = "Sardinium Shadow",

        ac = "Ability Chunk Generic",
        cqp = "CQ Points",

        sl = "Sheldon License",
        gsl = "Gold Sheldon License",

        bs = "Bronze Fish Scale",
        ss = "Silver Fish Scale",
        gs = "Gold Fish Scale",
        
        mb = "Membux",
        pl = "Prlz"
    }

    return currencyTypes[abbreviation] or default
end

-- Get the link text of a currency type from its abbreviation.
function p.getLinkFromAbbreviation(abbreviation, default)
    return frenchLinkText[abbreviation] or default
end

-- Function to get the cost details
function p.getCost(game, quantity, currencyType, size, linkDisplay, widthStyle)
	game = string.upper(game)
	if currencyType == nil then currencyType = "cash" end
	if size == nil then size = 24 end
	if linkDisplay == nil then linkDisplay = "" end
	if widthStyle == nil then widthStyle = "" end
	
    local currencyIconName = nil

    -- Special cases for currency names based on game type
    if currencyType == 'pe' and game == 'S3' then
        currencyIconName = "Power Egg Alterna"
    elseif currencyType == 'sard' and game == 'S2' then
        currencyIconName = "Sardinium Shadow"
    else
        currencyIconName = p.getNameFromAbbreviation(currencyType, "Cash")
    end

    -- Constructing file name and link
    local fileName = string.format("%s Icon %s.png", game, currencyIconName)
    local fileSize = string.format("%dx%dpx", size, size)
    local fileLink = p.getLinkFromAbbreviation(currencyType, "Cash")

    -- Now let's construct the display name.

    -- Dirty hack, for ac, remove 'Generic'
    if currencyType == 'ac' then currencyIconName = "Ability Chunk" end

    -- Append 's' for plural forms for the display name if quantity is not '1'
    -- Exclude sardinium, cqp, and cash
    if quantity ~= '1' and (currencyType ~= 'sard' and currencyType ~= 'cqp' and currencyIconName ~= 'Cash') then
        currencyIconName = currencyIconName .. "s"
    end

    -- Construct the image link
    local imageLink = string.format('[[File:%s|%s|%s|link=%s]]', fileName,
                                    fileSize, currencyIconName, fileLink)

    -- Constructing output with additional span for quantity if provided
    if quantity and quantity ~= '' then
        local spanTag = mw.html.create('span')
        spanTag:css('display', 'inline-block'):css('text-align', 'right')

        if widthStyle and widthStyle ~= '' then
            spanTag:cssText(widthStyle)
        end

        local quantityLink = linkDisplay == 'link' and string.format('[[%s|%s]]', fileLink, quantity) or quantity
        spanTag:wikitext('&nbsp;' .. quantityLink)

        return imageLink .. tostring(spanTag)
    else
        return imageLink
    end
end

return p