Module:BiomeDetails: Difference between revisions

From Eco - English Wiki
[checked revision][checked revision]
(Created page with "local p = {} local Utils = require('Module:Utils') function p.listBiomes(frame) local args = Utils.normaliseArgs(frame) return p.renderBiomeList(args.type) end function p.renderBiomeList(biomeType, includeSubBiomes) local biomeData = require( "Module:BiomeData" ) local isLand = nil if biomeType == 'Land' then isLand = true elseif biomeType == 'Water' then isLand = false end local biomes = {} for bid, biome in pa...")
 
No edit summary
Line 9: Line 9:


function p.renderBiomeList(biomeType, includeSubBiomes)
function p.renderBiomeList(biomeType, includeSubBiomes)
     local biomeData = require( "Module:BiomeData" )
     local biomeData = require("Module:BiomeData")
     local isLand = nil
    ---@type boolean
     local isLand
     if biomeType == 'Land' then
     if biomeType == 'Land' then
         isLand = true
         isLand = true
Line 16: Line 17:
         isLand = false
         isLand = false
     end
     end
   
 
     local biomes = {}
     local biomes = {}
     for bid, biome in pairs(biomeData) do
    local biome_keys = {}
     for _, biome in pairs(biomeData) do
         if biome.Name ~= '' and (isLand == nil or biome.Land == isLand) and (includeSubBiomes ~= true or biome.MainBiome == '') then
         if biome.Name ~= '' and (isLand == nil or biome.Land == isLand) and (includeSubBiomes ~= true or biome.MainBiome == '') then
             biomes[#biomes+1] = "* [[" .. biome.Name .."]]"
             if biome.MainBiome == '' then
                biome_keys[#biome_keys + 1] = biome.ID
                if biomes[biome.ID] == nil then
                    biomes[biome.ID] = { Name = biome.Name, SubBiomes = {} }
                else
                    biomes[biome.ID]["Name"] = biome.Name
                end
            else
                if biomes[biome.MainBiome] == nil then
                    biomes[biome.MainBiome] = { Name = biome.Name, SubBiomes = {} }
                end
                biomes[biome.MainBiome]["SubBiomes"][#biomes[biome.MainBiome]["SubBiomes"] + 1] = biome.Name
            end
        end
    end
    table.sort(biome_keys)
 
    local biome_list = {}
    for _, biome_id in ipairs(biome_keys) do
        local biome = biomes[biome_id]
        biome_list[#biome_list + 1] = "* [[" .. biome.Name .. "]]"
        for _, sname in pairs(biome["SubBiomes"]) do
            biome_list[#biome_list + 1] = "** [[" .. sname .. "]]"
         end
         end
     end
     end
    table.sort(biomes)


     return table.concat(biomes, "\n")
     return table.concat(biome_list, "\n")
end
end


return p
return p

Revision as of 17:29, 5 May 2024

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

local p = {}

local Utils = require('Module:Utils')

function p.listBiomes(frame)
    local args = Utils.normaliseArgs(frame)
    return p.renderBiomeList(args.type)
end

function p.renderBiomeList(biomeType, includeSubBiomes)
    local biomeData = require("Module:BiomeData")
    ---@type boolean
    local isLand
    if biomeType == 'Land' then
        isLand = true
    elseif biomeType == 'Water' then
        isLand = false
    end

    local biomes = {}
    local biome_keys = {}
    for _, biome in pairs(biomeData) do
        if biome.Name ~= '' and (isLand == nil or biome.Land == isLand) and (includeSubBiomes ~= true or biome.MainBiome == '') then
            if biome.MainBiome == '' then
                biome_keys[#biome_keys + 1] = biome.ID
                if biomes[biome.ID] == nil then
                    biomes[biome.ID] = { Name = biome.Name, SubBiomes = {} }
                else
                    biomes[biome.ID]["Name"] = biome.Name
                end
            else
                if biomes[biome.MainBiome] == nil then
                    biomes[biome.MainBiome] = { Name = biome.Name, SubBiomes = {} }
                end
                biomes[biome.MainBiome]["SubBiomes"][#biomes[biome.MainBiome]["SubBiomes"] + 1] = biome.Name
            end
        end
    end
    table.sort(biome_keys)

    local biome_list = {}
    for _, biome_id in ipairs(biome_keys) do
        local biome = biomes[biome_id]
        biome_list[#biome_list + 1] = "* [[" .. biome.Name .. "]]"
        for _, sname in pairs(biome["SubBiomes"]) do
            biome_list[#biome_list + 1] = "** [[" .. sname .. "]]"
        end
    end

    return table.concat(biome_list, "\n")
end

return p