Module:ModuleLevelTable: Difference between revisions

From The First Descendant Wiki
No edit summary
No edit summary
 
(46 intermediate revisions by 2 users not shown)
Line 1: Line 1:
------------------------------------------------------------------------------------------------------------------------------------------------
-- Variant Comparison Tabs & Tables
------------------------------------------------------------------------------------------------------------------------------------------------
-- IMPORTANT! This assumes data is structured EXACTLY in this order!  
-- IMPORTANT! This assumes data is structured EXACTLY in this order!  
--1 Nonsensical invoking ID
--1 Nonsensical invoking ID
--2 |?Module:Name --Unused, here for debug purposes
--2 |?Module:Name --Unused, here for debug purposes
--3 |?Module:Rarity
--3 |?Module:VariantID
--4 |?Module:Socket
--4 |?Module:Pic
--5 |?Module:Class
--5 |?Module:VersionReleased
--6 |?Module:MaxEnhancementLevel
--6 |?Module:Rarity
--7 |?Module:CapacityCost0
--7 |?Module:Socket
--8 |?Module:ExclusiveCategory
--8 |?Module:Class
--9 |?Module:Effect0
--9 |?Module:MaxEnhancementLevel
--10 |?Module:Effect1
--10 |?Module:CapacityCost0
--11 |?Module:Effect2
--11 |?Module:ExclusiveCategory
--12 |?Module:Effect3
--12 |?Module:Effect0
--13 |?Module:Effect4
--13 |?Module:Effect1
--14 |?Module:Effect5
--14 |?Module:Effect2
--15 |?Module:Effect6
--15 |?Module:Effect3
--16 |?Module:Effect7
--16 |?Module:Effect4
--17 |?Module:Effect8
--17 |?Module:Effect5
--18 |?Module:Effect9
--18 |?Module:Effect6
--19 |?Module:Effect10
--19 |?Module:Effect7
--
--20 |?Module:Effect8
--Note that not all Module parameters are being passed in here. Exclusive Descendant, for example
--21 |?Module:Effect9
-- does not need to be displayed in this table. So there's no need to pass it in.
--22 |?Module:Effect10
-- Make sure before you add anything that it's needed here.
 
local moduleCalculateCost = require('Module:ModuleCalculateCost')


local p = {}
local p = {}


local parsedArray = {}
local parsedArray = {}


local function addToParsedArray(parsedTable)
local function addToParsedArray(parsedTable)
Line 33: Line 38:
         parsedArray[#parsedArray][i] = parsedTable[i]  
         parsedArray[#parsedArray][i] = parsedTable[i]  
     end
     end
end
local function import(frame)
    if not frame.args.csv then
        return "Error: ModuleLevelTable not passed an argument. Report this to Discord!"
    end
    local csvText = frame.args.csv
   
    -- 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
    table.remove(parsedArray, 1) --The way that parsing works generates an empty first element.
                                -- I should figure it out and fix it, but... lazy
                                -- Removing it puts the first real element back in index 1
   
    return "" --Just a sanity to make sure we got no errors
end
end


Line 45: Line 74:
         if char == '"' then
         if char == '"' then
             inQuotes = not inQuotes
             inQuotes = not inQuotes
         elseif char == ',' and not inQuotes then
         elseif char == '@' and not inQuotes then
             table.insert(result, cell)
             table.insert(result, cell)
             cell = ""
             cell = ""
Line 69: Line 98:


     local tableHeader = [[
     local tableHeader = [[
         {| class="wikitable" style="width:100%;"
         {| class="wikitable sortable" style="width:100%;"
         |-
         |-
         ! Rarity !! Socket !! Class !! Max Level !! Capacity Cost !! Exclusive Category !! Effect
         ! Variant !! Rarity !! Socket !! Class !! Cost !! Exclusive !! Effect
     ]]
     ]]


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


     for i = 1, #parsedArray do
     for i = 1, #parsedArray do
         local row =
         local row =
         "\n|-\n| " .. parsedArray[i][3] ..
         "\n|-\n| " .. "[[" .. parsedArray[i][2] .. "#tab=".. parsedArray[i][3] .. "|" .. parsedArray[i][3] .. "]]" ..
        " || " .. parsedArray[i][4] ..
        " || " .. parsedArray[i][5] ..
         " || " .. parsedArray[i][6] ..
         " || " .. parsedArray[i][6] ..
         " || " .. parsedArray[i][7] .. --TODO: Maths this instead of pulling raw
         " || " .. parsedArray[i][7] ..
         " || " .. parsedArray[i][8] ..
         " || " .. parsedArray[i][8] ..
         " || " .. parsedArray[i][9 + element_level] --Effect0 is element 9, plus whatever element level we're looking at
         " || " .. moduleCalculateCost.calculate_module_cost(parsedArray[i][10], element_level, parsedArray[i][11]) .. --cost, level, exclusivecategory
        " || " .. parsedArray[i][11] ..
        " || " .. parsedArray[i][12 + element_level] --Effect0 is element 12, plus whatever element level we're looking at


         tableContents = tableContents .. row
         tableContents = tableContents .. row
Line 100: Line 124:
end
end


function p.process(frame)
local function getLargestTabIndex()
     if not frame.args[1] then
     local largest = tonumber(parsedArray[1][9]) -- We're assuming max upgrade level is always the same. If not, this will need to be handled here.
        return "Error: ModuleLevelTable not passed an argument. Report this to Discord!"
     if largest ~= nil then
    end
         return largest
    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
     end
    return 10 --This is a safety in case the value has not been entered. Assume the max.
end


    --if true then
function p.process(frame)
    --    return parsedArray[3][4]
     local importResult = import(frame)
    --end
     if importResult ~= "" then
      
         return importResult
     if #parsedArray == 0 then
         return "Error: ModuleLevelTable had no results. Report this to Discord!"
     end
     end
    table.remove(parsedArray, 1) --The way that parsing works generates an empty first element.
                                -- I should figure it out and fix it, but... lazy
                                -- Removing it puts the first real element back in index 1
   
    local largestTabIndex = parsedArray[1][6] -- We're assuming max upgrade level is always the same. If not, this will need to be handled here.
   


    local largestTabIndex = getLargestTabIndex()


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


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

Latest revision as of 00:42, 8 June 2024

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

------------------------------------------------------------------------------------------------------------------------------------------------
-- Variant Comparison Tabs & Tables
------------------------------------------------------------------------------------------------------------------------------------------------
-- IMPORTANT! This assumes data is structured EXACTLY in this order! 
--1 Nonsensical invoking ID
--2 |?Module:Name --Unused, here for debug purposes
--3 |?Module:VariantID
--4 |?Module:Pic
--5 |?Module:VersionReleased
--6 |?Module:Rarity
--7 |?Module:Socket
--8 |?Module:Class
--9 |?Module:MaxEnhancementLevel
--10 |?Module:CapacityCost0
--11 |?Module:ExclusiveCategory
--12 |?Module:Effect0
--13 |?Module:Effect1
--14 |?Module:Effect2
--15 |?Module:Effect3
--16 |?Module:Effect4
--17 |?Module:Effect5
--18 |?Module:Effect6
--19 |?Module:Effect7
--20 |?Module:Effect8
--21 |?Module:Effect9
--22 |?Module:Effect10

local moduleCalculateCost = require('Module:ModuleCalculateCost')

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 import(frame)
    if not frame.args.csv then
        return "Error: ModuleLevelTable not passed an argument. Report this to Discord!"
    end
    local csvText = frame.args.csv
    
    -- 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
    table.remove(parsedArray, 1) --The way that parsing works generates an empty first element.
                                 -- I should figure it out and fix it, but... lazy
                                 -- Removing it puts the first real element back in index 1
    
    return "" --Just a sanity to make sure we got no errors
end

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

    for i = 1, #csv do
        local char = csv:sub(i, i)
        
        if char == '"' then
            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

    if cell == "" then
        cell = "Q"
    end

    table.insert(result, cell)

    return result
end

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

    local tableHeader = [[
        {| class="wikitable sortable" style="width:100%;"
        |-
        ! Variant !! Rarity !! Socket !! Class !! Cost !! Exclusive !! Effect
    ]]

    local tableContents = ""

    for i = 1, #parsedArray do
        local row =
        "\n|-\n| " .. "[[" .. parsedArray[i][2] .. "#tab=".. parsedArray[i][3] .. "|" .. parsedArray[i][3] .. "]]" ..
        " || " .. parsedArray[i][6] ..
        " || " .. parsedArray[i][7] ..
        " || " .. parsedArray[i][8] ..
        " || " .. moduleCalculateCost.calculate_module_cost(parsedArray[i][10], element_level, parsedArray[i][11]) .. --cost, level, exclusivecategory
        " || " .. parsedArray[i][11] ..
        " || " .. parsedArray[i][12 + element_level] --Effect0 is element 12, plus whatever element level we're looking at

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

    local tabContent = tableHeader .. tableContents .. tableFooter

    return tabTitle .. tabContent
end

local function getLargestTabIndex()
    local largest = tonumber(parsedArray[1][9]) -- We're assuming max upgrade level is always the same. If not, this will need to be handled here.
    if largest ~= nil then
        return largest
    end
    return 10 --This is a safety in case the value has not been entered. Assume the max.
end

function p.process(frame)
    local importResult = import(frame)
    if importResult ~= "" then
        return importResult
    end

    local largestTabIndex = getLargestTabIndex()

    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