Home
Random
Log in
Settings
About the Deadlock Wiki
Search
Editing
Module:SoulUnlock
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local util_module = require('Module:Utilities') local dictionary_module = require('Module:Dictionary') 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 function to_tick(bool) if bool == nil or not bool then return '' else return '{{Tick}}' end end function p.write_table(frame) local debug_mode = frame.args['debug_mode'] if debug_mode == nil then debug_mode = false end local ret = '' -- Add header categories local tr = '' tr = tr .. '<th>' .. '' .. '</th>' tr = tr .. '<th colspan="3">' .. dictionary_module.translate('Individual') .. '</th>' tr = tr .. '<th colspan="3">' .. dictionary_module.translate('Accumulative') .. '</th>' ret = ret .. '<tr>' .. tr .. '</tr>' -- Add header record, will be soul + each other record twice local required_souls_header = '<th>' .. p.localize('RequiredSouls') .. '</th>' local non_souls_tr = '' for su_key, lang_key in pairs(localization_map) do if su_key ~= 'RequiredSouls' then non_souls_tr = non_souls_tr .. '<th>' .. p.localize(su_key) .. '</th>' end end local tr = '<tr>' .. required_souls_header .. non_souls_tr .. non_souls_tr .. '</tr>' ret = ret .. tr -- Add data agg_records for i, agg_record in ipairs(accumulated_data) do local tr = '' -- Retrieve souls agg_record local required_souls = agg_record['RequiredSouls'] local souls_str = '{{Souls|' .. required_souls .. '}}' tr = tr .. '<td>' .. souls_str .. '</td>' -- Retrieve non-aggregate agg_record local non_agg_record = soul_unlocks_data[i] for su_key, lang_key in pairs(localization_map) do if su_key ~= 'RequiredSouls' then local value = to_tick(non_agg_record[su_key]) td = '<td>' .. value .. '</td>' tr = tr .. td end end -- Retrieve aggregate agg_record for su_key, lang_key in pairs(localization_map) do if su_key ~= 'RequiredSouls' then local value = agg_record[su_key] -- Display blank instead of nil if missing if value == nil then value = '' end td = '<td>' .. value .. '</td>' tr = tr .. td end end ret = ret .. '<tr>' .. tr .. '</tr>' end ret = '<table class="wikitable defaultcenter" style="text-align:center">' .. ret .. '</table>' if debug_mode then return ret else return frame:preprocess(ret) end end return p
Summary:
Please note that all contributions to Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Deadlock:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Templates used on this page:
Data:Dictionary
(
edit
)
Data:LangCodes.json
(
edit
)
Data:Lang en.json
(
edit
)
Data:SoulUnlockData.json
(
edit
)
Template:Souls
(
edit
)
Template:Tick
(
edit
)
Module:Dictionary
(
edit
)
Module:Lang
(
edit
)
Module:SoulUnlock
(
edit
)
Module:SoulUnlock/doc
(
edit
)
Module:Utilities
(
edit
)