Module:GenericData: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
get_objective_param, get_rejuv_param, get_tiered_item_price initial
 
Sur (talk | contribs)
m get_item_price_per_tier for external use by Module:ItemData/nav
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
if key == nil then return "'key' parameter must be provided" end
if key == nil then return "'key' parameter must be provided" end
objective_params = generics_data['ObjectiveParams']
local objective_params = generics_data['ObjectiveParams']
objective_param = objective_params[key]
local objective_param = objective_params[key]
if objective_param == nil then
if objective_param == nil then
return "'key':" .. key .. " is not in ObjectiveParams"
return "'key':" .. key .. " is not in ObjectiveParams"
Line 23: Line 23:
-- Access the key
-- Access the key
rejuv_params = generics_data['RejuvParams']
local rejuv_params = generics_data['RejuvParams']
rejuv_param = rejuv_params[key]
local rejuv_param = rejuv_params[key]
-- Ensure the key is in the data
-- Ensure the key is in the data
Line 57: Line 57:
-- Retrieve the tier'th element
-- Retrieve the tier'th element
for i, elem in ipairs(generics_data["ItemPricePerTier"]) do
for i, elem in ipairs(p.get_item_price_per_tier()) do
if i == tier then
if i == tier then
return elem
return elem
Line 63: Line 63:
end
end
return "ItemPricePerTier does not have " .. tier .. " tiers"
return "ItemPricePerTier does not have " .. tier .. " tiers"
end
--for Module:ItemData/nav
function p.get_item_price_per_tier()
return generics_data['ItemPricePerTier']
end
end




return p
return p

Latest revision as of 14:48, 1 November 2024

Overview[edit source]

Provides access to generic/miscellaneous data from Data:GenericData.json

Functions[edit source]

get_objective_param[edit source]

Provides access to "ObjectiveParams" data.

Parameters[edit source]

  • key - key to access

Examples[edit source]

{{#invoke:GenericData|get_objective_param|GoldPerOrb}}

40

get_rejuv_param[edit source]

Provides access to "RejuvParams" data.

Parameters[edit source]

  • key - key to access
  • midboss_deaths - (OPTIONAL) list index to access that represents how many times midboss has died, if the provided key's value is a list

Examples[edit source]

{{#invoke:GenericData|get_rejuv_param|RejuvinatorExpirationWarningTiming}}

30

{{#invoke:GenericData|get_rejuv_param|TrooperHealthMult|3}}

1.9

get_tiered_item_price[edit source]

Provides access to "ItemPricePerTier" data.

Parameters[edit source]

  • tier - list index to access that represents the tier of the item

Examples[edit source]

{{#invoke:GenericData|get_tiered_item_price|5}}

6200


local generics_data = mw.loadJsonData("Data:GenericData.json")
local p = {}
	
function p.get_objective_param(frame)
	local key = frame.args[1]
	if key == nil then return "'key' parameter must be provided" end
	
	local objective_params = generics_data['ObjectiveParams']
	local objective_param = objective_params[key]
	if objective_param == nil then
		return "'key':" .. key .. " is not in ObjectiveParams"
	end
	return objective_param
end

function p.get_rejuv_param(frame)
	local key = frame.args[1]
	local midboss_deaths = frame.args[2]
	if key == nil then return "'key' parameter must be provided" end
	if midboss_deaths ~= nil and tonumber(midboss_deaths) == nil then
		return "'midboss_deaths' parameter must be an integer"
	end
	
	-- Access the key
	local rejuv_params = generics_data['RejuvParams']
	local rejuv_param = rejuv_params[key]
	
	-- Ensure the key is in the data
	if rejuv_param == nil then
		return "'key':" .. key .. " is not in RejuvParams"
	end
	
	-- If its a non-container, return it
	if (type(rejuv_param) == 'number' or 
		type(rejuv_param) == 'string' or 
		type(rejuv_param) == 'boolean') then
		return rejuv_param
	end
	
	-- Ensure an midboss_deaths is provided
	if midboss_deaths == nil then return "'key':" .. key .. "'s value is an array, so the 'midboss_deaths' parameter must be provided" end
	midboss_deaths = tonumber(midboss_deaths)
	
	-- Retrieve the midboss_deaths'th element
	for i, elem in ipairs(rejuv_param) do
		if i == midboss_deaths then
			return elem
		end
	end
	return "'key':" .. key .. "'s array value did not contain " .. midboss_deaths .. " elements"
end

function p.get_tiered_item_price(frame)
	local tier = frame.args[1]
	if tier == nil then return "'tier' parameter must be provided" end
	tier = tonumber(tier)
	
	-- Retrieve the tier'th element
	for i, elem in ipairs(p.get_item_price_per_tier()) do
		if i == tier then
			return elem
		end
	end
	return "ItemPricePerTier does not have " .. tier .. " tiers"
end

--for Module:ItemData/nav
function p.get_item_price_per_tier()
	return generics_data['ItemPricePerTier']
end


return p