Module:Sandbox/User:Robert571/Fishing Table
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Sandbox/User:Robert571/Fishing Table/doc
local p = {}
local data = mw.loadData('Module:Sandbox/User:Robert571/Fishing_Data')
local yesno = require('Module:Yesno')
local MEM_ICON = {
[false] = '[[File:F2P icon.png|24px|link=Free-to-play]]',
[true] = '[[File:P2P icon.png|24px|link=Pay-to-play]]'
}
function p.main(frame)
local args = frame:getParent().args
local func = mw.ustring.lower(args[1])
local name = args[2]
if (func == "spot") then
p = fishingSpotTable(name, frame)
elseif (func == "fish") then
p = fishTable(name, frame)
end
return p
end
function fishingSpotTable(spotType, frame)
local t = mw.html.create('table')
:addClass('wikitable align-center-2 align-center-4 sortable autosort=1,a')
:tag('tr')
:tag('th') :wikitext('Location') :done()
:tag('th') :wikitext('Number') :done()
:tag('th') :wikitext('Requirements') :done()
:tag('th') :wikitext('Members') :done()
:tag('th') :wikitext('Maplink') :done()
:done()
for _, spot in ipairs(data[spotType].spots) do
local mem = MEM_ICON[yesno(spot.members or 'no')]
local count = 0
local mapArgs = {
mapID = spot.mapID,
mtype = 'pin',
icon = 'redPin',
text = 'Show on map'
}
for _, coords in ipairs(spot.coords) do
table.insert(mapArgs, string.format('x:%d, y:%d', coords[1], coords[2]))
count = count + 1
end
local map = frame:expandTemplate{title = 'Maplink', args = mapArgs}
t:tag('tr')
:tag('td') :wikitext(spot.location) :done()
:tag('td') :wikitext(count) :done()
:tag('td') :wikitext(spot.reqs) :done()
:tag('td') :wikitext(mem) :done()
:tag('td') :wikitext(map) :done()
:done()
end
return t
end
function fishTable(fish, frame)
local t = mw.html.create('table')
:addClass('wikitable align-center-3 align-center-5 sortable autosort=1,a')
:tag('tr')
:tag('th') :wikitext('Spot') :done()
:tag('th') :wikitext('Location') :done()
:tag('th') :wikitext('Number') :done()
:tag('th') :wikitext('Requirements') :done()
:tag('th') :wikitext('Members') :done()
:tag('th') :wikitext('Maplink') :done()
:done()
for spotType, spotInfo in pairs(data) do
mw.log(spotType)
local hasFish = false
for _, catch in ipairs(spotInfo.catches) do
mw.log(catch.fish)
if catch.fish == fish then
hasFish = true
break
end
end
if hasFish then
for _, spot in ipairs(spotInfo.spots) do
local mem = MEM_ICON[yesno(spot.members or 'no')]
local count = 0
local mapArgs = {
mapID = spot.mapID,
mtype = 'pin',
icon = 'redPin',
text = 'Show on map'
}
for _, coords in ipairs(spot.coords) do
table.insert(mapArgs, string.format('x:%d, y:%d', coords[1], coords[2]))
count = count + 1
end
local map = frame:expandTemplate{title = 'Maplink', args = mapArgs}
t:tag('tr')
:tag('td') :wikitext('[[' .. spotType .. ']]') :done()
:tag('td') :wikitext(spot.location) :done()
:tag('td') :wikitext(count) :done()
:tag('td') :wikitext(spot.reqs) :done()
:tag('td') :wikitext(mem) :done()
:tag('td') :wikitext(map) :done()
:done()
end
end
end
return t
end
return p