Module:SoulUnlock: Difference between revisions
m invoke for accumulated_data |
m save accumulated_data after function definition |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local soul_unlocks_data = mw.loadJsonData("Data:SoulUnlockData.json") | 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 | -- Accumulate the data from a list of entries of unlocks, AP, and PI's, to a hash with the # of each | ||
Line 38: | Line 37: | ||
return accumulated_data | return accumulated_data | ||
end | end | ||
local accumulated_data = accumulate() | |||
local function write_accumulated(frame) | local function write_accumulated(frame) |
Revision as of 02:28, 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}}
Lua error at line 11: attempt to perform arithmetic on field 'RequiredGold' (a nil value).
{{#invoke:SoulUnlock|get_max|PowerIncrease}}
Lua error at line 11: attempt to perform arithmetic on field 'RequiredGold' (a nil value).
{{#invoke:SoulUnlock|get_max|AbilityUnlocks}}
Lua error at line 11: attempt to perform arithmetic on field 'RequiredGold' (a nil value).
{{#invoke:SoulUnlock|get_max|AbilityPoints}}
Lua error at line 11: attempt to perform arithmetic on field 'RequiredGold' (a nil value).
localize
Localize a key as its stored to the current language using Module:Lang.
Examples
{{#invoke:SoulUnlock|localize|RequiredSouls}}
Lua error at line 11: attempt to perform arithmetic on field 'RequiredGold' (a nil value).
{{#invoke:SoulUnlock|localize|PowerIncrease}}
Lua error at line 11: attempt to perform arithmetic on field 'RequiredGold' (a nil value).
{{#invoke:SoulUnlock|localize|AbilityUnlocks}}
Lua error at line 11: attempt to perform arithmetic on field 'RequiredGold' (a nil value).
{{#invoke:SoulUnlock|localize|AbilityPoints}}
Lua error at line 11: attempt to perform arithmetic on field 'RequiredGold' (a nil value).
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}}
Lua error at line 11: attempt to perform arithmetic on field 'RequiredGold' (a nil value).
write_table
Example
Lua error at line 11: attempt to perform arithmetic on field 'RequiredGold' (a nil value).
Lua error at line 11: attempt to perform arithmetic on field 'RequiredGold' (a nil value).
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
return accumulated_data
end
local accumulated_data = accumulate()
local function write_accumulated(frame)
return accumulated_data
end
return p