Module:Shops

From The Walkscape Walkthrough

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

local p = {}

local shops = {
    {ShopName = "Helpful Herbert's Hut",        Icon = "File:Cabin_icon.png|frameless|32x32px",               Location = "Disenchanted Forest", Region = "Jarvonia"},
    {ShopName = "Temple of Azurazera",          Icon = "File:Temple_of_Azurazera_icon.png|frameless|32x32px", Location = "Azurazera",           Region = "Jarvonia"},
    {ShopName = "The Icy Goblet",               Icon = "File:Tavern_icon.png|frameless|32x32px",              Location = "Kallaheim",           Region = "Jarvonia"},
    {ShopName = "Kallaheim's Frosty Finds",     Icon = "File:General_Store_icon.png|frameless|32x32px",       Location = "Kallaheim",           Region = "Jarvonia"},
    {ShopName = "JarvoJoy",                     Icon = "File:General_Store_icon.png|frameless|32x32px",       Location = "Frusenholm",          Region = "Jarvonia"},
    {ShopName = "Northstar Mercantile",         Icon = "File:General_Store_icon.png|frameless|32x32px",       Location = "Centaham",            Region = "Jarvonia"},
    {ShopName = "Frosthook Emporium",           Icon = "File:Fishing_Shop_icon.png|frameless|32x32px",        Location = "Port Skildar",        Region = "Jarvonia"},
    {ShopName = "Woodcutter's Cabin",           Icon = "File:Cabin_icon.png|frameless|32x32px",               Location = "Nomad Woods",         Region = "Jarvonia"},
    {ShopName = "Fort of Permafrost (Castle)",  Icon = "File:Castle_icon.png|frameless|32x32px",              Location = "Fort of Permafrost",  Region = "Jarvonia"},
    {ShopName = "Paws Are Us",                  Icon = "File:Animal_Shelter_icon.png|frameless|32x32px",      Location = "Salsfirth",           Region = "GDTE"},
    {ShopName = "Mossy Merchant's Breeze Mart", Icon = "File:General_Store_icon.png|frameless|32x32px",       Location = "Everhaven",           Region = "GDTE"},
    {ShopName = "Bilgemont Castle",             Icon = "File:Castle_icon.png|frameless|32x32px",              Location = "Bilgemont Port",      Region = "GDTE"},
    {ShopName = "Fish Market Stall",            Icon = "File:Market_Stall_icon.png|frameless|32x32px",        Location = "Granfiddich",         Region = "GDTE"},
    {ShopName = "Food Market Stall",            Icon = "File:Market_Stall_icon.png|frameless|32x32px",        Location = "Granfiddich",         Region = "GDTE"},
    {ShopName = "Tool Market Stall",            Icon = "File:Market_Stall_icon.png|frameless|32x32px",        Location = "Granfiddich",         Region = "GDTE"},
}

function p.getShopData(frame)
	local shopName = frame.args[1]
	
    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]

    for _, shop in ipairs(shops) do
        if shop.ShopName == shopName then
            return string.format("|-\n| [[%s]] || [[%s]] || [[%s]] || [[%s]]", shop.Icon, shop.ShopName, shop.Location, shop.Region)
        end
    end
    return string.format("Shop %s not found", shopName)
end

function p.getShops()
    return shops
end

function p.getAllShops()
    local rows = {}
    table.insert(rows, "{| class=\"wikitable sortable\" style=\"text-align: center;\"\n! !Icon !! Shop Name !! Location !! Region")

    for _, shop in ipairs(shops) do
        table.insert(rows, string.format("|-\n| [[%s]] || [[%s]] || [[%s]] || [[%s]]", shop.Icon, shop.ShopName, shop.Location, shop.Region))
    end
    
    table.insert(rows, "|}")
    return table.concat(rows, "\n")
end

function p.getAllShopsByLocation(frame)
    local location = frame.args[1]
    local rows = {}
    table.insert(rows, string.format("{| class=\"wikitable sortable\" style=\"text-align: center;\"\n! !Icon !! Shop Name !! Location !! Region"))
    
    for _, shop in ipairs(shops) do
        if shop.Location == location then
            table.insert(rows, string.format("|-\n| [[%s]] || [[%s]] || [[%s]] || [[%s]]", shop.Icon, shop.ShopName, shop.Location, shop.Region))
        end
    end
    
    table.insert(rows, "|}")
    return table.concat(rows, "\n")
end

function p.getAllShopsByRegion(frame)
    local region = frame.args[1]
    local rows = {}
    table.insert(rows, string.format("{| class=\"wikitable sortable\" style=\"text-align: center;\"\n! !Icon !! Shop Name !! Location !! Region"))
    
    for _, shop in ipairs(shops) do
        if shop.Region == region then
            table.insert(rows, string.format("|-\n| [[%s]] || [[%s]] || [[%s]] || [[%s]]", shop.Icon, shop.ShopName, shop.Location, shop.Region))
        end
    end
    
    table.insert(rows, "|}")
    return table.concat(rows, "\n")
end

return p