Difference between revisions of "Module:IconBar"

From Minetest Wiki
Jump to navigation Jump to search
m
(FnControlOption changed the content model of the page Module:IconBar from "plain text" to "Scribunto")
Tag: content model change
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
  
function p.hearts(num)
+
local makeInvokeFunc = require("Module:Arguments").makeInvokeFunc
     num = num or 1
+
 
 +
function p._bar(args)
 +
     local name = args.name
 +
    local num = tonumber(args[1]) or 1
 
     if num == 0 then
 
     if num == 0 then
         return "[[File:Empty heart.png|16px]]"
+
         return "[[File:Empty " .. name .. ".png|16px]]"
 
     end
 
     end
 
     local numFloor = math.floor(num)
 
     local numFloor = math.floor(num)
     local s = ""
+
     local s = string.rep("[[File:" .. name .. ".png|16px]]", numFloor)
    for i = 1, numFloor do
 
        s = s .. "[[File:Heart.png|16px]]"
 
    end
 
 
     if numFloor ~= num then
 
     if numFloor ~= num then
         s = s .. "[[File:Half heart.png|16px]]"
+
         s = s .. "[[File:Half " .. name .. ".png|16px]]"
 
     end
 
     end
 
     return s
 
     return s
 
end
 
end
 +
 +
p.bar = makeInvokeFunc(p._bar, {inherited = true})
  
 
return p
 
return p

Latest revision as of 17:44, 7 June 2022

Documentation for this module may be created at Module:IconBar/doc

local p = {}

local makeInvokeFunc = require("Module:Arguments").makeInvokeFunc

function p._bar(args)
    local name = args.name
    local num = tonumber(args[1]) or 1
    if num == 0 then
        return "[[File:Empty " .. name .. ".png|16px]]"
    end
    local numFloor = math.floor(num)
    local s = string.rep("[[File:" .. name .. ".png|16px]]", numFloor)
    if numFloor ~= num then
        s = s .. "[[File:Half " .. name .. ".png|16px]]"
    end
    return s
end

p.bar = makeInvokeFunc(p._bar, {inherited = true})

return p