Jump to content

Module:SoulUnlock

From The Deadlock Wiki
Revision as of 17:40, 26 October 2024 by Sur (talk | contribs) (RequiredGold > RequiredSouls)

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}} 45000
{{#invoke:SoulUnlock|get_max|PowerIncrease}} 32
{{#invoke:SoulUnlock|get_max|AbilityUnlocks}} 4
{{#invoke:SoulUnlock|get_max|AbilityPoints}} 29

localize

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

Examples

{{#invoke:SoulUnlock|localize|RequiredSouls}} Souls
{{#invoke:SoulUnlock|localize|PowerIncrease}} Boons
{{#invoke:SoulUnlock|localize|AbilityUnlocks}} Ability Unlock
{{#invoke:SoulUnlock|localize|AbilityPoints}} Ability Points

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: Souls:0, Ability Unlock:1,
Index2: Ability Unlock:1, Boons:1, Souls:300, Ability Points:1,
Index3: Ability Unlock:2, Boons:2, Souls:600, Ability Points:1,
Index4: Ability Unlock:2, Boons:3, Souls:900, Ability Points:2,
Index5: Ability Unlock:3, Boons:4, Souls:1500, Ability Points:2,
Index6: Ability Unlock:3, Boons:5, Souls:2200, Ability Points:3,
Index7: Ability Unlock:4, Boons:6, Souls:3000, Ability Points:3,
Index8: Ability Unlock:4, Boons:7, Souls:3800, Ability Points:4,
Index9: Ability Unlock:4, Boons:8, Souls:4600, Ability Points:5,
Index10: Ability Unlock:4, Boons:9, Souls:5400, Ability Points:6,
Index11: Ability Unlock:4, Boons:10, Souls:6200, Ability Points:7,
Index12: Ability Unlock:4, Boons:11, Souls:7100, Ability Points:8,
Index13: Ability Unlock:4, Boons:12, Souls:8000, Ability Points:9,
Index14: Ability Unlock:4, Boons:13, Souls:9000, Ability Points:10,
Index15: Ability Unlock:4, Boons:14, Souls:10200, Ability Points:11,
Index16: Ability Unlock:4, Boons:15, Souls:11600, Ability Points:12,
Index17: Ability Unlock:4, Boons:16, Souls:13200, Ability Points:13,
Index18: Ability Unlock:4, Boons:17, Souls:15000, Ability Points:14,
Index19: Ability Unlock:4, Boons:18, Souls:17000, Ability Points:15,
Index20: Ability Unlock:4, Boons:19, Souls:19000, Ability Points:16,
Index21: Ability Unlock:4, Boons:20, Souls:21000, Ability Points:17,
Index22: Ability Unlock:4, Boons:21, Souls:23000, Ability Points:18,
Index23: Ability Unlock:4, Boons:22, Souls:25000, Ability Points:19,
Index24: Ability Unlock:4, Boons:23, Souls:27000, Ability Points:20,
Index25: Ability Unlock:4, Boons:24, Souls:29000, Ability Points:21,
Index26: Ability Unlock:4, Boons:25, Souls:31000, Ability Points:22,
Index27: Ability Unlock:4, Boons:26, Souls:33000, Ability Points:23,
Index28: Ability Unlock:4, Boons:27, Souls:35000, Ability Points:24,
Index29: Ability Unlock:4, Boons:28, Souls:37000, Ability Points:25,
Index30: Ability Unlock:4, Boons:29, Souls:39000, Ability Points:26,
Index31: Ability Unlock:4, Boons:30, Souls:41000, Ability Points:27,
Index32: Ability Unlock:4, Boons:31, Souls:43000, Ability Points:28,
Index33: Ability Unlock:4, Boons:32, Souls:45000, Ability Points:29,

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")
local localization_map = {
	["RequiredSouls"] = "Citadel_Hero_Stats_Souls",
	["AbilityUnlocks"] = "Citadel_Player_Level_AbilityUnlock",
	["AbilityPoints"] = "guide_upgrades_killing_guardians_header",
	["PowerIncrease"] = "Citadel_Player_Level_PowerIncreases"
}
local lang_module = require('Module:Lang')

-- 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:SoulUnlock.accumulate() 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 == 'RequiredSouls' 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.localize(soul_unlock_key)
	-- If called internally (direct Lua call), args will be passed directly.
    -- If called from wikitext, `soul_unlock_key` 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(soul_unlock_key) == "table" and soul_unlock_key.args then
        local frame = soul_unlock_key
        soul_unlock_key = frame.args[1]
    end
	
	localization_key = localization_map[soul_unlock_key]
	if localization_key == nil then 
		return string.format("soul_unlock_key %s not in localization_map", soul_unlock_key)
	end
	
	-- Localize, nil for lang override, english string for fallback
	return lang_module.get_string(localization_key, nil, 'en')
end

function p.write_accumulated()
	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, ", p.localize(key), value)	
		end
		ret = ret .. '<br>'
	end
	return ret
	--return accumulated_data['0']['AbilityUnlocks']
end

-- Retrieve a certain stat's value at max souls
function p.get_max(soul_unlock_key)
	-- If called internally (direct Lua call), args will be passed directly.
    -- If called from wikitext, `soul_unlock_key` 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(soul_unlock_key) == "table" and soul_unlock_key.args then
        local frame = soul_unlock_key
        soul_unlock_key = frame.args[1]
    end
	
	last_index = #accumulated_data
	last_value = accumulated_data[last_index][soul_unlock_key]
	return last_value
end

return p