Module:Item: Difference between revisions

From EarthMC
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 21: Line 21:
local fileExists = fileModule.fileExists("File:"..arg..".png")
local fileExists = fileModule.fileExists("File:"..arg..".png")
if fileExists then
if fileExists then
return "[[File:"..arg..".png|20px]] "..capitalizeFirstLetter(arg)
return frame:preprocess("{{InvSprite|"..arg.."}} "..capitalizeFirstLetter(arg))
end
end
return capitalizeFirstLetter(arg)
return capitalizeFirstLetter(arg)

Revision as of 15:03, 21 October 2023

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

local p = {}

local fileModule = require("Module:FileExists")

local function capitalizeFirstLetter(input)
	local firstLetter = input:sub(1, 1)
	local restOfString = input:sub(2)
	return firstLetter:upper() .. restOfString:lower()
end

local function removeMinecraftPrefix(text)
    if text:sub(1, 10) == "minecraft:" then
        return text:sub(11)
    else
        return text
    end
end

function p.getItemNameAndIMG( frame )
    local arg = removeMinecraftPrefix(string.lower(frame.args[1]))
	local fileExists = fileModule.fileExists("File:"..arg..".png")
	if fileExists then
		return frame:preprocess("{{InvSprite|"..arg.."}} "..capitalizeFirstLetter(arg))
	end
	return capitalizeFirstLetter(arg)
end

return p