Anonymous

Module:Sandbox/SkillTree: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 57: Line 57:
         local levels = {}
         local levels = {}
         local function findLevel(node, currentLevel)
         local function findLevel(node, currentLevel)
            -- Set level for the node if it's not already set
             if not levels[node.name] then
             if not levels[node.name] then
                 levels[node.name] = currentLevel
                 levels[node.name] = currentLevel
Line 94: Line 93:


     -- Constants for layout
     -- Constants for layout
     local baseX = 500 -- Start X position (center of the screen)
     local baseX = 400 -- Adjust starting X position
     local baseY = 50  -- Start Y position (top of the screen)
     local baseY = 50  -- Starting Y position
     local verticalSpacing = 200  -- Distance between levels (Y-axis)
     local verticalSpacing = 200  -- Distance between levels (Y-axis)
     local horizontalSpacing = 300  -- Distance between nodes at the same level (X-axis)
     local horizontalSpacing = 300  -- Distance between nodes at the same level (X-axis)
Line 126: Line 125:


     -- Position each node dynamically
     -- Position each node dynamically
     for _, node in ipairs(skillNodes) do
     for i, node in ipairs(skillNodes) do
         local level = nodeLevels[node.name]
         local level = nodeLevels[node.name]
         local nodesAtThisLevel = nodesPerLevel[level]
         local nodesAtThisLevel = nodesPerLevel[level]
         local indexInLevel = nodesAtThisLevel
         local indexInLevel = i


         -- Calculate X and Y positions for this node
         -- Calculate X and Y positions for this node
Line 141: Line 140:
         local nodeDiv = html:tag('div'):css({
         local nodeDiv = html:tag('div'):css({
             ['position'] = 'absolute',
             ['position'] = 'absolute',
             ['width'] = '200px',
             ['width'] = '150px',
             ['height'] = '100px',
             ['height'] = '100px',
             ['top'] = yPos .. 'px',
             ['top'] = yPos .. 'px',
Line 155: Line 154:
             ['font-weight'] = '700',
             ['font-weight'] = '700',
         }):done()
         }):done()
        -- Debug the positions of the nodes
        nodeDiv:tag('p'):wikitext('X: ' .. xPos .. ' Y: ' .. yPos):done()


         -- Append nodeDiv to HTML
         -- Append nodeDiv to HTML
393

edits