Anonymous

Module:Sandbox/SkillTree: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 93: Line 93:


     -- Constants for layout
     -- Constants for layout
     local baseX = 400 -- Adjust starting X position
     local baseX = 500 -- Center of the tree horizontally
     local baseY = 50  -- Starting Y position
     local baseY = 50  -- Start Y position (top of the screen)
     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 = 200 -- Distance between nodes at the same level (X-axis)


     -- Count nodes per level for horizontal positioning
     -- Count nodes per level for horizontal positioning
Line 123: Line 123:
     -- Track positions for each node
     -- Track positions for each node
     local nodePositions = {}
     local nodePositions = {}
    -- Keep track of how many nodes we've placed on each level
    local nodeIndexPerLevel = {}


     -- Position each node dynamically
     -- Position each node dynamically
     for i, 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]
         nodeIndexPerLevel[level] = (nodeIndexPerLevel[level] or 0) + 1
         local indexInLevel = i
         local indexInLevel = nodeIndexPerLevel[level]


         -- Calculate X and Y positions for this node
         -- Calculate X and Y positions for this node
        local nodesAtThisLevel = nodesPerLevel[level]
         local xPos = baseX + (indexInLevel - nodesAtThisLevel / 2) * horizontalSpacing
         local xPos = baseX + (indexInLevel - nodesAtThisLevel / 2) * horizontalSpacing
         local yPos = baseY + level * verticalSpacing
         local yPos = baseY + level * verticalSpacing
393

edits