Technik Wiki
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, nocat)
	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/Standard-Vorlagen#%1|#minecraft:%1]]' )
		text = text:gsub( 'function ([%l%d%-_]+:[%l%d%.%-_/]+)', 'function [[#%1|%1]]' )
		text = text:gsub( 'schedule clear ([%l%d%-_]+:[%l%d%.%-_/]+)', 'schedule clear [[#%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( 'advancements=(%{[^%}]+%})', function(fortschritte)
			fortschritte = fortschritte:gsub( '([%{,]%s*)minecraft:recipes/([%l_]+)/([%l_]+)=', '%1[[:mcw:%3|minecraft:recipes/%2/%3]]=' )
			fortschritte = fortschritte:gsub( '([%{,]%s*)(minecraft:[%l_/]+)=', '%1[[:mcw:Fortschritte#%2|%2]]=' )
			fortschritte = fortschritte:gsub( '([%{,]%s*)([%l%d%-_]+:[%l%d%.%-_/]+)=', '%1[[#%2|%2]]=' )
			return 'advancements=' .. fortschritte
		end )
		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( 'item modify block (.+ .+ .+ [%l%d%.%-_/]+) ([%l%d%-_]+:[%l%d%.%-_/]+)', 'item modify block %1 [[#%2|%2]]' )
		text = text:gsub( 'item modify entity (.+ [%l%d%.%-_/]+) ([%l%d%-_]+:[%l%d%.%-_/]+)', 'item modify entity %1 [[#%2|%2]]' )
		text = text:gsub( 'item replace block (.+ .+ .+ [%l%d%.%-_/]+) from block (.+ .+ .+ [%l%d%.%-_/]+) ([%l%d%-_]+:[%l%d%.%-_/]+)', 'item replace block %1 from block %2 [[#%3|%3]]' )
		text = text:gsub( 'item replace block (.+ .+ .+ [%l%d%.%-_/]+) from entity (.+ [%l%d%.%-_/]+) ([%l%d%-_]+:[%l%d%.%-_/]+)', 'item replace block %1 from entity %2 [[#%3|%3]]' )
		text = text:gsub( 'item replace entity (.+ [%l%d%.%-_/]+) from block (.+ .+ .+ [%l%d%.%-_/]+) ([%l%d%-_]+:[%l%d%.%-_/]+)', 'item replace entity %1 from block %2 [[#%3|%3]]' )
		text = text:gsub( 'item replace entity (.+ [%l%d%.%-_/]+) from entity (.+ [%l%d%.%-_/]+) ([%l%d%-_]+:[%l%d%.%-_/]+)', 'item replace entity %1 from entity %2 [[#%3|%3]]' )
		text = text:gsub( 'loot (.+) loot minecraft:([%l_/]+)', 'loot %1 loot [[:mcw:Beutetabellen/Standard-Vorlagen#%2|minecraft:%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/Standard-Vorlagen#%2|minecraft:%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[[#%2|%2]]' )
		text = text:gsub( '([%{,]%s*LootTable:%s*\\*)(["\'])minecraft:([%l_/]+)%2', '%1%2[[:mcw:Beutetabellen/Standard-Vorlagen#%3|minecraft:%3]]%2' )
		text = text:gsub( '([%{,]%s*LootTable:%s*\\*)(["\'])([%l%d%-_]+:[%l%d%.%-_/]+)%2', '%1%2[[#%3|%3]]%2' )
		text = text:gsub( '([%{,]%s*DeathLootTable:%s*\\*)(["\'])minecraft:([%l_/]+)%2', '%1%2[[:mcw:Beutetabellen/Standard-Vorlagen#%3|minecraft:%3]]%2' )
		text = text:gsub( '([%{,]%s*DeathLootTable:%s*\\*)(["\'])([%l%d%-_]+:[%l%d%.%-_/]+)%2', '%1%2[[#%3|%3]]%2' )
		if nocat then
			text = text:gsub( '^/?(%l+)', '[[:mcw:Befehl/%1|%1]]' )
			text = text:gsub( 'run (%l+)', 'run [[:mcw:Befehl/%1|%1]]' )
			text = text:gsub( '(\\*"value\\*":%s*\\*")/(%l+)', '%1[[:mcw:Befehl/%2|/%2]]' )
			text = text:gsub( '([%{,]%s*Command:%s*\\*["\'])/?(%l+)', '%1[[:mcw:Befehl/%2|%2]]' )
		else
			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
	end
	return text
end

function p.json(text, type, nocat)
	text = text or ''
	type = type or ''
	if string.find( text, '^%s*"__comment":' ) then
		text = '<span style="color:grey">' .. text .. '</span>'
	elseif 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/Standard-Vorlagen#%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/Standard-Vorlagen#%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/Standard-Vorlagen#%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/Standard-Vorlagen#%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, args.nocat )
end

return p
Advertisement