Editing Module:NavboxGenerator

Jump to navigation Jump to search
Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 3: Line 3:
local function generateNavbox(data, level)
local function generateNavbox(data, level)
     local result = {}
     local result = {}
     local boxSizePercent = 100 - (level-1)*15 -- 15% less per level, 100%, 85%, 70%, 55%, etc.
     local boxSize = 5 - level  -- Adjust this to control the box size reduction per level
     local fontSize = 170 - (level * 15)  -- Adjust font size reduction per level
     local fontSize = 150 - (level * 20)  -- Adjust to decrease font size per level
      
      
     for key, value in pairs(data) do
     for key, value in pairs(data) do
         if key == "Style" then
         if type(value) == "table" then
            -- Skip "Style" as it's just an attribute holder
        elseif key == "Display" then
            -- Leaf node, render Display content
             table.insert(result, string.format(
             table.insert(result, string.format(
                 '<div style="text-align: center; font-size:%d%%;">%s</div>',
                 '<div style="font-size:%d%%; border:1px solid #aaa; padding:5px; margin:2px;">=%s=</div>',
                 fontSize, value
                 fontSize, key
             ))
             ))
        elseif type(value) == "table" then
            table.insert(result, generateNavbox(value, level + 1)-- Recursively process next level
            -- Nested node, render title with optional Style and recurse
        else
             table.insert(result, string.format(
             table.insert(result, string.format(
                 '<div style="width: %s%%; margin-left: auto; margin-right: auto; text-align: center; font-size:%d%%; border:1px solid #aaa; %s">%s</div>',
                 '<div style="font-size:%d%%; padding-left:%dpx; margin:2px;">%s</div>',
                 boxSizePercent, fontSize, value.Style or "", key
                 fontSize, level * 10, value
             ))
             ))
            table.insert(result, generateNavbox(value, level + 1))  -- Recursively process next level
         end
         end
     end
     end
      
      
     return mw.getCurrentFrame():preprocess(table.concat(result, "\n"))
     return table.concat(result, "\n")
end
end


Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template