Module:Resources: Difference between revisions
From Nova Roma Official Wiki
No edit summary |
No edit summary |
||
| (21 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
local icons = { | local icons = { | ||
wood = "[[File:icon_wood.png|30px|link=]]", | apples = "[[File:icon_apples.png|30px|link=Apples]]", | ||
armaments = "[[File:icon_armament.png|30px|link=Armaments]]", | |||
bread = "[[File:resource bread.png|30px|link=Bread]]", | |||
charcoal = "[[File:resource charcoal.png|30px|link=Charcoal]]", | |||
clay = "[[File:icon_clay.png|30px|link=Clay]]", | |||
fish = "[[File:icon_fish.png|30px|link=Fish]]", | |||
gold = "[[File:icon_gold.png|30px|link=Gold]]", | |||
grapes = "[[File:icon_grapes.png|30px|link=Grapes]]", | |||
iron = "[[File:Resource_iron.png|30px|link=Iron]]", | |||
marble = "[[File:icon_marble.png|30px|link=Marble]]", | |||
meat = "[[File:icon_pork.png|30px|link=Meat]]", | |||
olives = "[[File:icon_olives.png|30px|link=Olives]]", | |||
oliveoil = "[[File:icon_oliveoil.png|30px|link=Olive Oil]]", | |||
pottery = "[[File:icon_pottery.png|30px|link=Pottery]]", | |||
salt = "[[File:icon_salt.png|30px|link=Salt]]", | |||
stone = "[[File:icon_stone.png|30px|link=Stone]]", | |||
tools = "[[File:icon_tools.png|30px|link=Tools]]", | |||
wheat = "[[File:icon_wheat.png|30px|link=Wheat]]", | |||
wine = "[[File:icon_wine.png|30px|link=Wine]]", | |||
wood = "[[File:icon_wood.png|30px|link=Wood]]", | |||
citizens = "[[File:Citizens.png|30px|link=Citizens]]", | |||
favor = "[[File:Resource favor.png|30px|link=Favor]]", | |||
happiness = "[[File:happy_icon.png|30px|link=Happiness]]", | |||
size = "[[File:dimensions.png|30px|link=Size]]", | |||
food = "[[File:icon_wheat.png|30px|link=Food]]", | |||
} | } | ||
function p.format(frame) | function p.format(frame) | ||
local input = frame.args[1] or "" | local input = frame.args[1] or "" | ||
local direction = (frame.args[2] or "column"):lower() | |||
local result = {} | local result = {} | ||
| Line 19: | Line 41: | ||
if amount and name and icons[name] then | if amount and name and icons[name] then | ||
-- If amount exists: "icon amount" | -- If amount exists: "icon amount" | ||
table.insert(result, icons[name] .. " " .. amount) | table.insert(result, {icons[name] .. " " .. amount, true}) | ||
else | else | ||
-- If only name: "icon" | -- If only name: "icon" | ||
name = resource:match("(%w+)") | name = resource:match("(%w+)") | ||
if name and icons[name] then | if name and icons[name] then | ||
table.insert(result, icons[name]) | table.insert(result, {icons[name], false}) | ||
end | end | ||
end | end | ||
end | end | ||
return | -- Join based on direction | ||
local separator = (direction == "row") and "  " or "<br>" | |||
local final = "" | |||
for i, item in ipairs(result) do | |||
final = final .. item[1] | |||
if i < #result then | |||
final = final .. separator | |||
end | |||
end | |||
return final | |||
end | |||
-- outputs icon + linked name for a single resource | |||
function p.label(frame) | |||
local parent = frame:getParent() | |||
local name = frame.args[1] or (parent and parent.args.name) | |||
if not name then return "" end | |||
name = name:lower() | |||
local icon = icons[name] | |||
if not icon then | |||
return "''Unknown resource: " .. name .. "''" | |||
end | |||
local amount = frame.args[2] or frame.args.amount | |||
if parent then | |||
amount = amount or parent.args[1] or parent.args.amount | |||
end | |||
if amount then | |||
return string.format("%s %s", icon, amount) | |||
end | |||
local link = icon:match("link=([^%]]+)%]%]") or name | |||
return string.format("%s [[%s]]", icon, link) | |||
end | end | ||
return p | return p | ||
Latest revision as of 14:43, 26 March 2026
Documentation for this module may be created at Module:Resources/doc
local p = {}
local icons = {
apples = "[[File:icon_apples.png|30px|link=Apples]]",
armaments = "[[File:icon_armament.png|30px|link=Armaments]]",
bread = "[[File:resource bread.png|30px|link=Bread]]",
charcoal = "[[File:resource charcoal.png|30px|link=Charcoal]]",
clay = "[[File:icon_clay.png|30px|link=Clay]]",
fish = "[[File:icon_fish.png|30px|link=Fish]]",
gold = "[[File:icon_gold.png|30px|link=Gold]]",
grapes = "[[File:icon_grapes.png|30px|link=Grapes]]",
iron = "[[File:Resource_iron.png|30px|link=Iron]]",
marble = "[[File:icon_marble.png|30px|link=Marble]]",
meat = "[[File:icon_pork.png|30px|link=Meat]]",
olives = "[[File:icon_olives.png|30px|link=Olives]]",
oliveoil = "[[File:icon_oliveoil.png|30px|link=Olive Oil]]",
pottery = "[[File:icon_pottery.png|30px|link=Pottery]]",
salt = "[[File:icon_salt.png|30px|link=Salt]]",
stone = "[[File:icon_stone.png|30px|link=Stone]]",
tools = "[[File:icon_tools.png|30px|link=Tools]]",
wheat = "[[File:icon_wheat.png|30px|link=Wheat]]",
wine = "[[File:icon_wine.png|30px|link=Wine]]",
wood = "[[File:icon_wood.png|30px|link=Wood]]",
citizens = "[[File:Citizens.png|30px|link=Citizens]]",
favor = "[[File:Resource favor.png|30px|link=Favor]]",
happiness = "[[File:happy_icon.png|30px|link=Happiness]]",
size = "[[File:dimensions.png|30px|link=Size]]",
food = "[[File:icon_wheat.png|30px|link=Food]]",
}
function p.format(frame)
local input = frame.args[1] or ""
local direction = (frame.args[2] or "column"):lower()
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, true})
else
-- If only name: "icon"
name = resource:match("(%w+)")
if name and icons[name] then
table.insert(result, {icons[name], false})
end
end
end
-- Join based on direction
local separator = (direction == "row") and "  " or "<br>"
local final = ""
for i, item in ipairs(result) do
final = final .. item[1]
if i < #result then
final = final .. separator
end
end
return final
end
-- outputs icon + linked name for a single resource
function p.label(frame)
local parent = frame:getParent()
local name = frame.args[1] or (parent and parent.args.name)
if not name then return "" end
name = name:lower()
local icon = icons[name]
if not icon then
return "''Unknown resource: " .. name .. "''"
end
local amount = frame.args[2] or frame.args.amount
if parent then
amount = amount or parent.args[1] or parent.args.amount
end
if amount then
return string.format("%s %s", icon, amount)
end
local link = icon:match("link=([^%]]+)%]%]") or name
return string.format("%s [[%s]]", icon, link)
end
return p


