Module:Hearts: Difference between revisions
Want an adless experience? Log in or Create an account.
(Created page with "local p = {} function p.icons( frame ) local icon = { [0] = "link=", [0.25] = "link=", [0.5] = "[[File:1-2 Heart...") |
m (replace \n with <br/>) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
function p.icons( frame ) | function p.icons( frame ) | ||
local icon = { | local icon = { | ||
[0] = " | [0] = "", | ||
[0.25] = "[[File:1-4 Heart.png|link=]]", | [0.25] = "[[File:1-4 Heart.png|link=]]", | ||
[0.5] = "[[File:1-2 Heart.png|link=]]", | [0.5] = "[[File:1-2 Heart.png|link=]]", | ||
[0.75] = "[[File:3-4 Heart.png|link=]]", | [0.75] = "[[File:3-4 Heart.png|link=]]", | ||
[1] = "[[File:1 Heart.png|link=]]" | [1] = "[[File:1 Heart.png|link=]]", | ||
empty = "[[File:0 Heart.png|link=]]" | |||
} | } | ||
local output = {} | local output = {} | ||
for i,v in ipairs( frame: | for i,v in ipairs( frame:getParent().args ) do | ||
local num = tonumber( v ) | local num = tonumber( v ) | ||
local whole = math.floor( num ) | local whole = math.floor( num ) | ||
local fraction = num - whole | local fraction = num - whole | ||
output[#output+1] = string.rep( icon[1], whole ) .. icon[fraction] | output[#output+1] = num == 0 and icon.empty or string.rep( icon[1], whole ) .. icon[fraction] | ||
end | end | ||
return table.concat(output, " | return table.concat(output, "<br/>") | ||
end | end | ||
return p | return p |
Latest revision as of 07:32, April 4, 2017
Documentation for this module may be created at Module:Hearts/doc
local p = {} function p.icons( frame ) local icon = { [0] = "", [0.25] = "[[File:1-4 Heart.png|link=]]", [0.5] = "[[File:1-2 Heart.png|link=]]", [0.75] = "[[File:3-4 Heart.png|link=]]", [1] = "[[File:1 Heart.png|link=]]", empty = "[[File:0 Heart.png|link=]]" } local output = {} for i,v in ipairs( frame:getParent().args ) do local num = tonumber( v ) local whole = math.floor( num ) local fraction = num - whole output[#output+1] = num == 0 and icon.empty or string.rep( icon[1], whole ) .. icon[fraction] end return table.concat(output, "<br/>") end return p