Modul:Lehensabfrage

Aus TobrienWiki
Version vom 17. Mai 2021, 15:08 Uhr von VolkoV (Diskussion | Beiträge) (Automatisch synchronisiert.)
Zur Navigation springen Zur Suche springen
Dokumentation und Testfälle unter Modul:Lehensabfrage/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 holelehensub(frame,person)
 if person=='' then return '' end
 local s='[[-has subobject::'..person..']] [[Herrscher von BisIndex::99990000]]'
 local a=frame:callParserFunction(
  '#ask',s,
  'mainlabel=-',
  '?Herrscher von Lehen#=',
  'limit=500',
  'searchlabel=',
  'format=plainlist'
 )
 return a
end


function holelehen(frame,familie,manuell)
 if familie=='' then return '' end
 
 --Finde alle lebenden Familienmitglieder
 local s='<q>[[Familienmitglied von::'..familie..']] OR [[Familienmitglied von.Untergruppierung von::'..familie..']]</q> [[Lebend::Ja]]'
 local a=frame:callParserFunction(
  '#ask',s,
  'mainlabel=-',
  '?#-=',
  'limit=500',
  'searchlabel=',
  'format=plainlist'
 )
 
 --Finde alle aktiven Lehen dieser Familienmitglieder
 local result={}
 local doppelte={}
 local t=mw.text.split(a,',',true)
 local eingemischt=false
 for key,value in pairs(t) do
  if (robusttrim(value)~='')or(eingemischt~=true) then
   local l=holelehensub(frame,value)..','..manuell
   eingemischt=true

   --Finde die Art des Lehens dieses Familienmitglieds
   local t2=mw.text.split(l,',',true)
   for key2,value2 in pairs(t2) do
    if robusttrim(value2)~='' then
     local d=holelehenattribut(frame,value2,'Lehenstyp')
     local k=holelehenattribut(frame,value2,'Kurzname')
     local i=holelehenattribut(frame,value2,'Icon ist')
     if doppelte[value2]==nil then
      if(result[d]==nil) then result[d]={} end
      table.insert(result[d],{["Artikel"]=value2,["Kurzname"]=k,["Icon"]=i});
      doppelte[value2]=true;
     end
    end
   end

  end
 end
 return result
end

function holelehenattribut(frame,lehen,attribut)
 if lehen=='' then return 'unbekannt' end
 local a=frame:callParserFunction(
  '#show',lehen,
  '?'..attribut..'#'
 )
 if a=='' then a='unbekannt' end
 return a
end;

function kategorisiereUndHegemon(frame,lehen,title,catname,rekursion,kategorie)
 if kategorie==false then return '' end
 if lehen=='' then return '' end
 if rekursion==0 then return '' end
 local heg=frame:callParserFunction(
  '#show',lehen,
  '?Vasallenlehen von#'
 )
 hegsub=''
 if heg~=''then
  t=mw.title.new(heg).text
  hegsub=kategorisiereUndHegemon(frame,heg,t,catname,rekursion-1,kategorie)
 end

 return '[[Kategorie:'..title..'|'..catname..']]'..hegsub
end

function printlehensub(frame,lehentable,catname,art,artpl,kategorie) 
 result=''
 if(lehentable[art]~=nil) then
  result=''
  for key,value in pairs(lehentable[art]) do
   t=mw.title.new(value["Artikel"]).text
   result=result..'[['..value["Artikel"]..'|'..value["Kurzname"]..']]'..kategorisiereUndHegemon(frame,value["Artikel"],t,catname,7,kategorie)..', '
  end
 end
 result=mw.ustring.sub(result,1,mw.ustring.len(result)-2)
 return frame:callParserFunction('#invoke','Text','Zeile',artpl,result)
end

function printlehen(frame,lehentable,catname,weiterelehen,weitereaemter,kategorie)
 result=''
 result=result..printlehensub(frame,lehentable,catname,'Reich','Reiche',kategorie)
 result=result..printlehensub(frame,lehentable,catname,'Provinz','Provinzen',kategorie)
 result=result..printlehensub(frame,lehentable,catname,'Grafschaft','Grafschaften',kategorie)
 result=result..printlehensub(frame,lehentable,catname,'Baronie','Baronien',kategorie)
 result=result..printlehensub(frame,lehentable,catname,'Junkertum','Junkertümer',kategorie)
 result=result..printlehensub(frame,lehentable,catname,'Herrschaft','Herrschaften',kategorie)
 result=result..frame:callParserFunction('#invoke','Text','Zeile','Weitere Lehen',weiterelehen)
 result=result..frame:callParserFunction('#invoke','Text','Zeile','Weitere Ämter',weitereaemter)
 return frame:callParserFunction('#invoke','Text','Zeilengruppe','Lehen',result)
end

function printleheniconsub(frame,lehentable,art) 
 result=''
 if(lehentable[art]~=nil) then
  result=''
  for key,value in pairs(lehentable[art]) do
   result=result..'[['..value['Icon']..'|20px|link='..value['Artikel']..']]&nbsp;&nbsp;&nbsp;'
  end
 end
 return result
end

function printlehenicon(frame,lehentable)
 result=''
 result=result..printleheniconsub(frame,lehentable,'Reich')
 result=result..printleheniconsub(frame,lehentable,'Provinz')
 result=result..printleheniconsub(frame,lehentable,'Grafschaft')
 result=result..printleheniconsub(frame,lehentable,'Baronie')
 result=result..printleheniconsub(frame,lehentable,'Junkertum')
 result=result..printleheniconsub(frame,lehentable,'Herrschaft')
 return result
end


function p.Abfrage(frame)
 if (frame.args[1]==nil) then
  return "no parameter found"
 end
 catname=robusttrim(frame.args[2])
 weiterelehen=robusttrim(frame.args[3])
 weitereaemter=robusttrim(frame.args[4])
 manuell=robusttrim(frame.args[5])
 local familie=frame.args[1]
 local result=holelehen(frame,familie,manuell)
 frame:callParserFunction('#vardefine','LehensabfrageIcons',printlehenicon(frame,result))
 frame:callParserFunction('#vardefine','Lehensabfrage',printlehen(frame,result,catname,weiterelehen,weitereaemter,false))
 return printlehen(frame,result,catname,weiterelehen,weitereaemter,true)
end

return p