Module:Shops: Difference between revisions

From The Walkscape Walkthrough
Content deleted Content added
force param to be a string, even though it should be
m JarvoJoy
(12 intermediate revisions by 2 users not shown)
Line 2:
 
local shops = {
{ShopName = "Helpful Herbert's Hut", Icon = "File:Cabin_icon.png|frameless|32x32px", Location = "DisenchantedForestDisenchanted Forest", RealmRegion = "Jarvonia"},
{ShopName = "Temple of Azurazera", Icon = "File:Temple_of_Azurazera_icon.png|frameless|32x32px", Location = "Azurazera", Realm Region = "Jarvonia"},
{ShopName = "The Icy Goblet", Icon = "File:Tavern_icon.png|frameless|32x32px", Location = "Kallaheim", Realm Region = "Jarvonia"},
{ShopName = "Kallaheim's Frosty Finds", Icon = "File:General_Store_icon.png|frameless|32x32px", Location = "Kallaheim", Realm Region = "Jarvonia"},
{ShopName = "JarvojoyJarvoJoy", Icon = "File:General_Store_icon.png|frameless|32x32px", Location = "Frusenholm", Realm Region = "Jarvonia"},
{ShopName = "Northstar Mercantile", Icon = "File:General_Store_icon.png|frameless|32x32px", Location = "Centaham", Realm Region = "Jarvonia"},
{ShopName = "Frosthook Emporium", Icon = "File:Fishing_Shop_icon.png|frameless|32x32px", Location = "PortSkildarPort Skildar", RealmRegion = "Jarvonia"},
{ShopName = "Woodcutter's Cabin", Icon = "File:Cabin_icon.png|frameless|32x32px", Location = "NomadWoodsNomad Woods", RealmRegion = "Jarvonia"},
{ShopName = "Fort of Permafrost (Castle)", Icon = "File:Castle_icon.png|frameless|32x32px", Location = "FortOfPermafrostFort of Permafrost", RealmRegion = "Jarvonia"},
{ShopName = "Paws Are Us", Icon = "File:Animal_Shelter_icon.png|frameless|32x32px", Location = "Salsfirth", Realm Region = "GDTE"},
{ShopName = "Mossy Merchant's Breeze Mart", Icon = "File:General_Store_icon.png|frameless|32x32px", Location = "Everhaven", Realm Region = "GDTE"},
{ShopName = "Bilgemont Castle", Icon = "File:Castle_icon.png|frameless|32x32px", Location = "BilgemontPortBilgemont Port", RealmRegion = "GDTE"},
{ShopName = "Fish Market Stall", Icon = "File:Market_Stall_icon.png|frameless|32x32px", Location = "Granfiddich", Realm Region = "GDTE"},
{ShopName = "Food Market Stall", Icon = "File:Market_Stall_icon.png|frameless|32x32px", Location = "Granfiddich", Realm Region = "GDTE"},
{ShopName = "Tool Market Stall", Icon = "File:Market_Stall_icon.png|frameless|32x32px", Location = "Granfiddich", Realm Region = "GDTE"},
}
 
function p.getShopData(shopNameframe)
local shopName = frame.args[1]
for _, shop in ipairs(shops) do
if shop.ShopName == shopName then
Line 28 ⟶ 30:
end
 
function p.getShopData_AsTableRow(shopNameframe)
-- Extract the shop name from the frame arguments
-- Ensure shopName is a string
iflocal type(shopName) ~= "string" thenframe.args[1]
 
shopName = tostring(shopName)
end
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]] || [[%s]]", shop.Icon, shop.ShopName, shop.Location, shop.RealmRegion)
end
end
return tablestring.concatformat(o,"Shop %s not found"\n", shopName)
end
 
function p.getAllShopsgetShops()
return shops
end
 
function p.getAllShops_AsTableRowsgetAllShops()
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.RealmRegion))
end
table.insert(rows, "|}")
return table.concat(rows, "\n")
end
 
function p.getAllShopsByLocation(frame)
local location = frame.args[1]
local orows = {}
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(orows, string.format("shop.ShopName:|-\n| [[%s]] did|| not[[%s]] match|| input[[%s]] of|| [[%s]]", shop.Icon, shop.ShopName, shopNameshop.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

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