Module:SoulUnlock: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
m working version of accumulate()
Sur (talk | contribs)
m localization support
Line 2: Line 2:
local util_module = require('Module:Utilities')
local util_module = require('Module:Utilities')
local soul_unlocks_data = mw.loadJsonData("Data:SoulUnlockData.json")
local soul_unlocks_data = mw.loadJsonData("Data:SoulUnlockData.json")
local localization_map = {
["RequiredGold"] = "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
-- Accumulate the data from a list of entries of unlocks, AP, and PI's, to a hash with the # of each
Line 44: Line 51:


local accumulated_data = accumulate()
local accumulated_data = accumulate()
function p.localize(soul_unlock_key)
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(frame)
function p.write_accumulated(frame)
Line 50: Line 67:
ret = ret .. "Index" .. i .. ": "
ret = ret .. "Index" .. i .. ": "
for key, value in pairs(data) do
for key, value in pairs(data) do
ret = ret .. string.format("  %s:%s", key, value)
ret = ret .. string.format("  %s:%s, ", p.localize(key), value)
end
end
ret = ret .. '<br>'
ret = ret .. '<br>'

Revision as of 03:17, 26 October 2024

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}} Lua error at line 57: bad argument #2 to 'format' (string expected, got table).
{{#invoke:SoulUnlock|localize|PowerIncrease}} Lua error at line 57: bad argument #2 to 'format' (string expected, got table).
{{#invoke:SoulUnlock|localize|AbilityUnlocks}} Lua error at line 57: bad argument #2 to 'format' (string expected, got table).
{{#invoke:SoulUnlock|localize|AbilityPoints}} Lua error at line 57: bad argument #2 to 'format' (string expected, got table).

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: soul_unlock_key RequiredSouls not in localization_map:0, Ability Unlock:1,
Index2: soul_unlock_key RequiredSouls not in localization_map:400, Ability Unlock:2, Ability Points:1,
Index3: soul_unlock_key RequiredSouls not in localization_map:1200, Ability Unlock:2, Ability Points:2,
Index4: Ability Unlock:2, Power Increases:1, soul_unlock_key RequiredSouls not in localization_map:2400, Ability Points:2,
Index5: Ability Unlock:3, Power Increases:1, soul_unlock_key RequiredSouls not in localization_map:3900, Ability Points:2,
Index6: Ability Unlock:3, Power Increases:2, soul_unlock_key RequiredSouls not in localization_map:6100, Ability Points:3,
Index7: Ability Unlock:4, Power Increases:2, soul_unlock_key RequiredSouls not in localization_map:9100, Ability Points:3,
Index8: Ability Unlock:4, Power Increases:2, soul_unlock_key RequiredSouls not in localization_map:12600, Ability Points:4,
Index9: Ability Unlock:4, Power Increases:3, soul_unlock_key RequiredSouls not in localization_map:17100, Ability Points:5,
Index10: Ability Unlock:4, Power Increases:3, soul_unlock_key RequiredSouls not in localization_map:22300, Ability Points:6,
Index11: Ability Unlock:4, Power Increases:4, soul_unlock_key RequiredSouls not in localization_map:28300, Ability Points:7,
Index12: Ability Unlock:4, Power Increases:5, soul_unlock_key RequiredSouls not in localization_map:35800, Ability Points:8,
Index13: Ability Unlock:4, Power Increases:5, soul_unlock_key RequiredSouls not in localization_map:43800, Ability Points:9,
Index14: Ability Unlock:4, Power Increases:6, soul_unlock_key RequiredSouls not in localization_map:52800, Ability Points:10,
Index15: Ability Unlock:4, Power Increases:6, soul_unlock_key RequiredSouls not in localization_map:62500, Ability Points:11,
Index16: Ability Unlock:4, Power Increases:7, soul_unlock_key RequiredSouls not in localization_map:73000, Ability Points:12,
Index17: Ability Unlock:4, Power Increases:8, soul_unlock_key RequiredSouls not in localization_map:84500, Ability Points:13,
Index18: Ability Unlock:4, Power Increases:9, soul_unlock_key RequiredSouls not in localization_map:97000, Ability Points:14,
Index19: Ability Unlock:4, Power Increases:10, soul_unlock_key RequiredSouls not in localization_map:111000, Ability Points:15,
Index20: Ability Unlock:4, Power Increases:11, soul_unlock_key RequiredSouls not in localization_map:126000, Ability Points:15,
Index21: Ability Unlock:4, Power Increases:12, soul_unlock_key RequiredSouls not in localization_map:142000, Ability Points:16,
Index22: Ability Unlock:4, Power Increases:13, soul_unlock_key RequiredSouls not in localization_map:159000, Ability Points:17,
Index23: Ability Unlock:4, Power Increases:14, soul_unlock_key RequiredSouls not in localization_map:177000, Ability Points:18,
Index24: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:196000, Ability Points:19,
Index25: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:217500, Ability Points:20,
Index26: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:241000, Ability Points:21,
Index27: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:266500, Ability Points:22,
Index28: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:294000, Ability Points:23,
Index29: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:324000, Ability Points:24,
Index30: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:357000, Ability Points:25,
Index31: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:392000, Ability Points:26,
Index32: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:429000, Ability Points:27,
Index33: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:468000, Ability Points:28,
Index34: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:509000, Ability Points:29,
Index35: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:552000, Ability Points:30,
Index36: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:597000, Ability Points:31,
Index37: Ability Unlock:4, Power Increases:15, soul_unlock_key RequiredSouls not in localization_map:644000, Ability Points: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")
local localization_map = {
	["RequiredGold"] = "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: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.localize(soul_unlock_key)
	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(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, ", p.localize(key), value)	
		end
		ret = ret .. '<br>'
	end
	return ret
	--return accumulated_data['0']['AbilityUnlocks']
end

return p