Module:SoulUnlock

From Deadlock Wiki
Revision as of 03:04, 26 October 2024 by Sur (talk | contribs) (working version of accumulate())
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}}
Index1: RequiredSouls:0 AbilityUnlocks:1
Index2: RequiredSouls:400 AbilityUnlocks:2 AbilityPoints:1
Index3: RequiredSouls:1200 AbilityUnlocks:2 AbilityPoints:2
Index4: AbilityUnlocks:2 PowerIncrease:1 RequiredSouls:2400 AbilityPoints:2
Index5: AbilityUnlocks:3 PowerIncrease:1 RequiredSouls:3900 AbilityPoints:2
Index6: AbilityUnlocks:3 PowerIncrease:2 RequiredSouls:6100 AbilityPoints:3
Index7: AbilityUnlocks:4 PowerIncrease:2 RequiredSouls:9100 AbilityPoints:3
Index8: AbilityUnlocks:4 PowerIncrease:2 RequiredSouls:12600 AbilityPoints:4
Index9: AbilityUnlocks:4 PowerIncrease:3 RequiredSouls:17100 AbilityPoints:5
Index10: AbilityUnlocks:4 PowerIncrease:3 RequiredSouls:22300 AbilityPoints:6
Index11: AbilityUnlocks:4 PowerIncrease:4 RequiredSouls:28300 AbilityPoints:7
Index12: AbilityUnlocks:4 PowerIncrease:5 RequiredSouls:35800 AbilityPoints:8
Index13: AbilityUnlocks:4 PowerIncrease:5 RequiredSouls:43800 AbilityPoints:9
Index14: AbilityUnlocks:4 PowerIncrease:6 RequiredSouls:52800 AbilityPoints:10
Index15: AbilityUnlocks:4 PowerIncrease:6 RequiredSouls:62500 AbilityPoints:11
Index16: AbilityUnlocks:4 PowerIncrease:7 RequiredSouls:73000 AbilityPoints:12
Index17: AbilityUnlocks:4 PowerIncrease:8 RequiredSouls:84500 AbilityPoints:13
Index18: AbilityUnlocks:4 PowerIncrease:9 RequiredSouls:97000 AbilityPoints:14
Index19: AbilityUnlocks:4 PowerIncrease:10 RequiredSouls:111000 AbilityPoints:15
Index20: AbilityUnlocks:4 PowerIncrease:11 RequiredSouls:126000 AbilityPoints:15
Index21: AbilityUnlocks:4 PowerIncrease:12 RequiredSouls:142000 AbilityPoints:16
Index22: AbilityUnlocks:4 PowerIncrease:13 RequiredSouls:159000 AbilityPoints:17
Index23: AbilityUnlocks:4 PowerIncrease:14 RequiredSouls:177000 AbilityPoints:18
Index24: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:196000 AbilityPoints:19
Index25: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:217500 AbilityPoints:20
Index26: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:241000 AbilityPoints:21
Index27: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:266500 AbilityPoints:22
Index28: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:294000 AbilityPoints:23
Index29: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:324000 AbilityPoints:24
Index30: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:357000 AbilityPoints:25
Index31: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:392000 AbilityPoints:26
Index32: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:429000 AbilityPoints:27
Index33: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:468000 AbilityPoints:28
Index34: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:509000 AbilityPoints:29
Index35: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:552000 AbilityPoints:30
Index36: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:597000 AbilityPoints:31
Index37: AbilityUnlocks:4 PowerIncrease:15 RequiredSouls:644000 AbilityPoints:32

write_table

Example

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

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


local p = {}
local util_module = require('Module:Utilities')
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 sums = {} --holds only the current sums
	
	for i, su_data in ipairs(soul_unlocks_data) do
		for key, value in pairs(su_data) do
			-- 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
			
			
			-- Start at 0
			if sums[key] == nil then sums[key] = 0 end
			
			-- Sum the value, but not for gold because its already summed
			if key == 'RequiredGold' then
				sums[key] = num
			else
				sums[key] = sums[key] + num
			end
		end
		
		-- Add the current sum to accumulated_data
		table.insert(accumulated_data, util_module.deep_copy(sums))
	end
	
	return accumulated_data
end

local accumulated_data = accumulate()

function p.write_accumulated(frame)
	ret = ""
	for i, data in pairs(accumulated_data) do
		ret = ret .. "Index" .. i .. ": "
		for key, value in pairs(data) do
			ret = ret .. string.format("  %s:%s", key, value)	
		end
		ret = ret .. '<br>'
	end
	return ret
	--return accumulated_data['0']['AbilityUnlocks']
end

return p