Module:Param Parse: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
Line 445: Line 445:
smw_func = parse.difficulty_smw,
smw_func = parse.difficulty_smw,
category_incomplete = 'Needs difficulty'
category_incomplete = 'Needs difficulty'
}

-- Requirements
function parse.requirements_func(input_string)
local icon_map = {
scout = '[[File:Scout_icon.png|link=Scout|width=18x18]]',
knowledge = '[[File:Knowledge_icon.png|link=Knowledge|width=18x18]]',
quest = '[[File:Quests_icon.png|link=Quests|width=18x18]]',
min_weapon_strength = '[[File:Scout_icon.png|link=Scout|width=18x18]]'
}

local fields = {}
for field in input_string:gmatch("([^,]+)") do
table.insert(fields, field)
end

local result = {}

for i = 1, #fields, 2 do
local key = fields[i]
local value = fields[i+1]
if not value then
-- Do nothing
else
local icon = icon_map[key]
if type(value) == "number" then
table.insert(result, string.format("%s %d", icon, math.floor(value)))
else
table.insert(result, string.format("%s %s", icon, value))
end
end
end

return table.concat(result, ", ")
end

parse.requirements = {
name = 'requirements',
func = parse.requirements_func,
smw_property = 'Requirements',
category_incomplete = 'Needs requirements'
}
}