Module:Sandbox/SkillTree: Difference between revisions
From Melvor Idle
No edit summary |
No edit summary |
||
Line 44: | Line 44: | ||
if not skillName then | if not skillName then | ||
return "Invalid skillName" | |||
end | |||
local skillNodes = p. | local skillNodes = p.getSkillTree(skillName) | ||
if not skillNodes then | if not skillNodes then | ||
Line 59: | Line 59: | ||
:addClass('skill-tree-node') | :addClass('skill-tree-node') | ||
:tag('h4'):wikitext(node.name):done() | :tag('h4'):wikitext(node.name):done() | ||
:tag('p'):wikitext('Points: ' .. node.costs | :tag('p'):wikitext('Points: ' .. node.costs):done() | ||
if node.modifiers then | if node.modifiers then | ||
local modifierList = nodeDiv:tag('ul') | local modifierList = nodeDiv:tag('ul') | ||
for modifier, data in pairs(node.modifiers) do | for modifier, data in pairs(node.modifiers) do | ||
modifierList:tag('li') | if type(data) == "table" then | ||
modifierList:tag('li') | |||
:done() | :wikitext(modifier .. ': Skill: ' .. (data.skillID or "N/A") .. | ||
', Realm: ' .. (data.realmID or "N/A") .. | |||
', Value: ' .. (data.value or "N/A")) | |||
:done() | |||
else | |||
modifierList:tag('li') | |||
:wikitext(modifier .. ': ' .. tostring(data)) | |||
:done() | |||
end | |||
end | end | ||
modifierList:done() | modifierList:done() | ||
Line 76: | Line 84: | ||
return tostring(html) | return tostring(html) | ||
end | end | ||
return p | return p |
Revision as of 13:44, 31 August 2024
Documentation for this module may be created at Module:Sandbox/SkillTree/doc
local p = {}
local GameData = require('Module:GameData')
function p.getSkillTreeNodes(checkFunc)
local nodes = {}
for skillName, 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
local nodeCopy = {}
for k, v in pairs(node) do
nodeCopy[k] = v
end
nodeCopy.skillName = skillName
table.insert(nodes, nodeCopy)
end
end
end
end
return nodes
end
function p.getSkillTreeNodes(skillName)
mw.log(GameData.skillData)
local skillData = GameData.skillData[skillName]
if not skillData then return nil end
local nodes = {}
for _, node in ipairs(skillData.skillTrees[1].nodes) do
table.insert(nodes, node)
end
return nodes
end
function p.generateSkillTree(frame)
local args = frame.args ~= nil and frame.args or frame
local skillName = args[1]
if not skillName then
return "Invalid skillName"
end
local skillNodes = p.getSkillTree(skillName)
if not skillNodes then
return "No skill tree found for: " .. skillName
end
local html = mw.html.create('div'):addClass('skill-tree')
for _, node in ipairs(skillNodes) do
local nodeDiv = html:tag('div')
:addClass('skill-tree-node')
:tag('h4'):wikitext(node.name):done()
:tag('p'):wikitext('Points: ' .. node.costs):done()
if node.modifiers then
local modifierList = nodeDiv:tag('ul')
for modifier, data in pairs(node.modifiers) do
if type(data) == "table" then
modifierList:tag('li')
:wikitext(modifier .. ': Skill: ' .. (data.skillID or "N/A") ..
', Realm: ' .. (data.realmID or "N/A") ..
', Value: ' .. (data.value or "N/A"))
:done()
else
modifierList:tag('li')
:wikitext(modifier .. ': ' .. tostring(data))
:done()
end
end
modifierList:done()
end
html:done()
end
return tostring(html)
end
return p