Module:ItemData/nav: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
m reverting failed attempt- Undo revision 13674 by Sur (talk)
Tag: Undo
Sur (talk | contribs)
m write_item_slot_subgroup initial
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')


--With debug_mode on, it outputs unprocessed wikitext
--With debug_mode on, it outputs unprocessed wikitext
Line 76: Line 77:


-- 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]
        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 95:
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 debug_mode = frame.args['debug_mode']
if slot == nil then return "'slot' parameter is required" end
local ret = ''
local prices = generic_module.get_item_price_per_tier()
for i, souls in ipairs(prices) do
--Determine lower and upper bound for soul
min_souls = souls
max_souls = prices[i+1]
if max_souls == nil then
max_souls = min_souls * 10 --essentially have no upper bound
end
ret = ret .. "|group" .. i .. "={{Souls|500|Shadow=here}}"
ret = ret .. "|list" .. i .. "=" .. p.get_item_nav_cards(slot, min_souls, max_souls)
end
return process_debug_mode(ret, debug_mode)
end
end


return p
return p

Revision as of 17:26, 1 November 2024

Overview

Functions for creating navigation boxes/lists for items, grouped by a slot/category and souls

Functions

get_item_nav_bulletpoints

Gets a list of items that are each sent to the Template:ItemIcon template, separated by bullet points.

Filters down to a slot/specific category, and within a range of souls.

Parameters

  • slot - Slot/category that the items should be, should be Weapon, Armor, or Tech
  • min_souls - Minimum souls that the items should have
  • max_souls - Maximum souls that the items should have
  • debug_mode - (OPTIONAL) - if set to 'true', the wikitext is unprocessed, allowing for it to be read more clearly. Also used for showcasing the documentation examples more clearly.

Examples

With debug_mode on (for illustration purposes) {{#invoke:ItemData/nav|get_item_nav_bulletpoints|Armor|1250|3000|debug_mode=true}}

{{ItemIcon|Bullet Armor}} • {{ItemIcon|Bullet Lifesteal}} • {{ItemIcon|Combat Barrier}} • {{ItemIcon|Debuff Reducer}} • {{ItemIcon|Divine Barrier}} • {{ItemIcon|Enchanter's Barrier}} • {{ItemIcon|Enduring Speed}} • {{ItemIcon|Healbane}} • {{ItemIcon|Healing Booster}} • {{ItemIcon|Healing Nova}} • {{ItemIcon|Reactive Barrier}} • {{ItemIcon|Restorative Locket}} • {{ItemIcon|Return Fire}} • {{ItemIcon|Spirit Armor}} • {{ItemIcon|Spirit Lifesteal}}


With debug_mode off {{#invoke:ItemData/nav|get_item_nav_bulletpoints|Armor|1250|3000}}

Bullet Armor Bullet Lifesteal Combat Barrier Debuff Reducer Divine Barrier Enchanter's Barrier Enduring Speed Healbane Healing Booster Healing Nova Reactive Barrier Restorative Locket Return Fire Spirit Armor Spirit Lifesteal

get_item_nav_cards

Gets a list of items that are each sent to the Template:ItemBox template, separated by space.

Filters down to a specific slot/category, and within a range of souls.

Parameters

Same as get_item_nav_bulletpoints

Examples

With debug_mode on (for illustration purposes) {{#invoke:ItemData/nav|get_item_nav_bulletpoints|Armor|1250|3000|debug_mode=true}}

Min/Max souls must be numerical


With debug_mode off {{#invoke:ItemData/nav|get_item_nav_bulletpoints|Armor|1250|3000}}

Min/Max souls must be numerical

write_item_slot_subgroup

Writes a sub group for the navbox on Template:Item Navbox and Template:Infobox ShopItems. The sub group contains all items in each price range from "ItemPricePerTier" in Data:GenericData.json

Parameters

  • slot - Slot/category to create the subgroup for, ie Weapon, Armor, or Tech
  • type - The subfunction to call that determines the list formatting style. Options are 'get_item_nav_bulletpoints' or 'get_item_nav_cards'
  • debug_mode - (OPTIONAL) - if set to 'true', the wikitext is unprocessed, allowing for it to be read more clearly. Also used for showcasing the documentation examples more clearly.

Examples

With debug_mode on (for illustration purposes) {{#invoke:ItemData/nav|write_item_slot_subgroup|Weapon|get_item_nav_bulletpoints|debug_mode=true}}

|group1={{Souls|500|Shadow=here}}|list1=|group2={{Souls|500|Shadow=here}}|list2=

Souls500
Rapid Rounds

|group3={{Souls|500|Shadow=here}}|list3=

Souls1,250
Active Reload
Souls1,250
Berserker
Souls1,250
ACTIVE
Fleetfoot
Souls1,250
Kinetic Dash
Souls1,250
Long Range
Souls1,250
Melee Charge
Souls1,250
Mystic Shot
Souls1,250
Slowing Bullets
Souls1,250
Swift Striker

|group4={{Souls|500|Shadow=here}}|list4=

Souls3,000
ACTIVE
Alchemical Fire
Souls3,000
Burst Fire
Souls3,500

Headhunter
Souls3,000
ACTIVE
Heroic Aura
Souls3,000
Hunter's Aura
Souls3,500

Point Blank
Souls3,500

Pristine Emblem
Souls4,250

Sharpshooter
Souls3,000
Tesla Bullets
Souls3,500

Titanic Magazine
Souls3,000
Toxic Bullets
Souls3,000
ACTIVE
Warp Stone

|group5={{Souls|500|Shadow=here}}|list5=

Souls6,200
Frenzy
Souls6,200
Glass Cannon
Souls6,200
Lucky Shot
Souls6,200
Ricochet
Souls6,200
ACTIVE
Shadow Weave
Souls7,450
ACTIVE

Silencer
Souls6,200
ACTIVE
Vampiric Burst


With debug_mode off {{#invoke:ItemData/nav|write_item_slot_subgroup|Weapon|get_item_nav_bulletpoints}}

|group1=Souls500|list1=|group2=Souls500|list2=

Souls500
Rapid Rounds

|group3=Souls500|list3=

Souls1,250
Active Reload
Souls1,250
Berserker
Souls1,250
ACTIVE
Fleetfoot
Souls1,250
Kinetic Dash
Souls1,250
Long Range
Souls1,250
Melee Charge
Souls1,250
Mystic Shot
Souls1,250
Slowing Bullets
Souls1,250
Swift Striker

|group4=Souls500|list4=

Souls3,000
ACTIVE
Alchemical Fire
Souls3,000
Burst Fire
Souls3,500

Headhunter
Souls3,000
ACTIVE
Heroic Aura
Souls3,000
Hunter's Aura
Souls3,500

Point Blank
Souls3,500

Pristine Emblem
Souls4,250

Sharpshooter
Souls3,000
Tesla Bullets
Souls3,500

Titanic Magazine
Souls3,000
Toxic Bullets
Souls3,000
ACTIVE
Warp Stone

|group5=Souls500|list5=

Souls6,200
Frenzy
Souls6,200
Glass Cannon
Souls6,200
Lucky Shot
Souls6,200
Ricochet
Souls6,200
ACTIVE
Shadow Weave
Souls7,450
ACTIVE

Silencer
Souls6,200
ACTIVE
Vampiric Burst

Recall that it creates subgroup parameters for the mentioned templates.


local p = {}
local items_data = mw.loadJsonData("Data:ItemData.json")
local lang_module = require('Module:Lang')
local generic_module = require('Module:GenericData')

--With debug_mode on, it outputs unprocessed wikitext
--With debug_mode off/unspecified, it processes the wikitext
local function process_debug_mode(wikitext, debug_mode)
	if debug_mode == 'true' then
		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
		return 'slot must be Weapon, Armor (Vitality), or Tech (Spirit)'
	end
	local min_souls = tonumber(min_souls)
	local max_souls = tonumber(max_souls)
	if min_souls == nil or max_souls == nil then return 'Min/Max souls must be numerical' end
	
	--Retrieve all items that fit the bounds
	local items = {}
	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 
			return "REMINDER: 'Disabled' was renamed to 'IsDisabled'"
		end
		
		local this_cost = tonumber(item_data["Cost"])
		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 slot == this_slot and this_cost>=min_souls and this_cost<max_souls then
				table.insert(items, lang_module.get_string(item_key))
			end
		end
	end
	
	--Order list alphabetically
	table.sort(items) --O(nlogn)
	
	--Add each item to output
	-- Each item is surrounded by left and right wrap, and separated by sep
	local ret = ''
	for index, item_name in ipairs(items) do
		ret = ret .. left_wrap .. item_name .. right_wrap .. sep
	end
	
	--Remove the last separator thats trailing after the last item
	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 = ' &bull; '
	
	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(slot, min_souls, max_souls, debug_mode)
	-- If called internally (direct Lua call), args will be passed directly.
    -- If called from wikitext, `slot` will be the `frame` object, and we get args from `frame.args`.

    -- 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]
        debug_mode = frame.args["debug_mode"]
    end
	
	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 process_debug_mode(item_list, debug_mode)
end

function p.write_item_slot_subgroup(frame)
	local slot = frame.args[1]
	local debug_mode = frame.args['debug_mode']
	if slot == nil then return "'slot' parameter is required" end
	
	local ret = ''
	local prices = generic_module.get_item_price_per_tier()
	for i, souls in ipairs(prices) do
		--Determine lower and upper bound for soul
		min_souls = souls
		max_souls = prices[i+1]
		if max_souls == nil then 
			max_souls = min_souls * 10 --essentially have no upper bound
		end
		ret = ret .. "|group" .. i .. "={{Souls|500|Shadow=here}}"
		ret = ret .. "|list" .. i .. "=" .. p.get_item_nav_cards(slot, min_souls, max_souls)
	end
	
	return process_debug_mode(ret, debug_mode)
end

return p