Toggle menu
517
2.5K
889
23.2K
Deadlock Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:ItemData/nav: Difference between revisions

From Deadlock Wiki
Sur (talk | contribs)
m extracted logic to write_wrapped_item_list; get_item_nav_bulletpoints and get_item_nav_cards now more streamlined
m Reverted edit by 149.28.42.29 (talk) to last revision by Sur
Tag: Rollback
(12 intermediate revisions by 2 users not shown)
Line 2: Line 2:
local items_data = mw.loadJsonData("Data:ItemData.json")
local items_data = mw.loadJsonData("Data:ItemData.json")
local lang_module = require('Module:Lang')
local lang_module = require('Module:Lang')
local generic_module = require('Module:GenericData')
local util_module = require('Module:Utilities')


--With debug_mode on, it outputs unprocessed wikitext
--With debug_mode on, it outputs unprocessed wikitext
Line 23: Line 25:
return 'slot must be Weapon, Armor (Vitality), or Tech (Spirit)'
return 'slot must be Weapon, Armor (Vitality), or Tech (Spirit)'
end
end
local min_souls = tonumber(min_souls)
local min_souls = tonumber(min_souls)
local max_souls = tonumber(max_souls)
local max_souls = tonumber(max_souls)
Line 31: Line 34:
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
--future proofing; Disabled will be renamed to IsDisabled soon
if item_data['Disabled'] == nil and item_data['IsDisabled'] ~= nil then
return "REMINDER: 'Disabled' was renamed to 'IsDisabled'"
end
local this_cost = tonumber(item_data["Cost"])
local this_cost = tonumber(item_data["Cost"])
local this_slot = item_data["Slot"]
local this_slot = item_data["Slot"]
if item_data["Name"] ~= nil and item_data["Disabled"] == false and this_cost ~= nil and this_slot ~= nil then
if item_data["Name"] ~= nil and item_data["IsDisabled"] == 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
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))
Line 61: Line 60:


-- for [[Template:Item Navbox]]
-- for [[Template:Item Navbox]]
function p.get_item_nav_bulletpoints(frame)
function p.get_item_nav_bulletpoints(slot, min_souls, max_souls, debug_mode)
local slot = frame.args[1]
-- If called internally (direct Lua call), args will be passed directly.
local min_souls = frame.args[2]
    -- If called from wikitext, `slot` will be the `frame` object, and we get args from `frame.args`.
local max_souls = frame.args[3]
 
local debug_mode = frame.args["debug_mode"]
    -- Handle the case where it's called via #invoke (i.e., from wikitext)
    if type(slot) == "table" and slot.args then
        local frame = slot
        slot = frame.args[1]
        min_souls = frame.args[2]
        max_souls = frame.args[3]
        debug_mode = frame.args["debug_mode"]
    end
local left_wrap = '{{ItemIcon|'
local left_wrap = '{{ItemIcon|'
local right_wrap = '}}'
local right_wrap = '}}'
Line 76: Line 83:


-- for [[Template:Infobox ShopItems]]
-- for [[Template:Infobox ShopItems]]
function p.get_item_nav_cards(frame)
function p.get_item_nav_cards(slot, min_souls, max_souls, debug_mode)
local slot = frame.args[1]
-- If called internally (direct Lua call), args will be passed directly.
local min_souls = frame.args[2]
    -- If called from wikitext, `slot` will be the `frame` object, and we get args from `frame.args`.
local max_souls = frame.args[3]
 
local debug_mode = frame.args["debug_mode"]
    -- Handle the case where it's called via #invoke (i.e., from wikitext)
    if type(slot) == "table" and slot.args then
        local frame = slot
        slot = frame.args[1]
        min_souls = frame.args[2]
        max_souls = frame.args[3]
        debug_mode = frame.args["debug_mode"]
    end
local left_wrap = '{{ItemBox|item_name='
local left_wrap = '{{ItemBox|item_name='
local right_wrap = '}}'
local right_wrap = '}}'
Line 88: Line 103:
return process_debug_mode(item_list, debug_mode)
return process_debug_mode(item_list, debug_mode)
end
function p.write_item_slot_subgroup(frame)
local slot = frame.args[1]
local type = frame.args[2]
local debug_mode = frame.args['debug_mode']
if slot == nil then return "'slot' parameter is required" end
-- Define base args
local template_title = "Navbox subgroup"
local template_args = {
["groupstyle"] = "background-color:" .. util_module.get_slot_color(slot) .. ";width:10%;min-width:70px;border-radius: 8px 0 0 8px",
["grouppadding"] = "5px",
["listpadding"] = "0 0.25rem",
}
local soul_style = "font-size: 12px; text-shadow: 1px 1px rgba(0, 0, 0, 0.3);"
local prices = generic_module.get_item_price_per_tier()
for i, souls in ipairs(prices) do
--Determine lower bound for soul
min_souls = souls
--Skip 0 to i1 as no items cost less than 500
if min_souls ~= 0 then
-- Determine upper bound
max_souls = prices[i+1]
if max_souls == nil then
max_souls = min_souls * 10 --essentially have no upper bound
end
--Create the subgroup
template_args["group" .. (i-1)] = frame:expandTemplate{title="Souls", args={[1] = min_souls, ["Shadow"] = soul_style}}
local list
if type=='get_item_nav_cards' then
list = p.get_item_nav_cards(slot, min_souls, max_souls, debug_mode)
elseif type=='get_item_nav_bulletpoints' then
list = p.get_item_nav_bulletpoints(slot, min_souls, max_souls, debug_mode)
else
return "'type' should be get_item_nav_cards or get_item_nav_bulletpoints"
end
template_args["list" .. (i-1)] =  list
end
end
return frame:expandTemplate{title=template_title, args=template_args}
end
end


return p
return p