Modul:Koordinaten

Aus GaretienWiki
Zur Navigation springen Zur Suche springen
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Dokumentation und Testfälle unter Modul:Koordinaten/Doku.
	local p = {}
	
	function robusttrim(s)
		if s==nil then return '' end
		local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','')
		p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','')
		return mw.text.trim(p)
	end
	
	function split(inputstr,sep)
		if sep==nil then sep="%s" end
		local t={}
		local i=1
		for str in mw.ustring.gmatch(inputstr,"([^"..sep.."]+)") do
			t[i]=str
			i=i+1
		end
		if i==1 then t[1]=inputstr end
		return t
	end
	
	function holeViewbox(frame,ort)
		if ort=='' then return '' end
		local a=frame:callParserFunction(
			'#show',ort,
			'?Viewbox'
		)
		return a
	end
	
	function holeHandlungsorte(frame,geschichte)
		if geschichte=='' then return '' end
		local a=frame:callParserFunction(
			'#ask','[['..geschichte..']]',
			'mainlabel=-',
			'?Handlungsort ist#=',
			'sep=€'
		)
		return a
	end
	
	function viewboxToKoordinaten(viewbox)
		if viewbox=="" then return "" end
		local result=""
		local width=10000000
		for k,token in pairs(split(viewbox,",")) do
			local subtokens={}
			local i=0
			for k,subtoken in pairs(split(token,"%s")) do
				subtokens[i]=tonumber(subtoken)
				i=i+1
			end
			if subtokens[3] then
				if subtokens[3]<width then
					width=subtokens[3]
					local x=subtokens[0]+subtokens[2]/2
					local y=subtokens[1]+subtokens[3]/2
					result=x..";"..y
				end
			end
		end
		return result
	end
	
	function erzeugeKoordinaten(frame,geschichte,elementtyp)
		if geschichte=='' then return '' end
		local orte=holeHandlungsorte(frame,geschichte)
		
		local ortet=split(orte,'€')

		local result=""
		for key,ort in pairs(ortet) do
			view=holeViewbox(frame,ort)
			koord=viewboxToKoordinaten(view)
			if(koord~="") then
				result=result.."\n\n"..elementtyp..':'..geschichte..";0!14;;"..koord
			end
		end
		
		return result
	end
	
	function p.Koordinaten()
		local frame=mw.getCurrentFrame()
		local geschichte=robusttrim(frame.args[1])
		if(geschichte=='') then return '' end
		local elementtyp=frame:callParserFunction('#var','Elementtyp')
		if(elementtyp=='') then elementtyp='Hauptdarsteller' end
		local gbp=frame:callParserFunction('FULLPAGENAME',geschichte)
		return erzeugeKoordinaten(frame,gbp,elementtyp)
	end
	
	return p