Module:Param Parse: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(Level range support) |
(Smw support for number ranges) |
||
Line 23: | Line 23: | ||
end |
end |
||
-- Standardized number range |
-- Standardized number range: Accepts '1' and '1-5' |
||
function parse. |
function parse.number_or_number_range(prenum) |
||
local |
local ret = '' |
||
local count = 0 |
local count = 0 |
||
for out in string.gmatch(prenum, "[^-]+") do |
for out in string.gmatch(prenum, "[^-]+") do |
||
if count == 1 then |
if count == 1 then |
||
ret = ret .. "➨\n" |
|||
elseif count == 3 then |
elseif count == 3 then |
||
return |
return nil |
||
end |
end |
||
num = |
num = parse.number(out) |
||
⚫ | |||
return nil |
|||
⚫ | |||
ret = ret .. num |
|||
count = count + 1 |
count = count + 1 |
||
end |
end |
||
return |
return ret |
||
end |
|||
function parse.number_or_number_range_low(prenum) |
|||
local count = 0 |
|||
local value = nil |
|||
for out in string.gmatch(prenum, "[^-]+") do |
|||
if parse.number(out) == nil then |
|||
return nil |
|||
end |
|||
count = count + 1 |
|||
if count == 1 then |
|||
value = out |
|||
end |
|||
if count > 2 then |
|||
return nil |
|||
end |
|||
end |
|||
return parse.number(value) |
|||
end |
|||
function parse.number_or_number_range_high(prenum) |
|||
local count = 0 |
|||
local value = nil |
|||
for out in string.gmatch(prenum, "[^-]+") do |
|||
if parse.number(out) == nil then |
|||
return nil |
|||
end |
|||
count = count + 1 |
|||
if count == 2 then |
|||
value = out |
|||
end |
|||
if count > 2 then |
|||
return nil |
|||
end |
|||
end |
|||
return parse.number(value) |
|||
end |
end |
||
Line 253: | Line 293: | ||
} |
} |
||
-- Profession |
-- Profession |
||
function parse.profession_bubble_func(profession, level) |
function parse.profession_bubble_func(profession, level) |
||
local profession_valid = parse.has_content(profession) |
local profession_valid = parse.has_content(profession) |
||
local profession_valid_link = profession_valid |
local profession_valid_link = profession_valid |
||
local level_valid = parse. |
local level_valid = parse.number_or_number_range(level) |
||
local category_error = false |
local category_error = false |
||
if not profession_valid and not level_valid then |
if not profession_valid and not level_valid then |
||
Line 269: | Line 309: | ||
end |
end |
||
if profession_valid and not level_valid then |
if profession_valid and not level_valid then |
||
-- |
-- Profession defined without level, invalid, show an unknown level |
||
level_valid = |
level_valid = '?' |
||
⚫ | |||
⚫ | |||
-- Profession defined without level, invalid, show an unknown level |
|||
level_valid = '?' |
|||
⚫ | |||
⚫ | |||
end |
end |
||
return '[[File:'..profession_valid..' icon.png|x30px|link='..profession_valid_link..']] '..level_valid..(category_error and '[[Category:Invalid profession bubble]]' or '') |
return '[[File:'..profession_valid..' icon.png|x30px|link='..profession_valid_link..']] '..level_valid..(category_error and '[[Category:Invalid profession bubble]]' or '') |
||
Line 303: | Line 339: | ||
parse.profession_a_level_smw = { |
parse.profession_a_level_smw = { |
||
name = 'profession_a_level', |
name = 'profession_a_level', |
||
func = parse. |
func = parse.number_or_number_range_low, |
||
smw_property = 'Profession Level A', |
smw_property = 'Profession Level A', |
||
} |
|||
parse.profession_a_level_high_smw = { |
|||
name = 'profession_a_level_high', |
|||
func = {name = parse.number_or_number_range_high, params = {Infobox.raw_param('profession_a_level')}}, |
|||
smw_property = 'Profession Level A High', |
|||
} |
} |
||
parse.profession_bubble_b = { |
parse.profession_bubble_b = { |
||
Line 319: | Line 360: | ||
parse.profession_b_level_smw = { |
parse.profession_b_level_smw = { |
||
name = 'profession_b_level', |
name = 'profession_b_level', |
||
func = parse. |
func = parse.number_or_number_range_low, |
||
smw_property = 'Profession Level B', |
smw_property = 'Profession Level B', |
||
} |
|||
parse.profession_b_level_high_smw = { |
|||
name = 'profession_b_level_high', |
|||
func = {name = parse.number_or_number_range_high, params = {Infobox.raw_param('profession_b_level')}}, |
|||
smw_property = 'Profession Level B High', |
|||
} |
} |
||