Module:DisplayExternal

Revision as of 19:41, 20 May 2025 by Epyon (talk | contribs) (Initial commit)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

local totalWeight = {}

local sprite = require([[Module:Inventory slot]])
   
function p.lootTable( f )
    return parseLootTable(f)
end

function parseLootTable ( f )
    local args = f.args or f
    local url = args.url
    local type = args.type
    
    totalWeight["default"] = 0
    
    -- if args ~= nil then
    -- if string.find(url,".json") == nil then
    --     return nil
    -- end
    -- mw.log(url)
    local data, errors = mw.ext.externalData.getExternalData(url)
    if errors then
        mw.logObject(errors)
        return errors
    end
    local json = data.__json
    local entries = json.pools[1].entries
    for i, e in ipairs(entries) do
        calcTotalWeight( e )
    end
    -- mw.logObject(totalWeight)
    
    local root = mw.html.create('table'):addClass('wikitable')
    local headerRow = root:tag('tr')
    local itemCol = headerRow:tag('th'):wikitext("Item/Mob")
    local chanceCol = headerRow:tag('th'):wikitext("Chances")
    local conditionsCol = headerRow:tag('th'):wikitext("Conditions")
    local notesCol = headerRow:tag('th'):wikitext("Notes")
    
    -- generateLootTable( root, entries )
    return f:preprocess(tostring(root))
end

function calcTotalWeight ( obj )
    if obj.conditions == nil then
        totalWeight.default = totalWeight.default + obj.weight
    end
end


function generateLootTable ( root, entries )
    for i, e in ipairs(entries) do
        local row = root:tag('tr')
        if e.type == "minecraft:loot_table" then
            -- mw.log()
        elseif e.type == "minecraft:item" then
            parseLootItem (e)
        end
        break
    end
end

function parseLootItem ( entry )
    sprite:slot(entry.name)
end

function renderLootTable( entries )
    
end

return p