Module:ModuleLevelTable: Difference between revisions

From The First Descendant Wiki
No edit summary
No edit summary
Line 1: Line 1:
-- 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 p = {}
local p = {}


Line 20: Line 41:
local function generateTabberLine(element_level)
local function generateTabberLine(element_level)
     local tabTitle = "\n\n|-| Level " .. tostring(element_level) .. " =\n"
     local tabTitle = "\n\n|-| Level " .. tostring(element_level) .. " =\n"
     local tabContent = "\nThis is the content of the tab.\n"
 
    local tableHeader = [[
        {| class="wikitable" style="width:100%;"
        |+ '''Table Title'''
        |-
        ! Header 1 !! Header 2 !! Header 3
    ]]
 
    local row = [[
        |-
        | Row 1, Cell 1 || Row 1, Cell 2 || Row 1, Cell 3
    ]]
 
    local tableFooter = "|}"
 
     local tabContent = tableHeader .. row .. tableFooter
 
     return tabTitle .. tabContent
     return tabTitle .. tabContent
end
end
Line 41: Line 78:
         return "Error: ModuleLevelTable had no results. Report this to Discord!"
         return "Error: ModuleLevelTable had no results. Report this to Discord!"
     end
     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[2][6] + 1 --Un-upgraded is level 0, so max level + 1
     local largestTabIndex = parsedArray[2][6]


     local tabberHeadder = "<tabber>\n"
     local tabberHeadder = "<tabber>\n"


     local tabberContent = ""
     local tabberContent = ""
     for i = 0, tabCount do
     for i = 0, largestTabIndex do
         tabberContent = tabberContent .. generateTabberLine(i)
         tabberContent = tabberContent .. generateTabberLine(i)
     end
     end

Revision as of 17:03, 4 June 2024

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

-- 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 p = {}

local parsedArray = {}

local function addToParsedArray(parsedTable)
    parsedArray[#parsedArray+1] = {}
    for i=1,#parsedTable do
        parsedArray[#parsedArray][i] = parsedTable[i] 
    end
end

local function parseCSV(csvString) -- csvString is one line
    local result = {}
    for value in string.gmatch(csvString, '([^,]+)') do
        table.insert(result, value)
    end
    return result
end

local function generateTabberLine(element_level)
    local tabTitle = "\n\n|-| Level " .. tostring(element_level) .. " =\n"

    local tableHeader = [[
        {| class="wikitable" style="width:100%;"
        |+ '''Table Title'''
        |-
        ! Header 1 !! Header 2 !! Header 3
    ]]

    local row = [[
        |-
        | Row 1, Cell 1 || Row 1, Cell 2 || Row 1, Cell 3
    ]]

    local tableFooter = "|}"

    local tabContent = tableHeader .. row .. tableFooter

    return tabTitle .. tabContent
end

function p.process(frame)
    if not frame.args[1] then
        return "Error: ModuleLevelTable not passed an argument. Report this to Discord!"
    end
    local csvText = frame.args[1]
    
    -- Put all the CSV lines into an array
    for line in csvText:gmatch("[^\r\n]+") do
        if line ~= "" then
            local parsedLine = parseCSV(line)
            addToParsedArray(parsedLine)
        end
    end
    
    if #parsedArray == 0 then
        return "Error: ModuleLevelTable had no results. Report this to Discord!"
    end
    
    local largestTabIndex = parsedArray[2][6]

    local tabberHeadder = "<tabber>\n"

    local tabberContent = ""
    for i = 0, largestTabIndex do
        tabberContent = tabberContent .. generateTabberLine(i)
    end

    local tabberFooter = "\n</tabber>"
    
    return frame:preprocess(tabberHeadder .. tabberContent .. tabberFooter)
end



return p


--Debug lines
-- local csvText = "ModuleTestPage#_9a88490adf412a0c81fe3a2fa2d78e3c,Test Module Name,Transcendent,Almandine,High-Power Rounds,10,6,Resource,,,,,,,,,,"