Module:Item: Difference between revisions

From EarthMC
Jump to navigation Jump to search
(Created page with "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 function p.getItemNameAndIMG( frame ) local arg = string.lower(frame.args[1]) local fileExists = fileModule.fileExists("File:"..arg) if fileExists then return "File:"..arg.."|25px]] "..capitalizeFirstLetter(arg) end return capitalizeFirstLette...")
 
mNo edit summary
 
(27 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local fileModule = require("Module:FileExists")
local fileModule = require("Module:FileExists")


Line 5: Line 7:
local restOfString = input:sub(2)
local restOfString = input:sub(2)
return firstLetter:upper() .. restOfString:lower()
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
local function formatItemName(itemNames)
    local formattedNames = {}
    for itemName in string.gmatch(itemNames, "[^%s,/&]+") do
        local _, _, mod, name = string.find(itemName, "([^:]+):([^:]+)")
        if not mod then
            name = itemName
        else
            name = string.gsub(name, "_", " ")
            name = name:gsub("^%l", string.upper)
        end
if fileModule.fileExists("File:"..string.lower(name)..".png") then
name = "[[File:"..string.lower(name)..".png|20px]] "..capitalizeFirstLetter(name)
end
        table.insert(formattedNames, name)
    end
    return table.concat(formattedNames, " & ")
end
end


function p.getItemNameAndIMG( frame )
function p.getItemNameAndIMG( frame )
     local arg = string.lower(frame.args[1])
     local arg = frame.args[1]
local fileExists = fileModule.fileExists("File:"..arg)
    local text = formatItemName(string.lower(arg))
if fileExists then
--local fileExists = fileModule.fileExists("File:"..string.lower(text)..".png")
return "File:"..arg.."|25px]] "..capitalizeFirstLetter(arg)
--if fileExists then
end
-- return "[[File:"..string.lower(text)..".png|20px]] "..capitalizeFirstLetter(text)
return capitalizeFirstLetter(arg)
--end
return text
end
end
return p

Latest revision as of 13:48, 22 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

local function formatItemName(itemNames)
    local formattedNames = {}

    for itemName in string.gmatch(itemNames, "[^%s,/&]+") do
        local _, _, mod, name = string.find(itemName, "([^:]+):([^:]+)")
        if not mod then
            name = itemName
        else
            name = string.gsub(name, "_", " ")
            name = name:gsub("^%l", string.upper)
        end

		if fileModule.fileExists("File:"..string.lower(name)..".png") then
			name = "[[File:"..string.lower(name)..".png|20px]] "..capitalizeFirstLetter(name)
		end

        table.insert(formattedNames, name)
    end

    return table.concat(formattedNames, " & ")
end

function p.getItemNameAndIMG( frame )
    local arg = frame.args[1]
    local text = formatItemName(string.lower(arg))
	--local fileExists = fileModule.fileExists("File:"..string.lower(text)..".png")
	--if fileExists then
	--	return "[[File:"..string.lower(text)..".png|20px]] "..capitalizeFirstLetter(text)
	--end
	return text
end

return p