Module:SoulUnlock: Difference between revisions

Sur (talk | contribs)
m save accumulated_data after function definition
Sur (talk | contribs)
m working version of accumulate()
Line 1: Line 1:
local p = {}
local p = {}
local util_module = require('Module:Utilities')
local soul_unlocks_data = mw.loadJsonData("Data:SoulUnlockData.json")
local soul_unlocks_data = mw.loadJsonData("Data:SoulUnlockData.json")


Line 5: Line 6:
local function accumulate()  
local function accumulate()  
local accumulated_data = {} --holds the sum at each gold count
local accumulated_data = {} --holds the sum at each gold count
local sum_req_gold = 0
local sums = {} --holds only the current sums
local sums = {} --holds only the current sums
for i, su_data in ipairs(soul_unlocks_data) do
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
for key, value in pairs(su_data) do
if key == "RequiredGold" then break end
-- Determine how many to increase sum by
-- Determine how many to increase sum by
local num
local num
Line 27: Line 24:
end
end
-- Increase the sum
sums[key] = sums[key] + num
-- 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
end
-- Add the current sum to accumulated_data
-- Add the current sum to accumulated_data
accumulated_data[key] = sums
table.insert(accumulated_data, util_module.deep_copy(sums))
end
end
Line 40: Line 45:
local accumulated_data = accumulate()
local accumulated_data = accumulate()


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


return p
return p