|
|
| Line 1: |
Line 1: |
| local p = {} | | local p = {} |
|
| |
|
| local parsedArray = {} | | function p.loadJson(frame) |
| | -- Get the JSON string from the template parameter named 'json' |
| | local jsonString = frame.args.json |
|
| |
|
| local laststring = ""
| | -- Parse the JSON string into a Lua table |
| local function addToParsedArray(parsedTable)
| | local success, jsonTable = pcall(mw.text.jsonDecode, jsonString) |
| parsedArray[#parsedArray+1] = {} | |
| for i=1,#parsedTable do | |
| parsedArray[#parsedArray][i] = parsedTable[i]
| |
| laststring = parsedTable[i]
| |
| end
| |
| end
| |
|
| |
|
| local function parseCSV(csvString) -- csvString is one line
| | if success then |
| local result = {}
| | return jsonTable |
| for value in string.gmatch(csvString, '([^,]+)') do | | else |
| table.insert(result, value) | | return "Error parsing JSON" |
| end | | end |
| return result
| |
| end
| |
|
| |
| function p.process(frame)
| |
| local csvText = frame.args[1] or ""
| |
|
| |
| -- Put all the CSV lines into an array
| |
| for line in csvText:gmatch("[^\r\n]+") do
| |
| local parsedLine = parseCSV(line)
| |
| if #parsedLine > 0 then
| |
| --addToParsedArray(parsedLine)
| |
| parsedArray[#parsedArray+1] = {}
| |
| for i=1,#parsedLine do
| |
| parsedArray[#parsedArray][i] = parsedLine[i]
| |
| if laststring == "" then
| |
| --laststring = parsedLine[i]
| |
| end
| |
| end
| |
| laststring = #parsedLine
| |
| else
| |
| laststring = "NOPE"
| |
| end
| |
| end
| |
|
| |
| if #parsedArray == 0 then
| |
| return "Error: ModuleLevelTable had no results. Report this to Discord!"
| |
| end
| |
|
| |
| -- IMPORTANT! This assumes data is structured EXACTLY in this order!
| |
| --1 Nonsensical invoking ID
| |
| --2 |?Module:Name
| |
| --3 |?Module:Rarity
| |
| --4 |?Module:Socket
| |
| --5 |?Module:Class
| |
| --6 |?Module:MaxEnhancementLevel
| |
| --7 |?Module:CapacityCost0
| |
| --8 |?Module:ExclusiveCategory
| |
| --9 |?Module:Effect0
| |
| --10 |?Module:Effect1
| |
| --11 |?Module:Effect2
| |
| --12 |?Module:Effect3
| |
| --13 |?Module:Effect4
| |
| --14 |?Module:Effect5
| |
| --15 |?Module:Effect6
| |
| --16 |?Module:Effect7
| |
| --17 |?Module:Effect8
| |
| --18 |?Module:Effect9
| |
| --19 |?Module:Effect10
| |
|
| |
| --local tabCount = parsedArray[1][6] + 1 --Un-upgraded is level 0, so max level + 1
| |
|
| |
| local tabber = [[
| |
| <tabber>
| |
| |-|First Tab Title=
| |
| First tab content goes here.
| |
| |-|Second Tab Title=
| |
| Second tab content goes here.
| |
| |-|Third Tab Title=
| |
| Third tab content goes here.
| |
| </tabber>
| |
| ]]
| |
|
| |
| --local wat = ""
| |
| --for key, value in ipairs(parsedArray[1]) do
| |
| -- wat = wat .. "\n" .. "Key:" .. key .. "Value:" .. value
| |
| --end
| |
| return frame.args[1]
| |
| end | | end |
|
| |
|
| return p | | return p |