Module:Schedule: Difference between revisions

From Coral Island Wiki
Jump to navigation Jump to search
(Created page with "local p = {} local lib = require('Module:Feature') local Tabber = require('Module:Tabber')._main function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { wrappers = { 'Template:Schedule' } }) args.character = args.character or mw.title.getCurrentTitle().rootText return p._main(args) end function p._main(args) local out = mw.html.create() local tabs = {} local i = '1' while lib.isNotEmpty(args[i .. '_name']) and lib.isNotEmpty(args...")
 
No edit summary
Line 15: Line 15:
function p._main(args)
function p._main(args)
local out = mw.html.create()
local out = mw.html.create()
local tabs = {}
local tabs = {alwaystabs=true}
local i = '1'
local Y = '1'
while lib.isNotEmpty(args[Y .. '_group']) do
while lib.isNotEmpty(args[i .. '_name']) and lib.isNotEmpty(args[i .. '_1_time']) and lib.isNotEmpty(args[i .. '_1_info']) do
-- initialize table
local _table = mw.html.create('table'):addClass('fandom-table article-table tdc1 tdbg1')
local _table = mw.html.create('table'):addClass('fandom-table article-table tdc1 tdbg1')
if i == '1' and lib.isEmpty(args['2_name']) then _table:tag('caption'):wikitext(args[i .. '_name']) end
--header
local tr = _table:tag('tr')
local tr = _table:tag('tr')
tr:tag('th'):wikitext('Time')
tr:tag('th'):wikitext('Time')
tr:tag('th'):wikitext('Activity')
tr:tag('th'):wikitext('Activity')
local i = Y .. '_1'
local y = '1'
while true do
while lib.isNotEmpty(args[i .. '_' .. y .. '_time']) and lib.isNotEmpty(args[i .. '_' .. y .. '_info']) do
if lib.isNotEmpty(args[i .. '_time']) and lib.isNotEmpty(args[i .. '_info']) then
local tr = _table:tag('tr')
local tr = _table:tag('tr')
local _time = lib.split(args[i .. '_' .. y .. '_time'], ':')
local _time = lib.split(args[i .. '_' .. y .. '_time'], ':')
tr:tag('td'):wikitext(string.format('%02d', _time[1]),':', string.format('%02d', (_time[2] or '00')))
tr:tag('td'):wikitext(
tr:tag('td'):wikitext(args[i .. '_' .. y .. '_info'])
string.format('%02d',tostring(math.mod(tonumber(_time[1]),12))),
y = tostring(tonumber(y)+1)
':',
string.format('%02d', (_time[2] or '00')),
' ',
lib.ternary(tonumber(_time[1])>=12, 'PM', 'AM')
)
tr:tag('td'):wikitext(args[i .. '_' .. y .. '_info'])
elseif lib.isNotEmpty(args[i .. '_cond']) then
local tr = _table:tag('tr'):tag('th'):attr('colspan', '2'):wikitext(args[i .. '_cond'])
else
break
end
i = Y .. '_' ..tostring(tonumber(i:gsub('^%d+_', ''))+1)
end
end
tabs['label' .. Y] = args[Y .. '_group']
tabs['content' .. i] = _table
tabs['content' .. Y] = _table
tabs['label' .. i] = args[i .. '_name']
Y = tostring(tonumber(Y)+1)
i = tostring(tonumber(i)+1)
end
end
if not tabs['content1'] then
if not tabs['content1'] and not args.alwaystabs then
return 'No information about ' .. args.character .. '\'s schedule.'
return 'No information about ' .. args.character .. '\'s schedule.'
else
else

Revision as of 19:46, 13 January 2024

Documentation for this module may be created at Module:Schedule/doc

local p = {}
local lib = require('Module:Feature')
local Tabber = require('Module:Tabber')._main

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = { 'Template:Schedule' }
	})

	args.character = args.character or mw.title.getCurrentTitle().rootText
	
	return p._main(args)
end

function p._main(args)
	local out = mw.html.create()
	local tabs = {alwaystabs=true}
	local Y = '1'
	while lib.isNotEmpty(args[Y .. '_group']) do
		-- initialize table
		local _table = mw.html.create('table'):addClass('fandom-table article-table tdc1 tdbg1')
		local tr = _table:tag('tr')
		tr:tag('th'):wikitext('Time')
		tr:tag('th'):wikitext('Activity')
		
		local i = Y .. '_1'
		while true do
			if lib.isNotEmpty(args[i .. '_time']) and lib.isNotEmpty(args[i .. '_info']) then
				local tr = _table:tag('tr')
				local _time = lib.split(args[i .. '_' .. y .. '_time'], ':')
				tr:tag('td'):wikitext(
					string.format('%02d',tostring(math.mod(tonumber(_time[1]),12))),
					':',
					string.format('%02d', (_time[2] or '00')),
					' ',
					lib.ternary(tonumber(_time[1])>=12, 'PM', 'AM')
				)
				tr:tag('td'):wikitext(args[i .. '_' .. y .. '_info'])
			elseif lib.isNotEmpty(args[i .. '_cond']) then
				local tr = _table:tag('tr'):tag('th'):attr('colspan', '2'):wikitext(args[i .. '_cond'])
			else
				break
			end
			i = Y .. '_' ..tostring(tonumber(i:gsub('^%d+_', ''))+1)
		end
		tabs['label' .. Y] = args[Y .. '_group']
		tabs['content' .. Y] = _table
		Y = tostring(tonumber(Y)+1)
	end
	
	if not tabs['content1'] and not args.alwaystabs then
		return 'No information about ' .. args.character .. '\'s schedule.'
	else
		return Tabber(tabs)
	end
end

return p