Module:SoulUnlock: Difference between revisionsGive feedback
m get_max example and parameters now support invoke options |
Gammaton32 (talk | contribs) No edit summary |
||
| (8 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local util_module = require('Module:Utilities') | local util_module = require('Module:Utilities') | ||
local dictionary_module = require('Module:Dictionary') | |||
local soul_unlocks_data = mw.loadJsonData("Data:SoulUnlockData.json") | local soul_unlocks_data = mw.loadJsonData("Data:SoulUnlockData.json") | ||
local localization_map = { | local localization_map = { | ||
[" | ["RequiredSouls"] = "Citadel_Hero_Stats_Souls", | ||
["AbilityUnlocks"] = "Citadel_Player_Level_AbilityUnlock", | ["AbilityUnlocks"] = "Citadel_Player_Level_AbilityUnlock", | ||
["AbilityPoints"] = "guide_upgrades_killing_guardians_header", | ["AbilityPoints"] = "guide_upgrades_killing_guardians_header", | ||
| Line 36: | Line 37: | ||
-- Sum the value, but not for gold because its already summed | -- Sum the value, but not for gold because its already summed | ||
if key == ' | if key == 'RequiredSouls' then | ||
sums[key] = num | sums[key] = num | ||
else | else | ||
| Line 76: | Line 77: | ||
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, ", p.localize(key), | local display_value = value | ||
--Add 600 | |||
if key == "RequiredSouls" then | |||
display_value = display_value + 600 | |||
end | |||
ret = ret .. string.format(" %s:%s, ", p.localize(key), display_value) | |||
end | end | ||
ret = ret .. '<br>' | ret = ret .. '<br>' | ||
| Line 97: | Line 103: | ||
last_index = #accumulated_data | last_index = #accumulated_data | ||
last_value = accumulated_data[last_index][soul_unlock_key] | last_value = accumulated_data[last_index][soul_unlock_key] | ||
return | --Add 600 | ||
if soul_unlock_key == "RequiredSouls" then | |||
return last_value + 600 | |||
else | |||
return last_value | |||
end | |||
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'] | |||
--Add 600 | |||
local souls_str = '{{Souls|' .. (required_souls + 600) .. '}}' | |||
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 | end | ||
return p | return p | ||