Module:Shops: Difference between revisions

From The Walkscape Walkthrough
Content added Content deleted
(force param to be a string, even though it should be)
m (JarvoJoy)
(12 intermediate revisions by 2 users not shown)
Line 2: Line 2:


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


function p.getShopData(shopName)
function p.getShopData(frame)
local shopName = frame.args[1]
for _, shop in ipairs(shops) do
for _, shop in ipairs(shops) do
if shop.ShopName == shopName then
if shop.ShopName == shopName then
Line 28: Line 30:
end
end


function p.getShopData_AsTableRow(shopName)
function p.getShopData_AsTableRow(frame)
-- Extract the shop name from the frame arguments
-- Ensure shopName is a string
if type(shopName) ~= "string" then
local shopName = frame.args[1]

shopName = tostring(shopName)
end
local o = {}
for _, shop in ipairs(shops) do
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
if shop.ShopName == shopName then
return string.format("|-\n| [[%s]] || [[%s]] || [[%s]]", shop.ShopName, shop.Location, shop.Realm)
return string.format("|-\n| [[%s]] || [[%s]] || [[%s]] || [[%s]]", shop.Icon, shop.ShopName, shop.Location, shop.Region)
end
end
end
end
return table.concat(o, "\n")
return string.format("Shop %s not found", shopName)
end
end


function p.getAllShops()
function p.getShops()
return shops
return shops
end
end


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

for _, shop in ipairs(shops) do
for _, shop in ipairs(shops) do
table.insert(rows, string.format("|-\n| [[%s]] || [[%s]] || [[%s]]", shop.ShopName, shop.Location, shop.Realm))
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.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")
return table.concat(rows, "\n")
end
end

Revision as of 05:19, 25 March 2024

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