Module:Resources: Difference between revisions

From Nova Roma Official Wiki
mNo edit summary
No edit summary
Line 3: Line 3:
local icons = {
local icons = {
wood = "[[File:icon_wood.png|30px|link=]]",
wood = "[[File:icon_wood.png|30px|link=]]",
metal = "[[File:icon_tools.png|30px|link=]]",
tools = "[[File:icon_tools.png|30px|link=]]",
stone = "[[File:icon_stone.png|30px|link=]]",
stone = "[[File:icon_stone.png|30px|link=]]",
gold = "[[File:icon_gold.png|30px|link=]]",
gold = "[[File:icon_gold.png|30px|link=]]",
Line 14: Line 14:
-- Split by comma and process each resource
-- Split by comma and process each resource
for resource in input:gmatch("[^,]+") do
for resource in input:gmatch("[^,]+") do
resource = resource:match("^%s*(.-)%s*$") -- trim whitespace
local amount, name = resource:match("(%d+)%s+(%w+)")
local amount, name = resource:match("(%d+)%s+(%w+)")
if amount and name and icons[name] then
if amount and name and icons[name] then
-- If amount exists: "icon amount"
table.insert(result, icons[name] .. " " .. amount)
table.insert(result, icons[name] .. " " .. amount)
else
-- If only name: "icon"
name = resource:match("(%w+)")
if name and icons[name] then
table.insert(result, icons[name])
end
end
end
end
end

Revision as of 21:53, 24 February 2026

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

local p = {}

local icons = {
	wood = "[[File:icon_wood.png|30px|link=]]",
	tools = "[[File:icon_tools.png|30px|link=]]",
	stone = "[[File:icon_stone.png|30px|link=]]",
	gold = "[[File:icon_gold.png|30px|link=]]",
}

function p.format(frame)
	local input = frame.args[1] or ""
	local result = {}
	
	-- Split by comma and process each resource
	for resource in input:gmatch("[^,]+") do
		resource = resource:match("^%s*(.-)%s*$") -- trim whitespace
		local amount, name = resource:match("(%d+)%s+(%w+)")
		
		if amount and name and icons[name] then
			-- If amount exists: "icon amount"
			table.insert(result, icons[name] .. " " .. amount)
		else
			-- If only name: "icon"
			name = resource:match("(%w+)")
			if name and icons[name] then
				table.insert(result, icons[name])
			end
		end
	end
	
	return table.concat(result, "<br>")
end

return p