Module:Shops

From The Walkscape Walkthrough
Revision as of 00:58, 8 March 2024 by CptRileyyy (talk | contribs) (Today we learned: In MediaWiki, parameters are passed to Lua modules as tables, not as individual arguments...)

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

local p = {}

local shops = {
    {ShopName = "Helpful Herbert's Hut",        Location = "DisenchantedForest", Realm = "Jarvonia"},
    {ShopName = "Temple of Azurazera",          Location = "Azurazera",          Realm = "Jarvonia"},
    {ShopName = "The Icy Goblet",               Location = "Kallaheim",          Realm = "Jarvonia"},
    {ShopName = "Kallaheim's Frosty Finds",     Location = "Kallaheim",          Realm = "Jarvonia"},
    {ShopName = "Jarvojoy",                     Location = "Frusenholm",         Realm = "Jarvonia"},
    {ShopName = "Northstar Mercantile",         Location = "Centaham",           Realm = "Jarvonia"},
    {ShopName = "Frosthook Emporium",           Location = "PortSkildar",        Realm = "Jarvonia"},
    {ShopName = "Woodcutter's Cabin",           Location = "NomadWoods",         Realm = "Jarvonia"},
    {ShopName = "Fort of Permafrost",           Location = "FortOfPermafrost",   Realm = "Jarvonia"},
    {ShopName = "Paws Are Us",                  Location = "Salsfirth",          Realm = "GDTE"},
    {ShopName = "Mossy Merchant's Breeze Mart", Location = "Everhaven",          Realm = "GDTE"},
    {ShopName = "Bilgemont Castle",             Location = "BilgemontPort",      Realm = "GDTE"},
    {ShopName = "Fish Market Stall",            Location = "Granfiddich",        Realm = "GDTE"},
    {ShopName = "Food Market Stall",            Location = "Granfiddich",        Realm = "GDTE"},
    {ShopName = "Tool Market Stall",            Location = "Granfiddich",        Realm = "GDTE"},
}

function p.getShopData(shopName)
    for _, shop in ipairs(shops) do
        if shop.ShopName == shopName then
            return shop
        end
    end
    return "Shop not found"
end

function p.getShopData_AsTableRow(frame)
    -- Extract the shop name from the frame arguments
    local shopName = frame.args[1]

    local o = {}
    for _, shop in ipairs(shops) do
        table.insert(o, string.format("shop.ShopName: %s did not match input of %s", shop.ShopName, shopName))
        if shop.ShopName == shopName then
            return string.format("|-\n| [[%s]] || [[%s]] || [[%s]]", shop.ShopName, shop.Location, shop.Realm)
        end
    end
    return table.concat(o, "\n")
end

function p.getAllShops()
    return shops
end

function p.getAllShops_AsTableRows()
    local rows = {}
    for _, shop in ipairs(shops) do
        table.insert(rows, string.format("|-\n| [[%s]] || [[%s]] || [[%s]]", shop.ShopName, shop.Location, shop.Realm))
    end
    return table.concat(rows, "\n")
end

return p