Module:ItemData/nav: Difference between revisionsGive feedback
m get_item_nav_cards -> get_item_nav_bulletpoints |
m extracted logic to write_wrapped_item_list; get_item_nav_bulletpoints and get_item_nav_cards now more streamlined |
||
| Line 3: | Line 3: | ||
local lang_module = require('Module:Lang') | local lang_module = require('Module:Lang') | ||
-- | --With debug_mode on, it outputs unprocessed wikitext | ||
function | --With debug_mode off/unspecified, it processes the wikitext | ||
local function process_debug_mode(wikitext, debug_mode) | |||
if debug_mode == 'true' then | |||
local max_souls | return wikitext | ||
elseif debug_mode == 'false' or debug_mode == nil then | |||
return mw.getCurrentFrame():preprocess(wikitext) | |||
else | |||
return "debug_mode must be 'true' or 'false'" | |||
end | |||
end | |||
--Writes list of items of a certain slot within the min and max soul bounds | |||
-- Each item is wrapped and separated. For example of wrapping/separator, see | |||
-- get_item_nav_bulletpoints. 'sep' should not be combined with 'right_wrap', | |||
-- as the trailing separator should also be removed from the string | |||
local function write_wrapped_item_list(slot, min_souls, max_souls, left_wrap, right_wrap, sep) | |||
if slot ~= 'Weapon' and slot ~= 'Armor' and slot ~= 'Tech' then | if slot ~= 'Weapon' and slot ~= 'Armor' and slot ~= 'Tech' then | ||
return 'slot must be Weapon, Armor (Vitality), or Tech (Spirit)' | return 'slot must be Weapon, Armor (Vitality), or Tech (Spirit)' | ||
| Line 18: | Line 30: | ||
local items = {} | local items = {} | ||
for item_key, item_data in pairs(items_data) do | for item_key, item_data in pairs(items_data) do | ||
--future proofing; Disabled will be renamed to IsDisabled soon | |||
if item_data['Disabled'] == nil and item_data['IsDisabled'] ~= nil then | if item_data['Disabled'] == nil and item_data['IsDisabled'] ~= nil then | ||
return "REMINDER: 'Disabled' was renamed to 'IsDisabled'" | return "REMINDER: 'Disabled' was renamed to 'IsDisabled'" | ||
end | end | ||
local | |||
local | local this_cost = tonumber(item_data["Cost"]) | ||
if item_data["Name"] ~= nil and item_data["Disabled"] == false and | local this_slot = item_data["Slot"] | ||
if slot == | if item_data["Name"] ~= nil and item_data["Disabled"] == false and this_cost ~= nil and this_slot ~= nil then | ||
if slot == this_slot and this_cost>=min_souls and this_cost<max_souls then | |||
table.insert(items, lang_module.get_string(item_key)) | table.insert(items, lang_module.get_string(item_key)) | ||
end | end | ||
| Line 36: | Line 48: | ||
--Add each item to output | --Add each item to output | ||
-- Each item is surrounded by left and right wrap, and separated by sep | |||
local ret = '' | local ret = '' | ||
for index, item_name in ipairs(items) do | for index, item_name in ipairs(items) do | ||
ret = ret .. | ret = ret .. left_wrap .. item_name .. right_wrap .. sep | ||
end | end | ||
--Remove the last | --Remove the last separator thats trailing after the last item | ||
ret = string.sub(ret, 1, -(string.len(' • '))-1) | ret = string.sub(ret, 1, -(string.len(sep))-1) | ||
return ret | |||
end | |||
-- for [[Template:Item Navbox]] | |||
function p.get_item_nav_bulletpoints(frame) | |||
local slot = frame.args[1] | |||
local min_souls = frame.args[2] | |||
local max_souls = frame.args[3] | |||
local debug_mode = frame.args["debug_mode"] | |||
local left_wrap = '{{ItemIcon|' | |||
local right_wrap = '}}' | |||
local sep = ' • ' | |||
local item_list = write_wrapped_item_list(slot, min_souls, max_souls, left_wrap, right_wrap, sep) | |||
return process_debug_mode(item_list, debug_mode) | |||
end | |||
-- for [[Template:Infobox ShopItems]] | |||
function p.get_item_nav_cards(frame) | |||
local slot = frame.args[1] | |||
local min_souls = frame.args[2] | |||
local max_souls = frame.args[3] | |||
local debug_mode = frame.args["debug_mode"] | |||
local left_wrap = '{{ItemBox|item_name=' | |||
local right_wrap = '}}' | |||
local sep = ' ' | |||
local item_list = write_wrapped_item_list(slot, min_souls, max_souls, left_wrap, right_wrap, sep) | |||
return | return process_debug_mode(item_list, debug_mode) | ||
end | end | ||
return p | return p | ||