Module:DigimonTab: Difference between revisions
Appearance
imported>Ziebster No edit summary |
imported>Ziebster No edit summary |
||
| Line 33: | Line 33: | ||
local status | local status | ||
if type(summonable_field) == 'table' then | if type(summonable_field) == 'table' then | ||
if #summonable_field | if #summonable_field == 0 then | ||
error("Summonable table is empty for Digimon: " .. digimon.name) | |||
end | end | ||
local idx = math.min(i, #summonable_field) | |||
status = summonable_field[idx] | |||
else | else | ||
status = summonable_field or "Yes" | status = summonable_field or "Yes" | ||
| Line 51: | Line 50: | ||
end | end | ||
if status == "Yes" or status == "''Yes''" then has_yes = true end | if status == "Yes" or status == "''Yes''" then has_yes = true end | ||
table.insert(status == "No" and unsummonable or summonable, entry) | table.insert(status == "No" and unsummonable or summonable, entry) | ||
break | break | ||
Revision as of 06:30, 9 January 2026
Example Usage:
<tabber>
|-|Example=<div class="mobileonly"><h3>Example</h3></div>
{{#invoke:DigimonTab|show|Exam|Ex}}
</tabber>
- Example = Version tabber label
- Exam = Master List device tag
- Ex = Footnote tag (if applicable)
local p = {}
function p.show(frame)
local versionTag = frame.args[1] or (frame:getParent() and frame:getParent().args[1]) or "Error: No version tag"
local label = frame.args[2] or (frame:getParent() and frame:getParent().args[2]) or versionTag -- Fallback to versionTag if no label provided
local data = mw.loadData("Module:MasterList")
local summonable, unsummonable = {}, {}
local has_yes = false
local has_refs = false
-- New: Get the current page's raw wikitext to parse for categories
local title = mw.title.getCurrentTitle()
local content = title:getContent()
local battleTypeX = nil
-- Modified: Extract the full 'X' from {{Category}} template invocations where first param is "Battle Type X"
for match in content:gmatch('{{Category|(.-)}}') do
local parts = mw.text.split(match, '|')
if #parts >= 1 then
local cat_name = mw.text.trim(parts[1])
local match_x = cat_name:match('^Battle Type (.*)$')
if match_x then
battleTypeX = match_x
break
end
end
end
for _, digimon in ipairs(data) do
for i, v in ipairs(digimon.versions or {}) do
if v == versionTag then
local summonable_field = digimon.summonable
local status
if type(summonable_field) == 'table' then
if #summonable_field == 0 then
error("Summonable table is empty for Digimon: " .. digimon.name)
end
local idx = math.min(i, #summonable_field)
status = summonable_field[idx]
else
status = summonable_field or "Yes"
end
local entry = {
image = digimon.image and digimon.image ~= "" and "[[File:" .. digimon.image .. "|50px]]" or "",
name = "'''" .. digimon.name .. "'''"
}
if status == "''Yes''" then
entry.name = entry.name .. " [[#" .. label .. "|*]]"
has_refs = true
end
if status == "Yes" or status == "''Yes''" then has_yes = true end
table.insert(status == "No" and unsummonable or summonable, entry)
break
end
end
end
table.sort(summonable, function(a,b) return mw.text.unstripNoWiki(a.name) < mw.text.unstripNoWiki(b.name) end)
table.sort(unsummonable, function(a,b) return mw.text.unstripNoWiki(a.name) < mw.text.unstripNoWiki(b.name) end)
local function buildGrid(entries)
local rows = ""
local max_entries_per_row = 3 -- Limit to 3 entries per row (4 columns) to avoid scroll bars; increase to 3 if needed
for i = 1, #entries, max_entries_per_row do
local cells = {}
for j = 0, max_entries_per_row - 1 do
local idx = i + j
if idx > #entries then break end
table.insert(cells, 'style="border:none;" | ' .. entries[idx].image)
table.insert(cells, 'style="border:none;" | ' .. entries[idx].name)
end
if #cells > 0 then
rows = rows .. "|-\n| " .. table.concat(cells, " || ") .. "\n"
end
end
return rows
end
local summonable_title = (#summonable > 0 and has_yes) and "Summonable Digimon" or "Unimplemented Digimon"
local out = (#summonable > 0 and "=<span id=" .. label .. "S></span>'''" .. summonable_title .. "'''=\n{| class=\"fandom-table\" style=\"border: none; border-collapse: collapse;\"\n" .. buildGrid(summonable) .. "|}\n" or "") ..
(#unsummonable > 0 and "='''Unsummonable Digimon'''=\n{| class=\"fandom-table\" style=\"border: none; border-collapse: collapse;\"\n" .. buildGrid(unsummonable) .. "|}\n" or (#summonable == 0 and "''No Digimon in this version.''\n" or ""))
if has_refs then
-- Modified: Use [[:Category:... for linking, and include "same" in the piped link text
local battleTypeText = battleTypeX and '[[:Category:Battle Type ' .. battleTypeX .. '|same Battle Type]]' or 'same Battle Type'
out = out .. "\n:<span id=" .. label .. ">[[#" .. label .. "S|↑]]</span> <sub>You need another device with the " .. battleTypeText .. " in order to battle with this Digimon. This Digimon '''''can be summoned''''' but '''''cannot battle''''' with this device.</sub>\n"
end
return out
end
return p