Module:Hearts: Difference between revisions

Want an adless experience? Log in or Create an account.
fix 0 handling maybe if I got order of operations right
No edit summary
(fix 0 handling maybe if I got order of operations right)
Line 3: Line 3:
function p.icons( frame )
function p.icons( frame )
   local icon = {
   local icon = {
     [0]    = "[[File:0 Heart.png|link=]]",
     [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=]]"
   }
   }


Line 15: Line 16:
     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, "\n")
   return table.concat(output, "\n")