More actions
No edit summary  | 
				No edit summary  | 
				||
| (47 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {}  | local p = {  | ||
    split = function(s, sep)  | |||
        local separated = mw.text.split(s, ";")  | |||
        for i, v in ipairs(separated) do  | |||
            separated[i] = mw.text.trim(v)  | |||
        end  | |||
        return separated  | |||
    end,  | |||
    indexOf = function(t, value)  | |||
        for i, v in ipairs(t) do  | |||
            if v == value then  | |||
                return i  | |||
            end  | |||
        end  | |||
        return -1  | |||
    end,  | |||
}  | |||
p["sort"] = function(t, basedOn)  | |||
    local out = {}  | |||
    table.sort(t, function(a, b)  | |||
        return p.indexOf(basedOn, a:sub(1, (a:find("*") or 0) - 1)) < p.indexOf(basedOn, b:sub(1, (b:find("*") or 0) - 1))  | |||
    end)  | |||
    for i, v in ipairs(t) do  | |||
        table.insert(out, v:sub(v:find("*") or 1, -1))  | |||
    end  | |||
    return out  | |||
end  | |||
function p.powers( frame )  | |||
    local args = frame.args  | |||
    local out = {"== Powers =="}  | |||
    for _, v in pairs(args) do  | |||
        table.insert(out, "* [[" .. mw.text.trim(v) .. "]]");   | |||
    end  | |||
    return table.concat(out, "\n")  | |||
end  | |||
function p.attributes( frame )  | function p.attributes( frame )  | ||
| Line 5: | Line 43: | ||
     local args = frame.args  |      local args = frame.args  | ||
     local   |      local temp = {"== Attributes ==", "=== Default ==="}  | ||
     for i, v in ipairs(attributeList) do  |      for i, v in ipairs(attributeList) do  | ||
         local attr = args[v] or args[v:lower()]  |          local attr = args[v] or args[v:lower()]  | ||
         if attr then  |          if attr ~= nil then  | ||
             local attrName =   |              local attrName = p.split(v:lower(), "_")  | ||
             for j, k in ipairs(attrName) do  |              for j, k in ipairs(attrName) do  | ||
                 attrName[j] = k:sub(1, 1):upper() .. k:sub(2)  |                  attrName[j] = k:sub(1, 1):upper() .. k:sub(2)  | ||
             end  |              end  | ||
             attrName = table.concat(attrName, " ")  |              attrName = table.concat(attrName, " ")  | ||
             local attrValue = tonumber(  |              local attrValue = tonumber(p.split(attr, ";")[1])  | ||
             if attrValue then  |              if attrValue then  | ||
                 local operator =   |                  local operator = p.split(attr, ";")[2] or ""  | ||
                if operator == "0" then  | |||
                    operator = ""  | |||
                end  | |||
                 if operator == "1" then  |                  if operator == "1" then  | ||
                     operator = "%"  |                      operator = "%"  | ||
                 end  |                  end  | ||
                 if operator == "%" then  | |||
                 local positive  |                     attrValue = attrValue * 100  | ||
                end  | |||
                 local positive = ""  | |||
                 if (tonumber(attrValue) > 0) then  |                  if (tonumber(attrValue) > 0) then  | ||
                     positive = "+"  |                      positive = "+"  | ||
                 end  |                  end  | ||
                 table.insert(  |                  table.insert(temp, v.."* " .. positive .. attrValue .. operator .. " " .. attrName)  | ||
             end  |              end  | ||
         end  |          end  | ||
     end  |      end  | ||
     return table.concat(  |      return table.concat(p.sort(temp, attributeList), "\n")  | ||
end  | end  | ||
| Line 38: | Line 82: | ||
     local keybindCodes = {}  |      local keybindCodes = {}  | ||
     keybindCodes[-1] = "Left Click"  |      keybindCodes[-1] = "Left Click"  | ||
    keybindCodes[0] = "Right Click"  | |||
     for i = 1, 5 do  |      for i = 1, 5 do  | ||
         keybindCodes[i] = "Ability " .. i  |          keybindCodes[i] = "Ability " .. i  | ||
| Line 45: | Line 90: | ||
     local args = frame.args  |      local args = frame.args  | ||
     local   |      local temp = {"== Keybinds =="}  | ||
     for   |      for _, v in pairs(args) do  | ||
         local keybindInfo =   |          local keybindInfo = p.split(v, ";")  | ||
         local keybindLabel = keybindInfo[1]  |          local keybindLabel = keybindInfo[1]  | ||
         local keybindSlot = tonumber(keybindInfo[2])  |          local keybindSlot = tonumber(keybindInfo[2])  | ||
| Line 59: | Line 104: | ||
             mod = " (while " .. keybindModifier .. ")"  |              mod = " (while " .. keybindModifier .. ")"  | ||
         end  |          end  | ||
         table.insert(  |          table.insert(temp, v.."* " .. keybindLabel .. " - " .. keybindSlot .. mod)  | ||
     end  |      end  | ||
    return table.concat(p.sort(p.sort(temp, keybindCodes), modifiers), "\n")  | |||
end  | |||
function p.equipment( frame )  | |||
    local out = {"== Equipment =="}  | |||
    for _, v in pairs(frame.args) do  | |||
        local equipmentInfo = p.split(v, ";")  | |||
        local equipmentName = equipmentInfo[1]  | |||
        local included = equipmentInfo[2] == "true" or equipmentInfo[2] == "1"  | |||
        local temp = {"*"}  | |||
        local span = mw.html.create("span")  | |||
        if included then  | |||
            span:wikitext("+"):attr("title", "Included with suit")  | |||
        else  | |||
            span:wikitext("-"):attr("title", "Not included with suit")  | |||
        end  | |||
        table.insert(temp, tostring(span))  | |||
        table.insert(temp, "[["..equipmentName.."]]")  | |||
        table.insert(out, table.concat(temp, " "))  | |||
    end  | |||
    return table.concat(out, "\n")  | |||
end  | end  | ||
return p  | return p  | ||
Latest revision as of 18:39, 13 April 2025
Documentation for this module may be created at Module:HeroInfo/doc
local p = {
    split = function(s, sep)
        local separated = mw.text.split(s, ";")
        for i, v in ipairs(separated) do
            separated[i] = mw.text.trim(v)
        end
        return separated
    end,
    indexOf = function(t, value)
        for i, v in ipairs(t) do
            if v == value then
                return i
            end
        end
        return -1
    end,
}
p["sort"] = function(t, basedOn)
    local out = {}
    table.sort(t, function(a, b)
        return p.indexOf(basedOn, a:sub(1, (a:find("*") or 0) - 1)) < p.indexOf(basedOn, b:sub(1, (b:find("*") or 0) - 1))
    end)
    for i, v in ipairs(t) do
        table.insert(out, v:sub(v:find("*") or 1, -1))
    end
    return out
end
function p.powers( frame )
    local args = frame.args
    local out = {"== Powers =="}
    
    for _, v in pairs(args) do
        table.insert(out, "* [[" .. mw.text.trim(v) .. "]]"); 
    end
    return table.concat(out, "\n")
end
function p.attributes( frame )
    local attributeList = {"ARROW_DAMAGE", "BASE_SPEED", "BASE_SPEED_LEVELS", "BOW_DRAWBACK", "DAMAGE_REDUCTION", "FALL_RESISTANCE", "FISKTAG_ARMOR", "FISKTAG_HEALTH", "IMPACT_DAMAGE", "JUMP_HEIGHT", "KNOCKBACK", "MAX_HEALTH", "PUNCH_DAMAGE", "REACH_DISTANCE", "SPRINT_SPEED", "STEP_HEIGHT", "WEAPON_DAMAGE"}
    
    local args = frame.args
    local temp = {"== Attributes ==", "=== Default ==="}
    
    for i, v in ipairs(attributeList) do
        local attr = args[v] or args[v:lower()]
        if attr ~= nil then
            local attrName = p.split(v:lower(), "_")
            for j, k in ipairs(attrName) do
                attrName[j] = k:sub(1, 1):upper() .. k:sub(2)
            end
            attrName = table.concat(attrName, " ")
            local attrValue = tonumber(p.split(attr, ";")[1])
            if attrValue then
                local operator = p.split(attr, ";")[2] or ""
                if operator == "0" then
                    operator = ""
                end
                if operator == "1" then
                    operator = "%"
                end
                if operator == "%" then
                    attrValue = attrValue * 100
                end
                local positive = ""
                if (tonumber(attrValue) > 0) then
                    positive = "+"
                end
                table.insert(temp, v.."* " .. positive .. attrValue .. operator .. " " .. attrName)
            end
        end
    end
    return table.concat(p.sort(temp, attributeList), "\n")
end
function p.keybinds( frame )
    local keybindCodes = {}
    keybindCodes[-1] = "Left Click"
    keybindCodes[0] = "Right Click"
    for i = 1, 5 do
        keybindCodes[i] = "Ability " .. i
    end
    local modifiers = {"sneaking", "on the ground", "in the air", "flying"}
    local args = frame.args
    local temp = {"== Keybinds =="}
    for _, v in pairs(args) do
        local keybindInfo = p.split(v, ";")
        local keybindLabel = keybindInfo[1]
        local keybindSlot = tonumber(keybindInfo[2])
        keybindSlot = keybindCodes[keybindSlot] or keybindSlot
        local keybindModifier = tonumber(keybindInfo[3])
        keybindModifier = modifiers[keybindModifier] or keybindModifier
        local mod = ""
        if (keybindModifier) then
            mod = " (while " .. keybindModifier .. ")"
        end
        table.insert(temp, v.."* " .. keybindLabel .. " - " .. keybindSlot .. mod)
    end
    return table.concat(p.sort(p.sort(temp, keybindCodes), modifiers), "\n")
end
function p.equipment( frame )
    local out = {"== Equipment =="}
    for _, v in pairs(frame.args) do
        local equipmentInfo = p.split(v, ";")
        local equipmentName = equipmentInfo[1]
        local included = equipmentInfo[2] == "true" or equipmentInfo[2] == "1"
        
        local temp = {"*"}
        local span = mw.html.create("span")
        if included then
            span:wikitext("+"):attr("title", "Included with suit")
        else
            span:wikitext("-"):attr("title", "Not included with suit")
        end
        table.insert(temp, tostring(span))
        table.insert(temp, "[["..equipmentName.."]]")
        table.insert(out, table.concat(temp, " "))
    end
    return table.concat(out, "\n")
end
return p