Technik Wiki
Advertisement
Technik Wiki

Die Dokumentation für dieses Modul kann unter Modul:Datei/Dokumentation erstellt werden

local p = {}
function p.datei( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	
	local extension = args.extension or ''
	if ( args.link or '' ) ~= '' then
		local link = f:callParserFunction( '#var_final:' .. args.link, args.link )
		local line = args.line or ''
		local text = args.text
		local up = args.up or ''
		if line ~= '' then
			if up ~= '' then
				text = text or ( 'Z' .. line )
			else
				text = text or ( 'Zeile ' .. line )
			end
			link = link .. '-Line' .. line
		else
			text = text or link
		end
		
		if up ~= '' then
			return '<sup>[[#' .. link .. '|[' .. text .. ']]]</sup>'
		else
			return '[[#' .. link .. '|' .. text .. ']]'
		end
	else
		local content = mw.text.trim(args[1] or '<strong class="error">Inhalt oder <code>1=</code> fehlt!</strong>')
		local name = args.name or 'file'
		local icon = '[[Datei:' .. ( args.icon or 'Editor Icon.png' ) .. '|32px|link=#' .. name .. ']] '
		if args.icon == 'none' then
			icon = ''
		end
		
		local lines = {}
		for k, line in ipairs(mw.text.split( content, ' *\n' )) do
			local span = mw.html.create('span')
				:addClass('cmdreflink')
				:attr('id',name .. '-Line' .. k)
				:wikitext(line)
			lines[#lines + 1] = '\n ' .. tostring(span)
		end
		
		local maxlines = 'maxlines-999'
		if #lines < 10 then
			maxlines = 'maxlines-9'
		elseif #lines < 100 then
			maxlines = 'maxlines-99'
		end
		
		local div = mw.html.create('div')
			:addClass('mcfile')
			:addClass(maxlines)
			:attr('id',name)
			:wikitext('\n' .. f:expandTemplate{ title = 'Ausklappmenü', args = { icon .. '<code>' .. name .. extension .. '</code>' .. f:callParserFunction( '#vardefine:' .. ( args.alias or name ), name ), table.concat( lines, '' ), offen = args.offen or '1' } })
		
		return div
	end
end

function p.funktion( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	
	local Formatierung = require('Modul:Datei/Formatierung')
	
	local content = mw.text.trim(args[1] or '<strong class="error">Befehle oder <code>1=</code> fehlt!</strong>')
	
	local lines = {}
	for line in mw.text.gsplit( content, ' *\n *' ) do
		
		line = Formatierung.befehl(line)
		
		lines[#lines + 1] = '\n' .. tostring(line)
	end
	
	return p.datei{ table.concat( lines, '' ), name = args.name or 'function', link = args.link, alias = args.alias, line = args.line, text = args.text, up = args.up, icon = 'Editor Icon.png', extension = '.mcfunction', offen = args.offen or '1' }
end

function p.json( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	
	local Formatierung = require('Modul:Datei/Formatierung')
	
	local content = mw.text.trim(args[1] or '<strong class="error">Inhalt oder <code>1=</code> fehlt!</strong>')
	
	local type = args.type or ''
	local lines = {}
	for line in mw.text.gsplit( content, ' *\n' ) do
		
		line = Formatierung.json(line, type)
		
		if type == 'advancement' then
			line = line:gsub( '"criteria":', '"<span id="' .. ( args.name or 'file' ) .. '-criteria">criteria</span>":' )
		end
		
		lines[#lines + 1] = '\n' .. tostring(line)
	end
	
	return p.datei{ table.concat( lines, '' ), name = args.name, link = args.link, alias = args.alias, line = args.line, text = args.text, up = args.up, icon = 'JSON Icon.png', extension = '.json', offen = args.offen or '1' }
end

return p
Advertisement