Technik Wiki
Registrieren
Advertisement

Das Modul Datei/Formatierung stellt die Funktionen befehlsblock, befehl und json zur Verfügung. Dies ermöglicht die Formatierung der Befehle und JSON-Texte innerhalb von Befehlsblöcken oder Dateien.

Aufruf

Die Parameter des Aufrufers werden automatisch übergeben. Das sind:

für {{#invoke:Datei/Formatierung|befehlsblock}} siehe Vorlage:Befehlsblock

für {{#invoke:Datei/Formatierung|befehl}} siehe Vorlage:Funktion

für {{#invoke:Datei/Formatierung|json}} siehe Vorlage:JSON-Datei


Zur Liste aller Vorlagen und Module

Zur Moduldokumentation


local p = {}

function p.befehl(text)
	text = text or ''
	if string.find( text, '^%#' ) then
		text = '<span style="color:grey">' .. text .. '</span>'
	else
		text = text:gsub( '#([%l%d%-_]+:[%l%d%.%-_/]+)', '[[#%1]]' )
		text = text:gsub( '%[%[#minecraft:([%l_]+)%]%]', '[[:mcw:Aliasdaten#%1|#minecraft:%1]]' )
		text = text:gsub( 'function ([%l%d%-_]+:[%l%d%.%-_/]+)', 'function [[#%1|%1]]' )
		text = text:gsub( 'advancement (%l+ .+ %l+) minecraft:recipes/([%l_]+)/([%l_]+)', 'advancement %1 [[:mcw:%3|minecraft:recipes/%2/%3]]' )
		text = text:gsub( 'advancement (%l+ .+ %l+) (minecraft:[%l_/]+)', 'advancement %1 [[:mcw:Fortschritte#%2|%2]]' )
		text = text:gsub( 'advancement (%l+ .+) only ([%l%d%-_]+:[%l%d%.%-_/]+) (.+)', 'advancement %1 only [[#%2|%2]] [[#%2-criteria|%3]]' )
		text = text:gsub( 'advancement (%l+ .+ %l+) ([%l%d%-_]+:[%l%d%.%-_/]+)', 'advancement %1 [[#%2|%2]]' )
		text = text:gsub( 'recipe (%l+ .+) minecraft:([%l_/]+)', 'recipe %1 [[:mcw:%2|minecraft:%2]]' )
		text = text:gsub( 'recipe (%l+ .+) ([%l%d%-_]+:[%l%d%.%-_/]+)', 'recipe %1 [[#%2|%2]]' )
		text = text:gsub( 'loot (.+) loot (minecraft:[%l_/]+)', 'loot %1 loot [[:mcw:Beutetabellen|%2]]' )
		text = text:gsub( 'loot (.+) loot ([%l%d%-_]+:[%l%d%.%-_/]+)', 'loot %1 loot [[#%2|%2]]' )
		text = text:gsub( 'loot (.+) fish (minecraft:[%l_/]+)', 'loot %1 fish [[:mcw:Beutetabellen|%2]]' )
		text = text:gsub( 'loot (.+) fish ([%l%d%-_]+:[%l%d%.%-_/]+)', 'loot %1 fish [[#%2|%2]]' )
		text = text:gsub( 'predicate ([%l%d%-_]+:[%l%d%.%-_/]+)', 'predicate [[#%1|%1]]' )
		text = text:gsub( 'predicate=([%l%d%-_]+:[%l%d%.%-_/]+)', 'predicate=[[#%1|%1]]' )
		text = text:gsub( '^/?(%l+)', '[[:mcw:Befehl/%1|%1]][[Kategorie:Seiten mit %1]]' )
		text = text:gsub( 'run (%l+)', 'run [[:mcw:Befehl/%1|%1]][[Kategorie:Seiten mit %1]]' )
		text = text:gsub( '(\\*"value\\*":%s*\\*")/(%l+)', '%1[[:mcw:Befehl/%2|/%2]][[Kategorie:Seiten mit %2]]' )
		text = text:gsub( '([%{,]%s*Command:%s*\\*")/?(%l+)', '%1[[:mcw:Befehl/%2|%2]][[Kategorie:Seiten mit %2]]' )
		text = text:gsub( '(minecraft:structure_block)', '%1[[Kategorie:Konstruktionsblock]]' )
	end
	return text
end

function p.json(text, type)
	text = text or ''
	type = type or ''
	if type == 'advancement' then
		text = text:gsub( '("function":%s*)"([%l%d%-_]+:[%l%d%.%-_/]+)"', '%1"[[#%2|%2]]"' )
		text = text:gsub( '("item":%s*)"minecraft:([%l_]+)"', '%1"[[:mcw:%2|minecraft:%2]]"' )
		text = text:gsub( '("loot":%s*)"([%l%d%-_]+:[%l%d%.%-_/]+)"', '%1"[[#%2|%2]]"' )
		text = text:gsub( '("loot":%s*)"%[%[#(minecraft:[%l_/]+)|%2%]%]"', '%1"%2"' )
		text = text:gsub( '("parent":%s*)"minecraft:recipes/([%l_]+)/([%l_]+)"', '%1"[[:mcw:%3|minecraft:recipes/%2/%3]]"' )
		text = text:gsub( '("parent":%s*)"(minecraft:[%l_]+)"', '%1"[[:mcw:Fortschritte#%2|%2]]"' )
		text = text:gsub( '("parent":%s*)"([%l%d%-_]+:[%l%d%.%-_/]+)"', '%1"[[#%2|%2]]"' )
		text = text:gsub( '("recipes":%s*)"minecraft:([%l_/]+)"', '%1"[[:mcw:%2|minecraft:%2]]"' )
		text = text:gsub( '("recipes":%s*)"([%l%d%-_]+:[%l%d%.%-_/]+)"', '%1"[[#%2|%2]]"' )
		text = text:gsub( '("tag":%s*)"minecraft:([%l_]+)"', '%1"[[:mcw:Aliasdaten#%2|minecraft:%2]]"' )
		text = text:gsub( '("tag":%s*)"([%l%d%-_]+:[%l%d%.%-_/]+)"', '%1"[[#%2|%2]]"' )
		text = text:gsub( '("trigger":%s*)"minecraft:([%l_]+)"', '%1"[[:mcw:Fortschrittsdaten#%2|minecraft:%2]]"' )
	elseif type == 'alias' then
		text = text:gsub( '"minecraft:([%l_]+)"', '"[[:mcw:%1|minecraft:%1]]"' )
		text = text:gsub( '"#minecraft:([%l_]+)"', '"[[:mcw:Aliasdaten#%1|#minecraft:%1]]"' )
		text = text:gsub( '"#([%l%d%-_]+:[%l%d%.%-_/]+)"', '"[[#%1]]"' )
	elseif type == 'loot' then
		text = text:gsub( '("name":%s*)"minecraft:([%l_]+)"', '%1"[[:mcw:%2|minecraft:%2]]"' )
		text = text:gsub( '("name":%s*)"([%l%d%-_]+:[%l%d%.%-_/]+)"', '%1"[[#%2|%2]]"' )
		text = text:gsub( '("name":%s*)"%[%[#(minecraft:[%l%d%.%-_/]+)|%2%]%]"', '%1"%2"' )
	elseif type == 'recipe' then
		text = text:gsub( '("item":%s*)"minecraft:([%l_]+)"', '%1"[[:mcw:%2|minecraft:%2]]"' )
		text = text:gsub( '("tag":%s*)"minecraft:([%l_]+)"', '%1"[[:mcw:Aliasdaten#%2|minecraft:%2]]"' )
		text = text:gsub( '("tag":%s*)"([%l%d%-_]+:[%l%d%.%-_/]+)"', '%1"[[#%2|%2]]"' )
	elseif type == 'predicate' then
		text = text:gsub( '("item":%s*)"minecraft:([%l_]+)"', '%1"[[:mcw:%2|minecraft:%2]]"' )
		text = text:gsub( '("tag":%s*)"minecraft:([%l_]+)"', '%1"[[:mcw:Aliasdaten#%2|minecraft:%2]]"' )
		text = text:gsub( '("tag":%s*)"([%l%d%-_]+:[%l%d%.%-_/]+)"', '%1"[[#%2|%2]]"' )
	end
	return text
end

function p.befehlsblock( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'Modul:ParameterUmwandeln' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	
	return p.befehl( args.text )
end

return p
Advertisement