Module:ModuleUniqueStatTable: Difference between revisions

From The First Descendant Wiki
No edit summary
(Undo testing)
Tag: Manual revert
 
(35 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- IMPORTANT! This assumes data is structured EXACTLY in this order!
-- 1  Useless page identifier
-- 2  |?Module:Name
-- 3  |?Module:Class
-- 4  |?Module:MaxEnhancementLevel
-- 5  |?Module:CapacityCost0
-- 6  |?Module:ExclusiveCategory
-- 7  |?Module:Effect0
-- 8  |?Module:Effect1
-- 9  |?Module:Effect2
-- 10 |?Module:Effect3
-- 11 |?Module:Effect4
-- 12 |?Module:Effect5
-- 13 |?Module:Effect6
-- 14 |?Module:Effect7
-- 15 |?Module:Effect8
-- 16 |?Module:Effect9
-- 17 |?Module:Effect10
local moduleCalculateCost = require('Module:ModuleCalculateCost')
local p = {}
local p = {}


function parseCSV(csv)
local splitArray = {}
    local result = {}
    local cell = ""
    local inQuotes = false


    for i = 1, #csv do
local function split(str)
        local char = csv:sub(i, i)
    splitArray = {}
       
    for match in (str.."@"):gmatch("(.-)".."@") do
        if char == '"' then
         table.insert(splitArray, match)
            inQuotes = not inQuotes
        elseif char == '@' and not inQuotes then
            table.insert(result, cell)
            cell = ""
         elseif char == '\n' and not inQuotes then
            table.insert(result, cell)
            cell = ""
        else
            cell = cell .. char
        end
     end
     end
end


     if cell == "" then
local function generateTable()
         cell = "Q"
     local tableHeader = [[
        {| class="wikitable" style="width:100%;"
         |-
        ! Level !! Cost !! Effect
    ]]
 
    local tableContents = ""
 
    local maxLevel = tonumber(splitArray[4])
    if maxLevel == nil then
        maxLevel = 10 --This is a safety in case the value has not been entered. Assume the max.
     end
     end
    for i = 0,maxLevel do
        local row =
        "\n|-\n" ..
        "| ".. i..
        " || " .. moduleCalculateCost.calculate_module_cost(splitArray[5], i, splitArray[6]) .. --cost, level, exclusivecategory
        " || " .. splitArray[7 + i] --Effect0 is element 7, plus whatever element level we're looking at


     table.insert(result, cell)
        tableContents = tableContents .. row
    end
     local tableFooter = "\n|}"
 
    local tabContent = tableHeader .. tableContents .. tableFooter


     return result
     return tabContent
end
end


function p.processData(frame)
function p.processData(frame)
     local property1 = frame.args.property1 or ""
     if frame.args.csv == nil then
     local property2 = frame.args.property2 or ""
        return "ERROR: Module:ModuleUniqueStatTable got no csv string! Please tell us on Discord!"
     local name = frame.args.name or "DNE"
     end
   
     split(frame.args.csv)
    -- Process the data
 
     local result = "Name: " .. name .. name .. name .. ", Property2: " .. property2
     local completedTable = generateTable()
   
     return frame:preprocess(completedTable)
     return frame.args[0]
end
end


return p
return p

Latest revision as of 15:28, 30 June 2024

Documentation for this module may be created at Module:ModuleUniqueStatTable/doc

-- IMPORTANT! This assumes data is structured EXACTLY in this order! 
-- 1  Useless page identifier
-- 2  |?Module:Name
-- 3  |?Module:Class
-- 4  |?Module:MaxEnhancementLevel
-- 5  |?Module:CapacityCost0
-- 6  |?Module:ExclusiveCategory
-- 7  |?Module:Effect0
-- 8  |?Module:Effect1
-- 9  |?Module:Effect2
-- 10 |?Module:Effect3
-- 11 |?Module:Effect4
-- 12 |?Module:Effect5
-- 13 |?Module:Effect6
-- 14 |?Module:Effect7
-- 15 |?Module:Effect8
-- 16 |?Module:Effect9
-- 17 |?Module:Effect10

local moduleCalculateCost = require('Module:ModuleCalculateCost')

local p = {}

local splitArray = {}

local function split(str)
    splitArray = {}
    for match in (str.."@"):gmatch("(.-)".."@") do
        table.insert(splitArray, match)
    end
end

local function generateTable()
    local tableHeader = [[
        {| class="wikitable" style="width:100%;"
        |-
        ! Level !! Cost !! Effect
    ]]

    local tableContents = ""

    local maxLevel = tonumber(splitArray[4])
    if maxLevel == nil then
        maxLevel = 10 --This is a safety in case the value has not been entered. Assume the max.
    end
    for i = 0,maxLevel do
        local row =
        "\n|-\n" ..
        "| ".. i..
        " || " .. moduleCalculateCost.calculate_module_cost(splitArray[5], i, splitArray[6]) .. --cost, level, exclusivecategory
        " || " .. splitArray[7 + i] --Effect0 is element 7, plus whatever element level we're looking at

        tableContents = tableContents .. row
    end
    local tableFooter = "\n|}"

    local tabContent = tableHeader .. tableContents .. tableFooter

    return tabContent
end

function p.processData(frame)
    if frame.args.csv == nil then
        return "ERROR: Module:ModuleUniqueStatTable got no csv string! Please tell us on Discord!"
    end
    split(frame.args.csv)

    local completedTable = generateTable()
    return frame:preprocess(completedTable)
end

return p