Module:Sandbox/SkillTree: Difference between revisions

From Melvor Idle
No edit summary
No edit summary
Line 25: Line 25:
end
end


function p.printSkillTrees()
function p.printAllSkillTrees()
     local skillTrees = GameData.skillData.Agility.skillTrees
     -- Iterate through all skills in GameData.skillData
    for skillName, skillData in pairs(GameData.skillData) do
        local skillTrees = skillData.skillTrees


    if not skillTrees then
        if skillTrees then
        mw.log("No skill trees found.")
            mw.log("Skill Trees for " .. skillName .. ":")
        return
            for _, skillTree in ipairs(skillTrees) do
    end
                mw.log("------------------------------")
 
                mw.log("Skill Tree ID: " .. skillTree.id)
    mw.log("Skill Trees for Agility:")
                mw.log("Skill Tree Name: " .. skillTree.name)
    for _, skillTree in ipairs(skillTrees) do
                mw.log("Points Available: " .. (skillTree.points or "N/A"))
        mw.log("------------------------------")
                mw.log("Number of Nodes: " .. #skillTree.nodes)
        mw.log("Skill Tree ID: " .. skillTree.id)
        mw.log("Skill Tree Name: " .. skillTree.name)
        mw.log("Points Available: " .. (skillTree.points or "N/A"))
        mw.log("Number of Nodes: " .. #skillTree.nodes)


        -- Print information for each node in the skill tree
                -- Print information for each node in the skill tree
        for _, node in ipairs(skillTree.nodes) do
                for _, node in ipairs(skillTree.nodes) do
            mw.log("  Node ID: " .. node.id)
                    mw.log("  Node ID: " .. node.id)
            mw.log("  Node Name: " .. node.name)
                    mw.log("  Node Name: " .. node.name)
            mw.log("  Costs: " .. (node.costs.points or 0) .. " points")
                    mw.log("  Costs: " .. (node.costs.points or 0) .. " points")
            mw.log("  Unlocked: " .. tostring(node.isUnlocked))
                    mw.log("  Unlocked: " .. tostring(node.isUnlocked))


            -- Print the node's modifiers
                    -- Print the node's modifiers
            if node.modifiers then
                    if node.modifiers then
                mw.log("  Modifiers:")
                        mw.log("  Modifiers:")
                deepPrint(node.modifiers, 2)
                        deepPrint(node.modifiers, 2)
            end
                    end


            -- Print the node's parents (if any)
                    -- Print the node's parents (if any)
            if node.parents then
                    if node.parents then
                mw.log("  Parents:")
                        mw.log("  Parents:")
                for _, parentID in ipairs(node.parents) do
                        for _, parentID in ipairs(node.parents) do
                    mw.log("    Parent Node ID: " .. parentID)
                            mw.log("    Parent Node ID: " .. parentID)
                        end
                    end
                 end
                 end
             end
             end
        else
            mw.log("No skill trees found for " .. skillName .. ".")
         end
         end
     end
     end
Line 67: Line 69:
function p.getSkillTreeNodes(checkFunc)
function p.getSkillTreeNodes(checkFunc)
     local nodes = {}
     local nodes = {}
     for _, skill in pairs(SkillData) do
   
         for _, tree in ipairs(skill.skillTrees or {}) do
     for _, skillData in pairs(GameData.skillData) do
            for _, node in ipairs(GameData.getEntities(tree.nodes, checkFunc)) do
         local skillTrees = skillData.skillTrees
                table.insert(nodes, node)
        if skillTrees then
            for _, skillTree in ipairs(skillTrees) do
                for _, node in ipairs(GameData.getEntities(skillTree.nodes, checkFunc)) do
                    table.insert(nodes, node)
                end
             end
             end
         end
         end

Revision as of 13:43, 30 August 2024

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

local p = {}

local Constants = require('Module:Constants')
local Num = require('Module:Number')
local Shared = require('Module:Shared')
local Common = require('Module:Common')
local GameData = require('Module:GameData')
local SkillData = GameData.skillData
local Modifiers = require('Module:Modifiers')
local Skills = require('Module:Skills')
local Items = require('Module:Items')
local Icons = require('Module:Icons')

local function deepPrint(tbl, indent)
    if not indent then indent = 0 end
    for k, v in pairs(tbl) do
        local formatting = string.rep("  ", indent) .. k .. ": "
        if type(v) == "table" then
            mw.log(formatting)
            deepPrint(v, indent + 1)
        else
            mw.log(formatting .. tostring(v))
        end
    end
end

function p.printAllSkillTrees()
    -- Iterate through all skills in GameData.skillData
    for skillName, skillData in pairs(GameData.skillData) do
        local skillTrees = skillData.skillTrees

        if skillTrees then
            mw.log("Skill Trees for " .. skillName .. ":")
            for _, skillTree in ipairs(skillTrees) do
                mw.log("------------------------------")
                mw.log("Skill Tree ID: " .. skillTree.id)
                mw.log("Skill Tree Name: " .. skillTree.name)
                mw.log("Points Available: " .. (skillTree.points or "N/A"))
                mw.log("Number of Nodes: " .. #skillTree.nodes)

                -- Print information for each node in the skill tree
                for _, node in ipairs(skillTree.nodes) do
                    mw.log("  Node ID: " .. node.id)
                    mw.log("  Node Name: " .. node.name)
                    mw.log("  Costs: " .. (node.costs.points or 0) .. " points")
                    mw.log("  Unlocked: " .. tostring(node.isUnlocked))

                    -- Print the node's modifiers
                    if node.modifiers then
                        mw.log("  Modifiers:")
                        deepPrint(node.modifiers, 2)
                    end

                    -- Print the node's parents (if any)
                    if node.parents then
                        mw.log("  Parents:")
                        for _, parentID in ipairs(node.parents) do
                            mw.log("    Parent Node ID: " .. parentID)
                        end
                    end
                end
            end
        else
            mw.log("No skill trees found for " .. skillName .. ".")
        end
    end
end

function p.getSkillTreeNodes(checkFunc)
    local nodes = {}
    
    for _, skillData in pairs(GameData.skillData) do
        local skillTrees = skillData.skillTrees
        if skillTrees then
            for _, skillTree in ipairs(skillTrees) do
                for _, node in ipairs(GameData.getEntities(skillTree.nodes, checkFunc)) do
                    table.insert(nodes, node)
                end
            end
        end
    end
    return nodes
end

return p