Module:Shiren 6 Dungeon Items table: Difference between revisions

MDFW - The Mystery Dungeon Tree of Information.
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 1: Line 1:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--
-- Module:Shiren 6 Dungeon Items table
-- Module:Shiren 6 Dungeon Items table
--
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 9: Line 9:


function p.main(frame)
function p.main(frame)
local data = require("Module:Shiren 6 Item Data Cell")
local metatable = {__index = function () return "" end}
setmetatable(data, metatable)
local args = frame.args
local args = frame.args
local output = mw.html.create()
local header = mw.html.create()
local categoryArg = args["category"]
local categoryArg = args["category"]
local typeArg = args["type"]
 
local output = {}
-- Header row
-- Header row
table.insert(output, '<table class="templateTheme" style="text-align: center; width: 100%;">')
header
table.insert(output, '<tr>')
:tag('tr'):done()
if categoryArg then
:tag('th'):attr("colspan", "3"):wikitext(frame:expandTemplate{title = "Shiren6Sprite", args = {frame:preprocess('{{#switch:' .. categoryArg .. ' | Riceballs=Riceball | Projectile=Arrows | Miscellaneous=Jar Fragment | #default={{{category|}}} }}'), size = "32x32px"}} .. '<br>' .. frame:expandTemplate{title = "Shiren6", args = {(categoryArg or "")}}):done()
table.insert(output, '<th class="templatePrimary" colspan="4" style="border-radius: 1rem 1rem 0 0; height:7.5rem;">[[File:Shiren 6 - ' .. frame:preprocess('{{#switch:' .. categoryArg .. ' | Armbands=Armband | Weapons=Weapon | Shields=Shield | Herbs=Herb | Riceballs=Riceball | Monster Meats=Monster Meat | Jars=Jar | Projectiles=Arrows | Scrolls=Scroll | Staves=Staff | Traps=Trap | Miscellaneous=Jar Fragment | Gitan=Gitan Bag | #default={{{category|}}} }}') .. '.png|50x50px]]<br>' .. frame:expandTemplate{title = "Shiren6", args = {(categoryArg or "")}} .. '</th>')
:tag('tr'):done()
 
if string.lower(categoryArg) == "gitan" then
header
:tag('th'):cssText("width: 33%"):wikitext("Lowest amount"):done()
:tag('th'):cssText("width: 33%"):wikitext("Highest amount"):done()
else
else
table.insert(output, '<th class="templatePrimary" colspan="4" style="border-radius: 1rem 1rem 0 0; height:7.5rem;">' .. frame:expandTemplate{title = "Research"} .. '</th>')
header
:tag('th'):cssText("width: 33%"):wikitext("English"):done()
:tag('th'):cssText("width: 33%"):wikitext("Japanese"):done()
end
end
table.insert(output, '</tr>')
 
table.insert(output, '<tr>')
header
table.insert(output, '<th class="templatePrimary" style="width: 50%;">English</th>')
:tag('th'):cssText("width: 34%"):wikitext("Floors"):done()
table.insert(output, '<th class="templatePrimary" style="width: 50%;">Japanese</th>')
 
table.insert(output, '</tr>')
-- Data rows
-- Data rows
for i = 1, 100 do
local rows = mw.html.create()
local i = 1
 
while true do
local row = mw.html.create()
local itemArg = args["item_" .. i]
local itemArg = args["item_" .. i]
if not itemArg then
local lowAmountArg = args["low_amount_" .. i]
local highAmountArg = args["high_amount_" .. i]
local floorsArg = args["floors_" .. i]
 
if not itemArg and not floorsArg and not lowAmountArg and not highAmountArg then
break -- exit loop when no more rows are found
break -- exit loop when no more rows are found
end
end
local rowData = {}
 
table.insert(rowData, '<tr class="itemsTableRow">')
row
if itemArg then
:tag("tr"):done()
table.insert(rowData, '<td class="templateSecondary">' .. frame:expandTemplate{title = "Shiren6", args = {(itemArg or "")}} .. '</td>')
 
table.insert(rowData, '<td class="templateSecondary">' .. frame:preprocess('{{#invoke:Shiren 6 Item Data Cell|shiren6ItemDataCell|name=' .. (itemArg or "") .. '}}') .. '</td>')
if string.lower(categoryArg) == "gitan" then
row
:tag("td"):wikitext((lowAmountArg or frame:expandTemplate{title = "Research"})):done()
:tag("td"):wikitext((highAmountArg or frame:expandTemplate{title = "Research"})):done()
else
else
table.insert(rowData, '<td class="templateSecondary">' .. frame:expandTemplate{title = "Research"} .. '</td>')
if itemArg:lower() == 'riceball (item)' or itemArg:lower() == 'riceball' then
table.insert(rowData, '<td class="templateSecondary">' .. frame:expandTemplate{title = "Research"} .. '</td>')
itemArgs = { 'Riceball (item)', 'Riceball' }
else
itemArgs = { (itemArg or "") }
end
 
row
:tag("td"):wikitext(frame:expandTemplate{title = "Shiren6", args = itemArgs}):done()
:tag("td"):wikitext(data[itemArg]["ja"]):done()
end
end
table.insert(rowData, '</tr>')
 
table.insert(output, table.concat(rowData))
row
:tag("td"):wikitext((floorsArg or frame:expandTemplate{title = "Research"})):done()
 
rows
:node(row)
:allDone()
i = i + 1
end
end
table.insert(output, '</table>')
 
return table.concat(output)
output
:tag('table'):addClass("MDWiki"):cssText("text-align: center; width: 100%;")
:node(header)
:node(rows)
return tostring(output)
end
end


return p
return p

Revision as of 19:15, 10 November 2024

Documentation for this module may be created at Module:Shiren 6 Dungeon Items table/doc

--------------------------------------------------------------------------------
--
--					Module:Shiren 6 Dungeon Items table
--
--------------------------------------------------------------------------------

local p = {}
local mw = require('mw')

function p.main(frame)
	local data = require("Module:Shiren 6 Item Data Cell")
	local metatable = {__index = function () return "" end}
	setmetatable(data, metatable)
	local args = frame.args

	local output = mw.html.create()
	local header = mw.html.create()
	local categoryArg = args["category"]

	-- Header row
	header
		:tag('tr'):done()
			:tag('th'):attr("colspan", "3"):wikitext(frame:expandTemplate{title = "Shiren6Sprite", args = {frame:preprocess('{{#switch:' .. categoryArg .. ' | Riceballs=Riceball | Projectile=Arrows | Miscellaneous=Jar Fragment | #default={{{category|}}} }}'), size = "32x32px"}} .. '<br>' .. frame:expandTemplate{title = "Shiren6", args = {(categoryArg or "")}}):done()
		:tag('tr'):done()

	if string.lower(categoryArg) == "gitan" then
		header
			:tag('th'):cssText("width: 33%"):wikitext("Lowest amount"):done()
			:tag('th'):cssText("width: 33%"):wikitext("Highest amount"):done()
	else
		header
			:tag('th'):cssText("width: 33%"):wikitext("English"):done()
			:tag('th'):cssText("width: 33%"):wikitext("Japanese"):done()
	end

	header
		:tag('th'):cssText("width: 34%"):wikitext("Floors"):done()

	-- Data rows
	local rows = mw.html.create()
	local i = 1

	while true do
		local row = mw.html.create()
		local itemArg = args["item_" .. i]
		local lowAmountArg = args["low_amount_" .. i]
		local highAmountArg = args["high_amount_" .. i]
		local floorsArg = args["floors_" .. i]

		if not itemArg and not floorsArg and not lowAmountArg and not highAmountArg then
			break -- exit loop when no more rows are found
		end

		row
			:tag("tr"):done()

		if string.lower(categoryArg) == "gitan" then
			row
				:tag("td"):wikitext((lowAmountArg or frame:expandTemplate{title = "Research"})):done()
				:tag("td"):wikitext((highAmountArg or frame:expandTemplate{title = "Research"})):done()
		else
			if itemArg:lower() == 'riceball (item)' or itemArg:lower() == 'riceball' then
				itemArgs = { 'Riceball (item)', 'Riceball' }
			else
				itemArgs = { (itemArg or "") }
			end

			row
				:tag("td"):wikitext(frame:expandTemplate{title = "Shiren6", args = itemArgs}):done()
				:tag("td"):wikitext(data[itemArg]["ja"]):done()
		end

		row
			:tag("td"):wikitext((floorsArg or frame:expandTemplate{title = "Research"})):done()

		rows
			:node(row)
			:allDone()
		
		i = i + 1
	end

	output
		:tag('table'):addClass("MDWiki"):cssText("text-align: center; width: 100%;")
			:node(header)
			:node(rows)
	return tostring(output)
end

return p