8,758
edits
No edit summary |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
local utilTable = require('Module:Table Utility') | local utilTable = require('Module:Table Utility') | ||
local data = require('Module:CryptogullJr/Data') | local data = require('Module:CryptogullJr/Data') | ||
local cargo = mw.ext.cargo | |||
local p = {} | local p = {} | ||
Line 23: | Line 24: | ||
function p.decode(code, title, author) | function p.decode(code, title, author) | ||
local frame = mw.getCurrentFrame() | local frame = mw.getCurrentFrame() | ||
local | local gzdecode = zlib.gzdecode(zlib.base64_decode(code)) | ||
if gzdecode == false or gzdecode == nil then -- error handling | |||
error("This code isn't in base64. Please double check your input!") | |||
end | |||
local decoded = mw.text.jsonDecode(gzdecode) | |||
local version = decoded["gameversion"] | local version = decoded["gameversion"] | ||
Line 63: | Line 68: | ||
extNoun='Mutation' | extNoun='Mutation' | ||
end | end | ||
stats = decoded["modules"][statPos]["data"]["PointsPurchased"] | stats = decoded["modules"][statPos]["data"]["PointsPurchased"] | ||
-- No cybernetics means extra toughness | -- No cybernetics means extra toughness | ||
if extPos == 4 and #decoded["modules"][4]["data"]["selections"] == | if extPos == 4 and #decoded["modules"][4]["data"]["selections"] == 0 then | ||
exts[1] = "No Cybernetic" | exts[1] = "No Cybernetic" | ||
else | else | ||
for i, v in ipairs(decoded["modules"][extPos]["data"]["selections"]) do | for i, v in ipairs(decoded["modules"][extPos]["data"]["selections"]) do | ||
exts[i] = v[extNoun] | if extPos == 4 then | ||
exts[1] = getCyberneticName(v[extNoun]) | |||
else | |||
exts[i] = v[extNoun] | |||
end | |||
if v["variantName"] ~= "" and v["variantName"] ~= nil then | if v["variantName"] ~= "" and v["variantName"] ~= nil then | ||
exts[i] = exts[i] .. " (" .. v["variantName"] .. ")" | exts[i] = exts[i] .. " (" .. v["variantName"] .. ")" | ||
Line 125: | Line 132: | ||
} | } | ||
} | } | ||
end | |||
function getCyberneticName(id) | |||
local result = cargo.query("Cybernetics", "CyberneticID, Name", | |||
{where='CyberneticID ="'.. id..'"'}) | |||
if not next(result) then | |||
error(id .."is not a valid cybernetic id.") | |||
else | |||
return result[1]["Name"] | |||
end | |||
end | end | ||
return p | return p |