Module:SoulUnlock

From Deadlock Wiki
Revision as of 02:24, 26 October 2024 by Sur (talk | contribs) (accumulate() initial)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview

Data for what is unlocked at each increment of Souls. Data is stored and loaded from Data:SoulUnlockData.json.

The data is accumulated into another format that is used by the currently written functions.

Functions

get_max

Retrieve's maximum value for a given key in the accumulated data

Examples

{{#invoke:SoulUnlock|get_max|RequiredSouls}} Script error: The function "get_max" does not exist.
{{#invoke:SoulUnlock|get_max|PowerIncrease}} Script error: The function "get_max" does not exist.
{{#invoke:SoulUnlock|get_max|AbilityUnlocks}} Script error: The function "get_max" does not exist.
{{#invoke:SoulUnlock|get_max|AbilityPoints}} Script error: The function "get_max" does not exist.

localize

Localize a key as its stored to the current language using Module:Lang.

Examples

{{#invoke:SoulUnlock|localize|RequiredSouls}} Script error: The function "localize" does not exist.
{{#invoke:SoulUnlock|localize|PowerIncrease}} Script error: The function "localize" does not exist.
{{#invoke:SoulUnlock|localize|AbilityUnlocks}} Script error: The function "localize" does not exist.
{{#invoke:SoulUnlock|localize|AbilityPoints}} Script error: The function "localize" does not exist.

write_accumulated

Writes the accumulated data to wikitext. Not a format that is ready to be displayed on a wiki page yet. Used for debugging for any lua editors working off of the accumulated data as opposed to the original data.

Note: the keys outputted are localized to english. See the localization map at the top of the Module source.

Example

{{#invoke:SoulUnlock|write_accumulated}}
Script error: The function "write_accumulated" does not exist.

write_table

Example

Script error: The function "write_table" does not exist.

Script error: The function "write_table" does not exist.


local p = {}
local soul_unlocks_data = mw.loadJsonData("Data:SoulUnlockData.json")

-- Accumulate the data from a list of entries of unlocks, AP, and PI's, to a hash with the # of each
local function accumulate() 
	local accumulated_data = {} --holds the sum at each gold count
	local sum_req_gold = 0
	local sums = {} --holds only the current sums
	
	for i, su_data in ipairs(soul_unlocks_data) do
		sum_req_gold = sum_req_gold + su_data["RequiredGold"]
		for key, value in pairs(su_data) do
			if key == "RequiredGold" then break end
			
			-- Determine how many to increase sum by
			local num
			if type(value) == 'boolean' then 
				if value == true then
					num = 1
				else
					num = 0
				end
			elseif type(value) == 'number' then 
				num = value 
			else
				return "Module:SoulUnlockaccumulate() error, invalid value type"
			end
			
			-- Increase the sum
			sums[key] = sums[key] + num
		end
		
		-- Add the current sum to accumulated_data
		accumulated_data[key] = sums
	end
end

return p