Modul:Person/class: Unterschied zwischen den Versionen
Noémi (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Noémi (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| (81 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 22: | Zeile 22: | ||
-- ClassPerson.static.myPropertyModule = require('Module:extern') | -- ClassPerson.static.myPropertyModule = require('Module:extern') | ||
-- ClassPerson.static.staticProperty = ' ' | -- ClassPerson.static.staticProperty = ' ' | ||
ClassPerson.static.ClassDisciplineAbility = require('Modul:Discipline/ability/class') | |||
ClassPerson.static.myHidden = require('Modul:hidden').main | |||
-- remember the static classes provided by Foundationclass: | -- remember the static classes provided by Foundationclass: | ||
| Zeile 33: | Zeile 35: | ||
-- for properties you should rather use constructor and _private[self]. this only, if you need a private class property | -- for properties you should rather use constructor and _private[self]. this only, if you need a private class property | ||
-- you should, however predeclare private methods here | -- you should, however predeclare private methods here | ||
local | local _abilityLabel -- used to turn a discipline name into a paramter name | ||
local _debug -- private method declared later | local _debug -- private method declared later | ||
local _disciplineParamName -- used to turn a discipline name into a paramter name | local _disciplineParamName -- used to turn a discipline name into a paramter name | ||
| Zeile 79: | Zeile 81: | ||
} | } | ||
local result = ClassPerson.mySmwUtil.ask(query, attributes) | local result = ClassPerson.mySmwUtil.ask(query, attributes) | ||
if result and result[1] and result[1]. | if result and result[1] and result[1].PageName then | ||
val = result[1]. | val = result[1].PageName | ||
else | else | ||
val = false | val = false | ||
| Zeile 98: | Zeile 100: | ||
if result and #result > 0 then | if result and #result > 0 then | ||
for _, row in pairs(result) do | for _, row in pairs(result) do | ||
val[row. | val[row.PageName] = _disciplineParamName(self, row.PageName) | ||
end | end | ||
end | end | ||
| Zeile 115: | Zeile 117: | ||
val = {} | val = {} | ||
for _, row in pairs(result) do | for _, row in pairs(result) do | ||
val[row. | val[row.PageName] = _disciplineParamName(self, row.PageName) | ||
end | end | ||
end | end | ||
| Zeile 132: | Zeile 134: | ||
val = {} | val = {} | ||
for _, row in pairs(result) do | for _, row in pairs(result) do | ||
val[row. | val[row.PageName] = _disciplineParamName(self, row.PageName) | ||
end | end | ||
end | end | ||
| Zeile 213: | Zeile 215: | ||
end | end | ||
function ClassPerson.static:sfGenerateFormTableAbilities() | function ClassPerson.static:sfGenerateFormTableAbilities(fieldlist, tableid) | ||
_debug(self, 1, 'entering ClassPerson.static:sfGenerateFormTableAbilities()') | _debug(self, 1, 'entering ClassPerson.static:sfGenerateFormTableAbilities()') | ||
local _CFG = self.myConfiguration | local _CFG = self.myConfiguration | ||
| Zeile 229: | Zeile 231: | ||
local query = { | local query = { | ||
select = { '[[Is member of class::DisciplineAbility]]' }, | select = { '[[Is member of class::DisciplineAbility]]' }, | ||
fields = { 'Has ability name=name', 'Is associated to page=page'} | fields = { 'Has ability name=name', 'Has level=level', 'Is associated to page#-=page'} | ||
} | } | ||
local attributes = { | local attributes = { | ||
| Zeile 238: | Zeile 240: | ||
if result and #result > 0 then | if result and #result > 0 then | ||
for _, row in pairs(result) do | for _, row in pairs(result) do | ||
local label = _abilityLabel(self, row) | |||
if not abilities[row.page] then | if not abilities[row.page] then | ||
abilities[row.page] = { | abilities[row.page] = {label} | ||
else | else | ||
table.insert(abilities[row.page], | table.insert(abilities[row.page], label) | ||
end | end | ||
end | end | ||
| Zeile 256: | Zeile 259: | ||
if result and #result > 0 then | if result and #result > 0 then | ||
for _, row in pairs(result) do | for _, row in pairs(result) do | ||
fieldname = _disciplineParamName(self, row. | local fieldname = _disciplineParamName(self, row.PageName) | ||
if row. | if row.PageName == 'Thaumaturgie' or row.PageName == 'Nekromantie' then | ||
fielddata[fieldname] = _CFG.parameter[fieldname] | fielddata[fieldname] = _CFG.parameter[fieldname] | ||
else | else | ||
| Zeile 263: | Zeile 266: | ||
cardinality = 'list', | cardinality = 'list', | ||
description = 'Auf welche Ränge/Fähigkeiten hat die Person Zugriff in dieser Disziplin?', | description = 'Auf welche Ränge/Fähigkeiten hat die Person Zugriff in dieser Disziplin?', | ||
label = row. | label = row.PageName, | ||
severity = 'suggested', | severity = 'suggested', | ||
sf = { | sf = { | ||
| Zeile 269: | Zeile 272: | ||
input_type = 'checkboxes', | input_type = 'checkboxes', | ||
mapping_property = 'Has_ability_name', | mapping_property = 'Has_ability_name', | ||
values = abilities[row. | values = abilities[row.PageName], | ||
}, | }, | ||
td_type = 'line', | td_type = 'line', | ||
| Zeile 316: | Zeile 319: | ||
formtable:done() | formtable:done() | ||
:node(hidden) | :node(hidden) | ||
return formtable | return formtable | ||
end | end | ||
| Zeile 365: | Zeile 355: | ||
-- **************** declaration of private methods | -- **************** declaration of private methods | ||
-- use self.class.myConfiguration to access your configuration in a public or a private method that is called by a public method | -- use self.class.myConfiguration to access your configuration in a public or a private method that is called by a public method | ||
_abilityLabel = function (self, attrData) | |||
return '(' .. attrData.level .. ') ' .. attrData.name | |||
end | |||
_debug = function (self, level, text) | _debug = function (self, level, text) | ||
| Zeile 381: | Zeile 374: | ||
_disciplineParamName = function (self, discipline) | _disciplineParamName = function (self, discipline) | ||
--return 'debug module:person/class line 376' | |||
return 'discipline_' .. mw.uri.anchorEncode(mw.ustring.gsub(mw.ustring.lower(discipline), '[äöüß]', '')) | return 'discipline_' .. mw.uri.anchorEncode(mw.ustring.gsub(mw.ustring.lower(discipline), '[äöüß]', '')) | ||
end | |||
local _getAbilitiesForDiscipline = function(self, discipline, args) | |||
_debug(self, 1, 'entering private _getAbilitiesForDiscipline(self, discipline, args) to get abilites for discipline, from ' .. tostring(self)) | |||
_debug(self, 2, ' second parameter is ' .. discipline) | |||
-- _debug(self, 2, ' third parameter is ' .. ClassPerson.myTableTools.printTable(args)) | |||
-- note: 2nd paramter discipline may also represent a path for thaumaturgie or necromancy. mechanics are the same, though | |||
local rank = 0 | |||
local abilities = {} | |||
local html = mw.html.create('') | |||
local ability_bg_colors = { '#DCDCDC', '#D3D3D3', '#C0C0C0', '#A9A9A9', '#999999', '#2F4F4F', } | |||
if not discipline or type(discipline) ~= 'string' or #discipline == 0 then | |||
error('2nd parameter to _getAbilitiesForDiscipline must be a non empty string, depicting a discipline or a path!') | |||
end | |||
if not args or type(args) ~= 'table' then | |||
error('3rd parameter to _getAbilitiesForDiscipline must be a table, containing the arguments passed to the module!') | |||
end | |||
-- first get all abilities for the discipline | |||
local query = { | |||
select = { '[[Is member of class::DisciplineAbility]] [[Is_associated_to_page::' .. discipline .. ']]' }, | |||
fields = { 'has ability name=name', 'has level=level', 'costs_vitae=vitae', 'costs_willpower=willpower', 'needs_roll_on=roll', 'targets=target', 'lasts_for=duration', | |||
'has_short_description=flavour', 'has_instruction=system', 'is_identified_by_classengine_through=id' | |||
}, | |||
} | |||
local attributes = { | |||
sort = 'Has_level,Has ability name', | |||
order = 'asc,asc', | |||
} | |||
local result = ClassPerson.mySmwUtil.ask(query, attributes) | |||
-- now get the correct argument for the discipline and its content | |||
local argument = _disciplineParamName(self, discipline) | |||
if argument and args[argument] and #args[argument] > 0 and result and #result > 0 then | |||
-- at least we have data. | |||
-- now lets see, if any of args[argument] match findings in result. | |||
-- though result is most probably the larger array, we still iterate over it, because the entries in args[argument] are somewhat "coded". | |||
-- finding entries from result in args[argument] is easier. we make it quicker still by inverting the args[argument] array | |||
local abilitesSelected = {} | |||
local argsArray = {} | |||
for fragment in mw.text.gsplit(args[argument], '~') do | |||
table.insert(argsArray, mw.text.trim(fragment)) | |||
end | |||
for _, ability in pairs(argsArray) do | |||
abilitesSelected[ability] = true | |||
end | |||
for _, row in pairs(result) do | |||
if abilitesSelected[_abilityLabel(self, row)] then | |||
-- match found, processing | |||
if row.level > rank then | |||
rank = row.level | |||
end | |||
table.insert(abilities, row.id) | |||
local obj = ClassPerson.ClassDisciplineAbility:new(ClassPerson.ClassDisciplineAbility:getUidFromArgs(row)) | |||
obj:initFromArgs(row) | |||
local color_id = row.level | |||
local additional_headercss = '' | |||
if color_id > 5 then | |||
color_id = 6 | |||
additional_headercss = ';color:white;font-weight:bold' | |||
end | |||
html:wikitext(ClassPerson.myHidden{ | |||
header = obj:prepareRankedHeadline(), | |||
content = '\n' .. tostring(obj:prepareAbilityBody()), | |||
headerstyle = 'padding-left:10px;background:' .. ability_bg_colors[color_id] .. additional_headercss, | |||
ta1 = 'left', | |||
border = '1px solid ' .. ability_bg_colors[color_id], | |||
}) | |||
:newline() | |||
:tag('div') | |||
:css('clear', 'both') | |||
:done() | |||
:newline() | |||
end | |||
end | |||
end | |||
if rank == 0 then | |||
rank = nil | |||
end | |||
if #abilities == 0 then | |||
abilities = nil | |||
end | |||
if #tostring(html) == 0 then | |||
html:wikitext('Keine Fähigkeiten hinterlegt.') | |||
:newline() | |||
:tag('small') | |||
:wikitext('Um Fähigkeiten zu hinterlegen, bitte die Seite per Formular bearbeiten und auf dem Reiter \'\'Fähigkeiten\'\' im Feld \'\'' | |||
.. discipline .. '\'\' gewünschte Fähigkeiten aktivieren!' ) | |||
:done() | |||
end | |||
return rank, abilities, html | |||
end | end | ||
| Zeile 403: | Zeile 486: | ||
end | end | ||
end | end | ||
local ib_args = { | local ib_args = { | ||
bodyclass = 'infobox_person', | bodyclass = 'infobox_person', | ||
| Zeile 449: | Zeile 506: | ||
data5 = coreData.sire and ClassPerson:formRedlink(coreData.sire, 'Person') or (coreData.type == 'Vampir' and 'unbekannt' or nil), | data5 = coreData.sire and ClassPerson:formRedlink(coreData.sire, 'Person') or (coreData.type == 'Vampir' and 'unbekannt' or nil), | ||
label6 = _CFG.parameter.generation.label, | label6 = _CFG.parameter.generation.label, | ||
data6 = coreData.generation and coreData.generation or (coreData.type == 'Vampir' and 'unbekannt' or nil), | data6 = coreData.generation and tostring(coreData.generation) or (coreData.type == 'Vampir' and 'unbekannt' or nil), | ||
label7 = _CFG.parameter.original_generation.label, | label7 = _CFG.parameter.original_generation.label, | ||
data7 = coreData.original_generation and coreData.original_generation or nil, | data7 = coreData.original_generation and tostring(coreData.original_generation) or nil, | ||
label8 = _CFG.parameter.embraced.label, | label8 = _CFG.parameter.embraced.label, | ||
data8 = coreData.embraced and (ClassPerson.myYesno(coreData.embraced_is_estimate) and 'um ' or '') .. coreData.embraced or (coreData.type == 'Vampir' and 'unbekannt' or nil), | data8 = coreData.embraced and (ClassPerson.myYesno(coreData.embraced_is_estimate) and 'um ' or '') .. coreData.embraced or (coreData.type == 'Vampir' and 'unbekannt' or nil), | ||
label9 = _CFG.parameter.apparent_age.label, | label9 = _CFG.parameter.apparent_age.label, | ||
data9 = coreData.apparent_age and coreData.apparent_age or nil, | data9 = coreData.apparent_age and tostring(coreData.apparent_age) or nil, | ||
label13 = _CFG.parameter.residence.label, | label13 = _CFG.parameter.residence.label, | ||
data13 = coreData.residence and ClassPerson:formRedlink(coreData.residence, 'Stadt') or nil, | data13 = coreData.residence and ClassPerson:formRedlink(coreData.residence, 'Stadt') or nil, | ||
| Zeile 461: | Zeile 518: | ||
data14 = coreData.office and coreData.office or nil, | data14 = coreData.office and coreData.office or nil, | ||
label15 = _CFG.parameter.haven.label, | label15 = _CFG.parameter.haven.label, | ||
data15 = haven and mw.text.listToText(haven, ', ', ' und ') or | data15 = haven and mw.text.listToText(haven, ', ', ' und ') or 'unbekannt', | ||
label17 = _CFG.parameter.chapter_of_first_appearance.label, | label17 = _CFG.parameter.chapter_of_first_appearance.label, | ||
data17 = coreData.chapter_of_first_appearance and '[[' .. coreData.chapter_of_first_appearance .. ']]' or nil, | data17 = coreData.chapter_of_first_appearance and '[[' .. coreData.chapter_of_first_appearance .. ']]' or nil, | ||
| Zeile 471: | Zeile 528: | ||
data23 = (coreData.ghuls and #coreData.ghuls > 0) and '[[' .. mw.text.listToText(coreData.ghuls, ']], [[', ']] und [[') ..']]' or nil, | data23 = (coreData.ghuls and #coreData.ghuls > 0) and '[[' .. mw.text.listToText(coreData.ghuls, ']], [[', ']] und [[') ..']]' or nil, | ||
label24 = 'Disziplinen', | label24 = 'Disziplinen', | ||
data24 = | -- data24 = disciplines, | ||
data24 = coreData.ib_disciplines and mw.text.listToText(coreData.ib_disciplines, ', ', ' und ') or nil, | |||
header26 = 'Through the looking glass', | header26 = 'Through the looking glass', | ||
label27 = 'Figurentyp', | label27 = 'Figurentyp', | ||
data27 = coreData.coterie and 'SC' or 'NSC', | data27 = FoundationClass.myYesno(coreData.coterie) and 'SC' or 'NSC', | ||
label28 = _CFG.parameter.player.label, | label28 = _CFG.parameter.player.label, | ||
data28 = coreData.player and coreData.player or nil, | data28 = coreData.player and coreData.player or nil, | ||
label29 = 'Spielteilnahmen', | label29 = 'Spielteilnahmen', | ||
data29 = coreData.history and #coreData.history or nil, | data29 = coreData.history and tostring(#coreData.history) or nil, | ||
} | } | ||
self:addOutput(require('Module:Infobox').infobox(ib_args)) | self:addOutput(require('Module:Infobox').infobox(ib_args)) | ||
| Zeile 501: | Zeile 559: | ||
self:addOutput(self:renderWarnings()) | self:addOutput(self:renderWarnings()) | ||
self:setSortkey(coreData.displayname) | self:setSortkey(coreData.displayname) | ||
self:setDisplayTitle(coreData.displayname) | |||
if self:goodToGo() then | if self:goodToGo() then | ||
local section_htmls = {} | local section_htmls = {} | ||
| Zeile 512: | Zeile 571: | ||
if coreData.history and #coreData.history > 0 then | if coreData.history and #coreData.history > 0 then | ||
for _, data in pairs(coreData.history) do | for _, data in pairs(coreData.history) do | ||
history:wikitext('* ' .. ClassPerson:formRedlink(data.place, 'Stadt') .. ', ' .. data.begin .. (data['end'] and ' - ' .. data['end'] or '') .. ': [[' .. data. | history:wikitext('* ' .. ClassPerson:formRedlink(data.place, 'Stadt') .. ', ' .. data.begin .. (data['end'] and ' - ' .. data['end'] or '') .. ': [[' .. data.PageName .. ']] (' .. data.description .. ')') | ||
:newline() | :newline() | ||
--history:wikitext('* ' .. mw.text.nowiki(ClassPerson.myTableTools.printTable(data))):newline() | |||
end | end | ||
else | else | ||
| Zeile 526: | Zeile 586: | ||
:newline() | :newline() | ||
for _, data in pairs(coreData.mentions) do | for _, data in pairs(coreData.mentions) do | ||
mentions:wikitext('* [[' .. data. | mentions:wikitext('* [[' .. data.PageName .. ']] (Quelle: [[' .. data.source .. ']], Beschreibung: ' .. data.description .. ')') | ||
:newline() | :newline() | ||
end | end | ||
| Zeile 565: | Zeile 625: | ||
section_htmls[sections2params[section]] = element | section_htmls[sections2params[section]] = element | ||
end | end | ||
section_htmls.abilities:node(coreData.section_disciplines) | |||
--[===[ | |||
--[== | |||
local testing = mw.html.create('') | local testing = mw.html.create('') | ||
testing:wikitext('<h3>possesses_ability</h3>') | testing:wikitext('<h3>possesses_ability</h3>') | ||
| Zeile 655: | Zeile 645: | ||
:wikitext((coreData and ClassPerson.myTableTools.printTable(coreData) or 'NIL')) | :wikitext((coreData and ClassPerson.myTableTools.printTable(coreData) or 'NIL')) | ||
:done() | :done() | ||
self:addOutput(testing) | --self:addOutput(testing) | ||
--]===] | |||
self:addOutput(section_htmls.introtext) | self:addOutput(section_htmls.introtext) | ||
| Zeile 666: | Zeile 657: | ||
self:addOutput(section_htmls.comments) | self:addOutput(section_htmls.comments) | ||
local navbox = require('Module:Navbox')._navbox | -- adding the navbox | ||
local navbox = require('Module:Navbox person')._navbox | |||
self:addOutput(navbox({clan=coreData.clan, coterie=true})) | |||
if coreData.clan then | |||
self:addCategory(coreData.clan) | |||
if coreData. | |||
end | end | ||
return true | return true | ||
end | end | ||
| Zeile 697: | Zeile 675: | ||
-- hint: for conversion bool values, this is useful: FoundationClass.myYesno | -- hint: for conversion bool values, this is useful: FoundationClass.myYesno | ||
local coreData = coreData | local coreData = coreData | ||
local thatsMe = self:getUid() | |||
if not coreData.displayname then | if not coreData.displayname then | ||
coreData.displayname = | coreData.displayname = thatsMe | ||
end | end | ||
coreData.displaytitle = coreData.displayname | coreData.displaytitle = coreData.displayname | ||
| Zeile 706: | Zeile 685: | ||
if not coreData.image then | if not coreData.image then | ||
coreData.image = 'Bild:NoCharPic.png' | coreData.image = 'Bild:NoCharPic.png' | ||
self:addCategory('Personen ohne Portrait') | |||
else | else | ||
if mw.ustring.find(coreData.image, ':') then | if mw.ustring.find(coreData.image, ':') then | ||
| Zeile 714: | Zeile 694: | ||
if not coreData.coterie then | if not coreData.coterie then | ||
coreData.coterie = false | coreData.coterie = false | ||
end | |||
if coreData.heaven == 'unbekannt' then | |||
coreData.heaven = nil | |||
end | end | ||
-- the following antitribu calculate should be done dynamically later (once, clans are in the system) | -- the following antitribu calculate should be done dynamically later (once, clans are in the system) | ||
if coreData.sect and coreData.clan then | coreData.antitribu = 'Nein' | ||
if coreData.sect and coreData.clan and coreData.sect ~= 'Anarchen' then | |||
local sects = { | local sects = { | ||
Assamiten = 'Unabhängig', | Assamiten = 'Unabhängig', | ||
| Zeile 738: | Zeile 722: | ||
sects['Harbinger of Skulls'] = 'Sabbat' | sects['Harbinger of Skulls'] = 'Sabbat' | ||
sects['Jünger des Set'] = 'Unabhängig' | sects['Jünger des Set'] = 'Unabhängig' | ||
if sects[coreData.clan] | sects['Töchter der Kakophonie'] = 'Camarilla' | ||
coreData. | if sects[coreData.clan] ~= coreData.sect | ||
and coreData.clan ~= 'Caitiff' | |||
and coreData.clan ~= 'Dünnblütige' | |||
then | |||
coreData.antitribu = 'Ja' | coreData.antitribu = 'Ja' | ||
end | end | ||
end | end | ||
-- get all | -- get all offsprings (children, ghuls) for the person | ||
_debug(self, 2, 'ClassPerson:myArgumentProcessing(): get all offsprings (children, ghuls) for the person') | |||
local children = {} | local children = {} | ||
local ghuls = {} | local ghuls = {} | ||
local query = { | local query = { | ||
select = { '[[is_member_of_class::Person]]' }, | select = { '[[is_member_of_class::Person]]', '[[was_sired_by::' .. self:getUid() .. ']]' }, | ||
fields = { 'is_of_character_type=type | fields = { 'is_of_character_type=type', 'is_member_of_the_coterie=coterie', 'is_member_of_clan=clan' } | ||
} | } | ||
local attributes = { | local attributes = { | ||
| Zeile 761: | Zeile 745: | ||
if result then | if result then | ||
for _, data in pairs(result) do | for _, data in pairs(result) do | ||
if data.sire == | if data.sire == thatsMe then | ||
if data.type == 'Vampir' then | if data.type == 'Vampir' then | ||
table.insert(children, data. | table.insert(children, data.PageName) | ||
elseif data.type == 'Ghul' then | elseif data.type == 'Ghul' then | ||
table.insert(ghuls, data. | table.insert(ghuls, data.PageName) | ||
end | end | ||
end | end | ||
end | end | ||
| Zeile 785: | Zeile 761: | ||
end | end | ||
coreData.children = children | coreData.children = children | ||
coreData.ghuls = ghuls | coreData.ghuls = ghuls | ||
-- now get the characters story | -- now get the characters story | ||
_debug(self, 2, 'ClassPerson:myArgumentProcessing(): now get the characters story') | |||
local query = { | local query = { | ||
select = { '[[is_member_of_class::Chapter]]', '[[has cast::' .. | select = { '[[is_member_of_class::Chapter]]', '[[has cast::' .. thatsMe .. ']]' }, | ||
fields = { 'Took_place_on=begin', 'Took_place_until=end', 'Took_place_in=place', 'Is_titled=title', 'Has_short_description=description' } | fields = { 'Took_place_on=begin', 'Took_place_until=end', 'Took_place_in#=place', 'Is_titled=title', 'Has_short_description=description' } | ||
} | } | ||
local attributes = { | local attributes = { | ||
| Zeile 801: | Zeile 775: | ||
-- get all mentions in texts | -- get all mentions in texts | ||
local query = { | local query = { | ||
select = { '[[is_member_of_class::Text]]', '[[concerns::' .. | select = { '[[is_member_of_class::Text]]', '[[concerns::' .. thatsMe .. ']]' }, | ||
fields = { 'has source=source', 'Has_short_description=description' } | fields = { 'has source#=source', 'Has_short_description=description' } | ||
} | } | ||
local attributes = { | local attributes = { | ||
| Zeile 811: | Zeile 785: | ||
-- and all the information available about this person | -- and all the information available about this person | ||
local query = { | local query = { | ||
select = { '[[is_member_of_class::Info]]', '[[concerns::' .. | select = { '[[is_member_of_class::Info]]', '[[concerns::' .. thatsMe .. ']]' }, | ||
fields = { 'has_source=source', 'holds_information=payload', 'is_about=type', 'is_associated_to_page=page' } | fields = { 'has_source#=source', 'holds_information=payload', 'is_about=type', 'is_associated_to_page#=page' } | ||
} | } | ||
local result = ClassPerson.mySmwUtil.ask(query, {}) | local result = ClassPerson.mySmwUtil.ask(query, {}) | ||
| Zeile 825: | Zeile 799: | ||
end | end | ||
coreData.information = information | coreData.information = information | ||
-- lets see, if the character has any abilities entered | -- lets see, if the character has any abilities entered | ||
local possesses_ability | _debug(self, 2, 'ClassPerson:myArgumentProcessing(): abilities') | ||
local | local possesses_ability | ||
local | local ib_disciplines | ||
local section_disciplines = mw.html.create('') | |||
if coreData.disciplines and #coreData.disciplines > 0 then | if coreData.disciplines and #coreData.disciplines > 0 then | ||
-- so the disciplines parameter is filled. we work with that | |||
possesses_ability = {} | |||
ib_disciplines = {} | |||
local getArgs = require('Module:Arguments').getArgs | |||
local frame = mw.getCurrentFrame() | |||
local args = getArgs(frame) | |||
table.sort(coreData.disciplines) | table.sort(coreData.disciplines) | ||
for _, | for _, discipline in pairs(coreData.disciplines) do | ||
local ib_discipline = '[[' .. discipline .. ']]' | |||
local headline = discipline | |||
local rank = 0 | |||
local html = mw.html.create('') | |||
local ib_paths | |||
if discipline == 'Thaumaturgie' or discipline == 'Nekromantie' then | |||
local disciplineArg = _disciplineParamName(self, discipline) | |||
if coreData[disciplineArg] and #coreData[disciplineArg] > 0 then | |||
path_html = mw.html.create('') | |||
ib_paths = {} | |||
table.sort(coreData[disciplineArg]) | |||
for _, _path in pairs(coreData[disciplineArg]) do | |||
local ib_path = '[[' .. _path .. ']]' | |||
local pathRank, abilities, pathHtml = _getAbilitiesForDiscipline(self, _path, args) | |||
if pathRank and pathRank > 0 then | |||
ib_path = ib_path .. ' (' .. pathRank ..')' | |||
html:wikitext('<h4>' .. _path .. ' (' .. pathRank .. ')</h4>') | |||
:newline() | |||
if pathRank > rank then | |||
rank = pathRank | |||
end | |||
else | |||
html:wikitext('<h4>' .. _path .. '</h4>') | |||
:newline() | |||
end | |||
table.insert(ib_paths, ib_path) | |||
if abilities and #abilities > 0 then | |||
for _, ability in pairs(abilities) do | |||
table.insert(possesses_ability, ability) | |||
end | |||
end | |||
html:node(pathHtml) | |||
end | |||
else | |||
html:wikitext('Keine Pfade hinterlegt.') | |||
:newline() | |||
:tag('small') | |||
:wikitext('Um Pfade zu hinterlegen, bitte die Seite per Formular bearbeiten und auf dem Reiter \'\'Fähigkeiten\'\' im Feld \'\'' | |||
.. discipline .. '\'\' bei einem oder mehreren Pfaden Fähigkeiten aktivieren!' ) | |||
:done() | |||
end | |||
else | |||
local maxRank, abilities, aHtml = _getAbilitiesForDiscipline(self, discipline, args) | |||
rank = maxRank | |||
if abilities and #abilities > 0 then | |||
for _, ability in pairs(abilities) do | |||
table.insert(possesses_ability, ability) | |||
end | |||
end | |||
if aHtml then | |||
html:node(aHtml) | |||
end | |||
end | |||
if rank and rank ~= 0 then | |||
ib_discipline = ib_discipline .. ' (' .. rank .. ')' | |||
headline = headline .. ' (' .. rank .. ')' | |||
end | |||
if ib_paths and #ib_paths > 0 then | |||
ib_discipline = ib_discipline .. ' [' .. mw.text.listToText(ib_paths, ', ', ' und ') .. ']' | |||
end | |||
table.insert(ib_disciplines, ib_discipline) | |||
section_disciplines:wikitext('<h3>' .. headline .. '</h3>') | |||
:newline() | |||
:node(html) | |||
end | end | ||
end | end | ||
coreData.possesses_ability = possesses_ability | |||
coreData.ib_disciplines = ib_disciplines | |||
coreData.section_disciplines = tostring(section_disciplines) | |||
--coreData.section_disciplines = 'LENGTH OF section_disciplines: ' .. #tostring(section_disciplines) | |||
-- and finally some bool adjusts | -- and finally some bool adjusts | ||
Aktuelle Version vom 11. Oktober 2024, 16:54 Uhr
| This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This is a Class Module. It implements a class in Lua using Module:Middleclass and the template class Module:Foundationclass. This class provides methods for managing persons in this wiki.
Usage[Quelltext bearbeiten]
local name = args[1] or args.name or mw.title.getCurrentTitle().rootText
local Class = require('Module:Person/class')
local me = Class:new(mw.title.getCurrentTitle().prefixedText)
me:initFromArgs(args)
me:storeData()
me:addInfobox()
me:addPageBody()
return me:render()
Data Storage
Semantic properties used in this class: |
|---|
|
Methods[Quelltext bearbeiten]
Constructor[Quelltext bearbeiten]
new(uid, superhandler)[Quelltext bearbeiten]
Creates a new Object for the class.
- uid
- variable, optional
- used to identify the object
- superhandler
- object of childclass of Foundationclass, optional
- supply the superhandler, if you instanciate this object within another object. the instanciated object will pass errors and warnings to the superhandler and forgo adding the object category
- return
- object, of the class
public methods[Quelltext bearbeiten]
addInfobox()[Quelltext bearbeiten]
If no errors and data is present, adds an infobox to the object's output.
- return
- boolean, whether adding was successful or not
addPageBody()[Quelltext bearbeiten]
Adds a page body (all content besides the infobox) to the object's output: Errors and Warnings, sample configuration, statistics, ... Of course, only if there is data.
- return
- boolean, whether adding was successful or not
myArgumentProcessing(coreData)[Quelltext bearbeiten]
Performs the individual argument processing in initFromArgs(args) right before inititializing it.
- coreData
- table, mandatory
- the core data of the object. the one to process individually before initialization
- return
- table, the new core data array to be used
myDataAdjustments(data)[Quelltext bearbeiten]
Performs a transformation form data (coming from the datastore) into data used for argument processing. This is called by initFromData(data) (for smw: after property to parameter conversion) and is directly passed to initFromArgs(args) and subsequently plausibility test.
- data
- table, mandatory
- a data table coming directly from the data store
- return
- table, the new data table suiteable for argument processing
myPlausibilityTest(args)[Quelltext bearbeiten]
Performs the individual plausibility tests in initFromArgs(args) before entering the initialization part. NOTE: The return value will be ignored. If this finds errors, it must add them to the list of errors via addError(errortext).
- args
- table, mandatory
- arguments passed to the template to be checked
- return
- boolean, whether the object is plausible or not.
myStashAdjustments(stash, storeType)[Quelltext bearbeiten]
Performs the adjusts the stash in storeData() right before storing it.
- stash
- table, mandatory
- the array of data to be saved (in the form fieldname: value)
- storeType
- string, mandatory
- type of storage method used with the current call (either 'cargo' or 'swm'). In case you use both stores and your stash adjustment differs with each of this methods
- return
- boolean, the new stash
static methods[Quelltext bearbeiten]
ClassPerson:mySfDynamicFieldAttribute(fieldname, attribute, value)[Quelltext bearbeiten]
For some semantic form fields there are attribute values, that are not static, thus can not be provided at forehand in the configuration file. This method does the trick to adapt them at runtime shortly before the field is rendered. Essentially: the method checks, if it has a special rule for the pair fieldname:attribute and if so, calculates the new value. if not, the old value is returned. Note, that you can completely disable a form field with this when you return false on attribute "disable".
- fieldname
- string, mandatory
- the form field's name, needed to match current paring to an existing special treatment rule
- attribute
- string, mandatory
- the form field's attribute, needed to match current paring to an existing special treatment rule
- value
- variable, mandatory
- the value, that is already provided in the configuration file. this will be adapted by the method, if there is a special rule for the pair fieldname:attribute.
- return
- string, the value to be used forthwith (which can be the old one or a freshly calculated)
private methods[Quelltext bearbeiten]
_debug(self, level, text)[Quelltext bearbeiten]
Adds output to the internal debug log.
- self
- object, me
- level
- int; mandatory
- debug level for the message
- text
- string; mandatory
- debug message text
- return
- void
Properties[Quelltext bearbeiten]
static[Quelltext bearbeiten]
See also Static Properties
- ClassPerson.myConfiguration
- this is your configuration. It is devided in several section, each a
- table, holds configuration data found in Module:Person/config
- WARNING: This is a read only table and besides functions pairs() and ipairs() nothing else will work on it, especially not the functions of the table library!
- form, table, holds data used to create the form. here are some of them:
- formButtons, table, which buttons should be printed at the bottom
- fieldOrder, table, in which order the form fields should appear (note: only fields listed here will be added to the form)
- global, table, holds some global configuration data
- parameter, table, holds all data about all parameter used in the module (be they form only, data store only or normal). The table has the form paramname = { table of paramdata }. The tables for the parameter have data as follows:
- cardinality, string, mandatory, one of singe or list
- cargo_type, string, optional, if the parameter is to be stored in cargo, add the field type here (one of Page, Text, Integer, Float, Date, Datetime, Boolean (which should be provided as 1 or 0), Coordinates, Wikitext, File, String, URL, or Email)
- description, string, mandatory, a description of this parameter
- label, string, mandatory, the label used in the form and the template documentation
- property_name, string, optional, if the parameter is to be stored in smw, add the property name here
- property_type, string, optional, if the parameter is to be stored in smw, add the property type here (defaults to page)
- severity, string, optional, if provided one of mandatory, suggested
- sf, table, optional, used to add more attributes to the semantic forms field. ref Module:SFfield/config for all possible attributes. Note that the table is of type attribute_name : value. Value can be of type string, integer, boolean, and (in case of 'show on select') a table. Please note, that the attribute name cannot contain a " " (space). Use the underscore instead.
- td_default, string, optional, if you want a default value to be indicated in the template data section on the documentation page, add it here
- td_type, string, optional, if the parameter should be present in the template documentation page, fill this field. all possible values are listed here
- values, table, optional, if you want the possible values to be restricted to a specific set, fill this table
- template, table, holds some data used only in the template
- ClassPerson.publicStaticProperty
- type, explanation
- _privateStaticProperty
- type, explanation
private[Quelltext bearbeiten]
Note: all private properties are stored in table _private[self]. _private is a static array that is indexed by self, so the table _private[self] holds all properties for instance self.
- dbg
- object, my instance of Module:Debug/class for debugging purposes. only present afer first call of _debug(self, level, text)
Configuration Data[Quelltext bearbeiten]
This class holds its control data in Module:Person/config.
Inheritance[Quelltext bearbeiten]
Note: You still reference those either by self:publicMethod() or ClassPerson:staticMethod() and ClassPerson.staticProperty respectively!
Methods[Quelltext bearbeiten]
Constructor[Quelltext bearbeiten]
| Warning When you instantiate an object from another object, you have to supply the superhandler. Otherwise you might get categorized or defaultsorted! |
| Warning If you want to be able to use initMyself(), then you have to submit the correct uid-value here. The method must be able to identify itself by this value! |
new(uid, superhandler)[Quelltext bearbeiten]
Creates a new Object for the class.
- uid
- variable, suggested
- used to identify the object. defaults to mw.title.getCurrentTitle().prefixedText
- superhandler
- object of childclass of Foundationclass, optional
- supply the superhandler, if you instanciate an object within another object. the instanciated object will pass errors and warnings to the superhandler and forgo adding an object category
- return
- object, of the class
Abstract Methods
Warning You have to implement (thus overwriting) the following abstract methods in your childclass, otherwise the execution of most of your methods will fail! Take note: FoundationClass:mySfDynamicFieldAttribute(fieldname, attribute, value) is a static method, the rest must be declared public! |
myArgumentProcessing(coreData)[Quelltext bearbeiten]
Performs the individual argument processing in initFromArgs(args) right before inititializing it.
- coreData
- table, mandatory
- the core data of the object. the one to process individually before initialization
- return
- table, the new core data array to be used
myDataAdjustments(data)[Quelltext bearbeiten]
Performs a transformation form data (coming from the datastore) into data used for argument processing. This is called by initFromData(data) (for smw: after property to parameter conversion) and is directly passed to initFromArgs(args) and subsequently plausibility test.
- data
- table, mandatory
- a data table coming directly from the data store
- return
- table, the new data table suiteable for argument processing
myPlausibilityTest(args)[Quelltext bearbeiten]
Performs the individual plausibility tests in initFromArgs(args) before entering the initialization part. NOTE: The return value will be ignored. If this finds errors, it must add them to the list of errors via addError(errortext).
- args
- table, mandatory
- arguments passed to the template to be checked
- return
- boolean, whether the object is plausible or not.
myStashAdjustments(stash, storeType)[Quelltext bearbeiten]
Can adjusts the stash in storeData() right before storing it.
- stash
- table, mandatory
- the array of data to be saved (in the form fieldname: value)
- storeType
- string, mandatory
- type of storage method used with the current call (either 'cargo' or 'swm'). In case you use both stores and your stash adjustment differs with each of this methods
- return
- table, the new stash
FoundationClass:mySfDynamicFieldAttribute(fieldname, attribute, value)[Quelltext bearbeiten]
For some semantic form fields there are attribute values, that are not static, thus can not be provided at forehand in the configuration file. This method does the trick to adapt them at runtime shortly before the field is rendered. Essentially: the method checks, if it has a special rule for the pair fieldname:attribute and if so, calculates the new value. if not, the old value is returned. Note, that you can completely disable a form field with this when you return false on attribute "disable".
- fieldname
- string, mandatory
- the form field's name, needed to match current paring to an existing special treatment rule
- attribute
- string, mandatory
- the form field's attribute, needed to match current paring to an existing special treatment rule
- value
- variable, mandatory
- the value, that is already provided in the configuration file. this will be adapted by the method, if there is a special rule for the pair fieldname:attribute.
- return
- string, the value to be used forthwith (which can be the old one or a freshly calculated)
Public methods
addCategory(category)[Quelltext bearbeiten]
Prepares to add the page to category category. Note: until you actually call render() or renderCategories(), this will not be implemented
- category
- string, mandatory
- the name of the category, to add the page to
- return
- boolean, true
addError(errortext)[Quelltext bearbeiten]
adds errortext as new error to the list of errors, rendered at a later time.
- errortext
- string, mandatory
- text added to list of errors
- return
- boolean, whether adding was successful or not
addInfobox()[Quelltext bearbeiten]
If no errors and data is present, adds an infobox to the object's output. NOTE: This is a shell method and should be overwritten!
- return
- boolean, whether adding was successful or not
addOutput(content)[Quelltext bearbeiten]
Adds something to the page's output. Something can be of type string, int, or table (that needs to have __tostring() implemented)
- content
- string, int, or table; mandatory
- content element that is added to page's output
- return
- boolean, whether adding was successful or not
addPageBody()[Quelltext bearbeiten]
Adds a page body (all content besides the infobox) to the object's output: Errors and Warnings, sample configuration, statistics, ... Of course, only if there is data. NOTE: This is a shell method and should be overwritten!
- return
- boolean, whether adding was successful or not
addWarning(warning)[Quelltext bearbeiten]
adds warning as new warning to the list of warnings, to be rendered at a later time (with renderWarnings()).
- warning
- string, mandatory
- text added to list of warnings
- return
- boolean, whether adding was successful or not
getCoreData()[Quelltext bearbeiten]
Returns the table of coreData
- return
- table, the value for _private[self].coreData, emtpy if not initialized
getUid()[Quelltext bearbeiten]
Returns the object's uid, nil if not set
- return
- variable, the value for _private[self].uid
goodToGo()[Quelltext bearbeiten]
Is this a proper object (with data and no errors)
- return
- boolean, whether we are proper initialized
initFromArgs(args)[Quelltext bearbeiten]
Initializes the object with a data table, containing arguments (template parameter). Does plausibility tests and mangling of input and either fills list of errors or adds input to the object's data. {{{1}}}
initFromData(data)[Quelltext bearbeiten]
Initializes the object with a data table, coming from the datastore. Depending on datastore, that means that the table keys might be different than when using arguments form the template. Does plausibility tests and mangling of input and either fills list of errors or adds input to the object's data. {{{1}}}
initMyself(uid)[Quelltext bearbeiten]
Initializes the object with data from the data store. The method queries for the object's uid in the container defined by Foundationclass.globalConfig.uidFieldName (can be set to an infividual name in Module:Foundationclass/globalconfig) in either the class's table (in case of datastore cargo) or for objects that have Foundationclass.globalConfig.smwClassProperty set to class.name (in case of datastore smw). The uid was either passed to the method (priority) or submitted to the constructor. Does NOT do plausibility tests and mangling of input but assumes the data comes directly from the data store and thus can be trusted (i.e. passes _plausibilityTest())
- uid
- string, optional
- the data, the object can use to identify itself. This field can be omitted, in which case the uid that was submitted to the constructor will be used.
- return
- boolean, whether initialization was successful or not
render()[Quelltext bearbeiten]
Renders the object's output
- return
- string, the textual representation of the object (which can vary, depending on what add*-methods you called before)
renderCategories()[Quelltext bearbeiten]
Renders the object's categories (if any), thus adding them to the output stream and in turn sorting the page in it, if and only if render() is called on the object's page (when self:getUid == Person/class).
- return
- object of type mw.html, the wikitext necessary to add the page to the categories
renderErrors()[Quelltext bearbeiten]
Renders the object's errors (if any)
- return
- object of type mw.html, the representation of the list of errors
renderWarnings()[Quelltext bearbeiten]
Renders the object's warnings (if any)
- return
- object of type mw.html, the representation of the list of warnings
setSortkey(sortkey)[Quelltext bearbeiten]
Sets a default sortkey for this page using the magic word DEFAULTSORT. Only applies, if no superhandler is given.
- sortkey
- string, mandatory
- new sortkey for this page
- return
- void
setUid(value)[Quelltext bearbeiten]
Sets my uid to the given value. normally this should be set by constructor
- value
- string/integer, mandatory
- new valued for my uid
- return
- boolean, true/false
storeData()[Quelltext bearbeiten]
If this was initialized with outside data and there are no errors, stores the arguments in an appropriate data store (smw or cargo). In case of cargo, also calls the necessary #cargo_declare parser function if in the template namespace.
- return
- boolean, whether store was successful or not
Static methods
FoundationClass:categorize()[Quelltext bearbeiten]
Placed on one to class's pages (usually not on the class object pages), this calculates the necessary (meta-) category, to put the page in, using pagetitle, subpagetitle, namespace, and so on. Your project's categories (defined in Module:Foundationclass/globalconfig) are used.
- return
- string, to be put on page, so that it will be categorized
FoundationClass:categoryPage()[Quelltext bearbeiten]
Procudes the output for our corresponding category page. Including the message box and the display of the data structure.
- return
- object of type mw.html, the representation of the category page's content
FoundationClass:cargoGenerateTableStructure()[Quelltext bearbeiten]
Produces a cargo table declaration array (fieldname => declaration of field) that can be used in method storeData() for cargo_declare.
- return
- table, data structure for cargo table
FoundationClass:explainDataStore()[Quelltext bearbeiten]
Produces a textual explanation of the used datastructure (table definition for cargo or property list and types for smw) that can be printed on various dodumentation pages
- return
- string, a textual explanation
FoundationClass:formRedlink(target, form, linktext, queryString)[Quelltext bearbeiten]
Takes a pagename (target) and a formname (form) and then generates a link to that page if the page exists. Otherwise it links to the form to create the page. Linktext is target per default, if you do not provide linktext
- target
- string, mandatory
- the pagename (including namespace) to link to
- form
- string, mandatory
- the name of the form (w/o the form namespace!!) to fallback to, if page does not exist
- linktext
- string, optional
- text you want to display instead of target
- queryString
- string, optional
- the query string provided to the form, e.g.
'Template[page]=' .. mw.title.getCurrentTitle().prefixedText - return
- string, the requested link
FoundationClass:gardeningCategoryPage()[Quelltext bearbeiten]
Procudes the output for the class' gardening category page (if any). Includung the message boxes.
- return
- object of type mw.html, the representation of the gardening category page's content
FoundationClass:mwLink(object)[Quelltext bearbeiten]
Takes object and links it (adding square brackets). If object is a table, it iterates over it with lua's mw.text.listToText()
- object
- mixed
- object to return as linked string(s)
- return
- string, with all elements of object mw-linked
FoundationClass:placeInNamespace(pagename, namespace)[Quelltext bearbeiten]
Makes sure, that (string) pagename resides in (string) namespace. Returns the pagename w/ new namespace and w/o any namespace
- pagename
- string
- name of page to be prepended with new namespace
- namespace
- string
- new namespace for page
- return
- string, full page name in new namespace
- string, base page name without any namespace
FoundationClass:sfGenerateForm()[Quelltext bearbeiten]
Generates all output necessary for a form, that can be used to create or maintain an object of this class. Note: this output is to be put inside the <includeonly>-tag on the Form page.
- return
- object of class mw.html, the representation of the form
FoundationClass:sfGenerateFormEntry()[Quelltext bearbeiten]
Generates the "teaser" text shown on the form page when accessing it to create a form (before you type in the name in the input field)
- return
- object of class mw.html, the representation of the form teaser
FoundationClass:sfGenerateFormInfoTag()[Quelltext bearbeiten]
Generates a form's info-tag, together with create and edit title and - if applicable - the query string (in case we have createLinkType formlink).
- return
- string, a semantic form info tag
FoundationClass:sfGenerateFormLink(params)[Quelltext bearbeiten]
Generates a form input field or a form link that links to the class's form (essentially calls the parser function #forminput or #formlink respectively).
- params
- table, data to pass to the form link/input generator. supported fields are: label and query string
- return
- string, the input field, that lints to the form
FoundationClass:sfGenerateFormTable(fieldlist)[Quelltext bearbeiten]
Generates a table that can be used in a form inside the {{{for template}}} tag. The table contains all fields, that are named in the table parameter fieldlist (which defaults to _CFG.form.fieldOrder) and that are present in _CFG.parameter.. All fields with attribute hidden are placed after the closing /table-tag
- fieldlist
- table, optional
- contains a list of fieldnames, to be processed and added to the return node.
- return
- object of class mw.html, the representation of the formtable
FoundationClass:sfInitField(fieldname)[Quelltext bearbeiten]
Creates a field object of Class SFfield and initializes it per myConfiguration.parameters[fieldname] if entry is present
- fieldname
- string, mandatory
- contains the name of the field to initialize
- return
- object of Class SFfield, the initialized field object. nil if fieldname is not present in parameter-array
FoundationClass:smwGetProperty2ParameterTranslationTable()[Quelltext bearbeiten]
Returns a translation table property-name => parametername, if data store smw is used.
- return
- table, for every property used in the class the corresponding parameter name
FoundationClass:templateDocumentation()[Quelltext bearbeiten]
Generates almost all the output, necessary to have a good documentation page for the corresponding template. Only missing the {{documentation subpage}} call at the top and the includeonly part at the bottom.
- return
- object of class mw.html, the representation of the template documentation
FoundationClass:usesDataStore(store)[Quelltext bearbeiten]
Returs true, if class uses store as datastore. Available stores are 'cargo' and 'smw'
- store
- string, mandatory
- store type to check against
- return
- bool, whether store store is used as data store
Static Properties[Quelltext bearbeiten]
- FoundationClass.globalConfig
- table, holds some global configuration (data, that applies to all classes the same way). See Module:Foundationclass/globalconfig for details.
- FoundationClass.myCargoUtil
- table, instance of Module:CargoUtil
- FoundationClass.mySwmUtil
- table, instance of Module:SmwUtil
- FoundationClass.myTableTools
- table, instance of Module:TableTools
- FoundationClass.myYesno
- table, instance of Module:Yesno
Maintenanace notes
This page was created by Module:Classgenerator and belongs to Class:Person.
local FoundationClass = require('Module:Foundationclass')
local ClassDebug = require('Module:Debug/class')
local ClassSFfield = require('Module:SFfield/class')
-- ****************************************************************
-- * inheritance *
-- ****************************************************************
local ClassPerson = FoundationClass:subclass('Person')
-- setting class's configuration data
ClassPerson.static.myConfiguration = mw.loadData('Module:Person/config')
-- being in a static method, use self.myConfiguration
-- being in a private method, that knows self or in a public method, use self.class.myConfiguration
-- ****************************************************************
-- * properties *
-- ****************************************************************
-- **************** initialization of table for private properties
local _private = setmetatable({}, {__mode = 'k'}) -- weak table storing all private attributes
-- **************** declaration of public static properties
-- ClassPerson.static.myPropertyModule = require('Module:extern')
-- ClassPerson.static.staticProperty = ' '
ClassPerson.static.ClassDisciplineAbility = require('Modul:Discipline/ability/class')
ClassPerson.static.myHidden = require('Modul:hidden').main
-- remember the static classes provided by Foundationclass:
-- ClassPerson.globalConfig
-- ClassPerson.myCargoUtil
-- ClassPerson.mySmwUtil
-- ClassPerson.myTableTools
-- ClassPerson.myYesno
-- **************** declaration of (global) private properties
-- for properties you should rather use constructor and _private[self]. this only, if you need a private class property
-- you should, however predeclare private methods here
local _abilityLabel -- used to turn a discipline name into a paramter name
local _debug -- private method declared later
local _disciplineParamName -- used to turn a discipline name into a paramter name
local _privateMethodAhead -- declaration ahead, so this private method can be used in the constructor and in other private methods
-- ***************************************************************
-- * methods *
-- ***************************************************************
-- **************** declaration of static methods
function ClassPerson:initialize(uid, superhandler)
local _CFG = self.class.myConfiguration
FoundationClass.initialize(self, uid, superhandler)
_private[self] = {
dbg = ClassDebug:new(tostring(self.class) .. ': id ' .. uid),
}
_debug(self, 1, ' ClassPerson: done initializing object "' .. uid ..'", from ' .. tostring(self))
end
-- use use self.myConfiguration to access your configuration in a static method
function ClassPerson.static:aStaticMethod(var)
_debug(self, 1, 'entering ClassPerson.static:aStaticMethod() to do something, from ' .. tostring(self))
end
function ClassPerson.static:mySfDynamicFieldAttribute(fieldname, attribute, value)
_debug(self, 1, 'entering ClassPerson.static:mySfDynamicFieldAttribute(fieldname, attribute, value), from ' .. tostring(self))
_debug(self, 2, ' with parameters "' .. fieldname .. '", "' .. attribute .. '" and a ' .. type(value) .. ' value')
-- function that can process any attribute/value pair just before rendering the semantic forms field
-- usually done, to generate a dynamic 'default' value
-- keep in mind: you can completely disable a form field, if you return true on attribute "disable".
-- however, this causes the parameter to not show at all, neither in the form, nor in processing
local val = value
if fieldname == 'fullname' and attribute == 'default' then
val = mw.title.getCurrentTitle().text
end
if (fieldname == 'chapter_of_first_appearance' or fieldname == 'died_in_chapter') and attribute == 'default' then
local query = {
select = {'[[is_member_of_class::Chapter]]'},
fields = {'Is_titled'}
}
local attributes = {
limit = 1,
sort = 'was_written_on',
order = 'desc',
}
local result = ClassPerson.mySmwUtil.ask(query, attributes)
if result and result[1] and result[1].PageName then
val = result[1].PageName
else
val = false
end
end
if fieldname == 'disciplines' and attribute == 'show_on_select' then
val = {}
local query = {
select = { '[[Kategorie:Disziplinen]] [[is path of::Nein]]' },
fields = { 'is path of=path', }
}
local attributes = {
sort = 'has display title',
order = 'asc',
}
local result = ClassPerson.mySmwUtil.ask(query, attributes)
if result and #result > 0 then
for _, row in pairs(result) do
val[row.PageName] = _disciplineParamName(self, row.PageName)
end
end
end
if fieldname == 'discipline_nekromantie' and attribute == 'show_on_select' then
local query = {
select = { '[[Kategorie:Disziplinen]] [[is path of::Nekromantie]]' },
fields = { 'is path of=path', }
}
local attributes = {
sort = 'has display title',
order = 'asc',
}
local result = ClassPerson.mySmwUtil.ask(query, attributes)
if result and #result > 0 then
val = {}
for _, row in pairs(result) do
val[row.PageName] = _disciplineParamName(self, row.PageName)
end
end
end
if fieldname == 'discipline_thaumaturgie' and attribute == 'show_on_select' then
local query = {
select = { '[[Kategorie:Disziplinen]] [[is path of::Thaumaturgie]]' },
fields = { 'is path of=path', }
}
local attributes = {
sort = 'has display title',
order = 'asc',
}
local result = ClassPerson.mySmwUtil.ask(query, attributes)
if result and #result > 0 then
val = {}
for _, row in pairs(result) do
val[row.PageName] = _disciplineParamName(self, row.PageName)
end
end
end
return val -- this value will be used as new value for field's attribute
end
function ClassPerson.static:sfGenerateForm()
_debug(self, 1, 'entering ClassPerson.static:sfGenerateForm()')
local _CFG = self.myConfiguration
local mbox = require('Module:Message box')
local tagStart = '{{{'
local tagEnd = '}}}'
local frame = mw.getCurrentFrame()
-- create the form header
local notification = mw.html.create('')
if _CFG.form.notification and mw.ustring.len(_CFG.form.notification) > 0 then
notification:wikitext(mbox.main('ombox', { text = _CFG.form.notification }))
:newline()
end
local formheader = mw.html.create('')
formheader:wikitext(self:sfGenerateFormInfoTag())
:wikitext('<h2>' .. _CFG.global.entityTitle .. '</h2>')
:tag('p')
:wikitext(_CFG.form.headerText)
:done()
:newline()
:node(notification)
:tag('div')
:attr('id', 'wikiPreview')
:cssText('display: none; padding-bottom: 25px; margin-bottom: 25px; border-bottom: 1px solid #AAAAAA;')
:done()
:newline()
-- create the form buttons
local formbuttons = mw.html.create('div') -- we have to use a div here. this somehow helps the includes/SF_FormPrinter.php to correcly place the fieldset (blue box) around the form
if FoundationClass.myTableTools.inTable(_CFG.form.buttons, 'summary') then
formbuttons:tag('p')
:wikitext(tagStart .. 'standard input|summary' .. tagEnd)
:done()
:newline()
end
for _, button in pairs(_CFG.form.buttons) do
if button ~= 'summary' then
formbuttons:wikitext(tagStart .. 'standard input|' .. button .. tagEnd)
end
end
formbuttons:addClass('formbuttons')
:done()
-- assemble everything
-- start the html object
local html = mw.html.create('div') -- we need this div, otherwise the embedded template will fail
html:node(formheader)
:wikitext('__NOGLOSSARY__<h1>Personendaten</h1>')
:newline()
:wikitext(tagStart .. 'for template|' .. _CFG.template.name .. '|label=' .. _CFG.global.entityTitle .. tagEnd)
:newline()
:node(self:sfGenerateFormTable(_CFG.form.tab_maindata))
:wikitext('<h1>Fähigkeiten</h1>')
:newline()
:node(self:sfGenerateFormTableAbilities())
:newline()
:wikitext('<h1>Weitere Informationen</h1>')
:newline()
:node(self:sfGenerateFormTable(_CFG.form.tab_information))
:newline()
:wikitext(frame:extensionTag('headertabs'))
:newline()
:wikitext("'''(*) Pflichtfeld'''")
:newline()
:wikitext(tagStart .. 'end template' .. tagEnd)
:newline()
:node(formbuttons)
local debugLevel = FoundationClass.globalConfig.debugLevel or self.myConfiguration.global.debugLevel
if debugLevel then
html:newline()
:newline()
:wikitext(ClassDebug:printLog(debugLevel))
end
return html
end
function ClassPerson.static:sfGenerateFormTableAbilities(fieldlist, tableid)
_debug(self, 1, 'entering ClassPerson.static:sfGenerateFormTableAbilities()')
local _CFG = self.myConfiguration
ClassSFfield:setDefaultSize(_CFG.form.fieldSize)
ClassSFfield:setDefaultTextAreaCols(_CFG.form.textareaAttributes.cols)
ClassSFfield:setDefaultTextAreaEditor(_CFG.form.textareaAttributes.editor)
ClassSFfield:setDefaultTextAreaRows(_CFG.form.textareaAttributes.rows)
local abilities = {}
local fieldlist = {'abilities', 'disciplines'}
local fielddata = {
abilities = _CFG.parameter.abilities,
disciplines = _CFG.parameter.disciplines,
}
local fieldlist_helper = {}
local query = {
select = { '[[Is member of class::DisciplineAbility]]' },
fields = { 'Has ability name=name', 'Has level=level', 'Is associated to page#-=page'}
}
local attributes = {
sort = 'Is associated to page,Has_level,Has ability name',
order = 'asc,asc,asc',
}
local result = ClassPerson.mySmwUtil.ask(query, attributes)
if result and #result > 0 then
for _, row in pairs(result) do
local label = _abilityLabel(self, row)
if not abilities[row.page] then
abilities[row.page] = {label}
else
table.insert(abilities[row.page], label)
end
end
end
local query = {
select = { '[[Kategorie:Disziplinen]]' },
fields = { 'is path of=path', }
}
local attributes = {
sort = 'has display title',
order = 'asc',
}
local result = ClassPerson.mySmwUtil.ask(query, attributes)
if result and #result > 0 then
for _, row in pairs(result) do
local fieldname = _disciplineParamName(self, row.PageName)
if row.PageName == 'Thaumaturgie' or row.PageName == 'Nekromantie' then
fielddata[fieldname] = _CFG.parameter[fieldname]
else
fielddata[fieldname] = {
cardinality = 'list',
description = 'Auf welche Ränge/Fähigkeiten hat die Person Zugriff in dieser Disziplin?',
label = row.PageName,
severity = 'suggested',
sf = {
delimiter='~',
input_type = 'checkboxes',
mapping_property = 'Has_ability_name',
values = abilities[row.PageName],
},
td_type = 'line',
}
end
local fieldlist_helper_index = _disciplineParamName(self, row.path)
if not fieldlist_helper[fieldlist_helper_index] then
fieldlist_helper[fieldlist_helper_index] = {fieldname}
else
table.insert(fieldlist_helper[fieldlist_helper_index], fieldname)
end
end
end
local startIndex = _disciplineParamName(self, 'Nein')
if fieldlist_helper[startIndex] and #fieldlist_helper[startIndex] > 0 then
for _, fname in pairs(fieldlist_helper[startIndex]) do
table.insert(fieldlist, fname)
if fieldlist_helper[fname] then
for _, fname2 in pairs(fieldlist_helper[fname]) do
table.insert(fieldlist, fname2)
end
end
end
end
-- now generate the table
-- now create the form table
local hidden = mw.html.create('')
local formtable = mw.html.create('table')
for _, fieldname in pairs(fieldlist) do
if fielddata[fieldname] and not self:mySfDynamicFieldAttribute(fieldname, 'disable', false) then
local field = self:sfInitFieldAbility(fieldname, fielddata[fieldname])
if field then
if field:get('hidden') then
hidden:wikitext(field:render())
else
formtable:node(field:createTr(fielddata[fieldname].label, fielddata[fieldname].description))
end
end
end
end
formtable:addClass(FoundationClass.globalConfig.formTableClass)
:css('width', 'auto')
if tableid then
formtable:attr('id', tableid)
end
formtable:done()
:node(hidden)
return formtable
end
function ClassPerson.static:sfInitFieldAbility(fieldname, fielddata)
_debug(self, 1, 'entering ClassPerson.static:sfInitFieldAbility(fieldname) to initialize field ' .. fieldname or 'NOT SET' .. ', from ' .. tostring(self))
local _CFG = self.myConfiguration
local field
if fieldname and fielddata and fielddata.sf and not self:mySfDynamicFieldAttribute(fieldname, 'disable', false) then
field = ClassSFfield:new(fieldname)
if fielddata.cardinality and fielddata.cardinality == 'list' then
field:set('list', self:mySfDynamicFieldAttribute(fieldname, 'list', true))
local delimiter = fielddata.sf and fielddata.sf.delimiter or _CFG.global.delimiter
-- if we have a global or local delimiter set which is not the comma (','), provide it here automatically
if delimiter ~= ',' then
field:set('delimiter', self:mySfDynamicFieldAttribute(fieldname, 'delimiter', delimiter))
end
end
if fielddata.severity and fielddata.severity == 'mandatory' then
field:set('mandatory', self:mySfDynamicFieldAttribute(fieldname, 'mandatory', true))
end
if fielddata.values then
field:set('values', self:mySfDynamicFieldAttribute(fieldname, 'values', fielddata.values))
end
if fielddata.sf then
for attr, val in pairs(fielddata.sf) do
field:set(mw.ustring.gsub(attr, '_', ' '),
self:mySfDynamicFieldAttribute(fieldname, attr, val) -- remember: self refers to a class, not an object and this method is static
)
end
end
end
return field
end
-- **************** declaration of private methods
-- use self.class.myConfiguration to access your configuration in a public or a private method that is called by a public method
_abilityLabel = function (self, attrData)
return '(' .. attrData.level .. ') ' .. attrData.name
end
_debug = function (self, level, text)
if _private[self] and _private[self].dbg then
local debugLevel = FoundationClass.globalConfig.debugLevel or self.class.myConfiguration.global.debugLevel
if debugLevel and level <= debugLevel then
_private[self].dbg:log(level, text)
end
else
local debugLevel = FoundationClass.globalConfig.debugLevel or self.myConfiguration.global.debugLevel
if debugLevel and level <= debugLevel then
ClassDebug:log(level, text, tostring(self) .. '.static')
end
end
end
_disciplineParamName = function (self, discipline)
--return 'debug module:person/class line 376'
return 'discipline_' .. mw.uri.anchorEncode(mw.ustring.gsub(mw.ustring.lower(discipline), '[äöüß]', ''))
end
local _getAbilitiesForDiscipline = function(self, discipline, args)
_debug(self, 1, 'entering private _getAbilitiesForDiscipline(self, discipline, args) to get abilites for discipline, from ' .. tostring(self))
_debug(self, 2, ' second parameter is ' .. discipline)
-- _debug(self, 2, ' third parameter is ' .. ClassPerson.myTableTools.printTable(args))
-- note: 2nd paramter discipline may also represent a path for thaumaturgie or necromancy. mechanics are the same, though
local rank = 0
local abilities = {}
local html = mw.html.create('')
local ability_bg_colors = { '#DCDCDC', '#D3D3D3', '#C0C0C0', '#A9A9A9', '#999999', '#2F4F4F', }
if not discipline or type(discipline) ~= 'string' or #discipline == 0 then
error('2nd parameter to _getAbilitiesForDiscipline must be a non empty string, depicting a discipline or a path!')
end
if not args or type(args) ~= 'table' then
error('3rd parameter to _getAbilitiesForDiscipline must be a table, containing the arguments passed to the module!')
end
-- first get all abilities for the discipline
local query = {
select = { '[[Is member of class::DisciplineAbility]] [[Is_associated_to_page::' .. discipline .. ']]' },
fields = { 'has ability name=name', 'has level=level', 'costs_vitae=vitae', 'costs_willpower=willpower', 'needs_roll_on=roll', 'targets=target', 'lasts_for=duration',
'has_short_description=flavour', 'has_instruction=system', 'is_identified_by_classengine_through=id'
},
}
local attributes = {
sort = 'Has_level,Has ability name',
order = 'asc,asc',
}
local result = ClassPerson.mySmwUtil.ask(query, attributes)
-- now get the correct argument for the discipline and its content
local argument = _disciplineParamName(self, discipline)
if argument and args[argument] and #args[argument] > 0 and result and #result > 0 then
-- at least we have data.
-- now lets see, if any of args[argument] match findings in result.
-- though result is most probably the larger array, we still iterate over it, because the entries in args[argument] are somewhat "coded".
-- finding entries from result in args[argument] is easier. we make it quicker still by inverting the args[argument] array
local abilitesSelected = {}
local argsArray = {}
for fragment in mw.text.gsplit(args[argument], '~') do
table.insert(argsArray, mw.text.trim(fragment))
end
for _, ability in pairs(argsArray) do
abilitesSelected[ability] = true
end
for _, row in pairs(result) do
if abilitesSelected[_abilityLabel(self, row)] then
-- match found, processing
if row.level > rank then
rank = row.level
end
table.insert(abilities, row.id)
local obj = ClassPerson.ClassDisciplineAbility:new(ClassPerson.ClassDisciplineAbility:getUidFromArgs(row))
obj:initFromArgs(row)
local color_id = row.level
local additional_headercss = ''
if color_id > 5 then
color_id = 6
additional_headercss = ';color:white;font-weight:bold'
end
html:wikitext(ClassPerson.myHidden{
header = obj:prepareRankedHeadline(),
content = '\n' .. tostring(obj:prepareAbilityBody()),
headerstyle = 'padding-left:10px;background:' .. ability_bg_colors[color_id] .. additional_headercss,
ta1 = 'left',
border = '1px solid ' .. ability_bg_colors[color_id],
})
:newline()
:tag('div')
:css('clear', 'both')
:done()
:newline()
end
end
end
if rank == 0 then
rank = nil
end
if #abilities == 0 then
abilities = nil
end
if #tostring(html) == 0 then
html:wikitext('Keine Fähigkeiten hinterlegt.')
:newline()
:tag('small')
:wikitext('Um Fähigkeiten zu hinterlegen, bitte die Seite per Formular bearbeiten und auf dem Reiter \'\'Fähigkeiten\'\' im Feld \'\''
.. discipline .. '\'\' gewünschte Fähigkeiten aktivieren!' )
:done()
end
return rank, abilities, html
end
local _privateMethod = function (self)
_debug(self, 1, 'entering private _privateMethod() to do something, from ' .. tostring(self))
end
-- **************** declaration of public methods
-- use self.class.myConfiguration to access your configuration in a public method
function ClassPerson:addInfobox()
_debug(self, 1, 'entering ClassPerson:addInfobox(), from ' .. tostring(self))
if self:goodToGo() then
local _CFG = self.class.myConfiguration
local coreData = self:getCoreData()
local name = coreData.fullname or coreData.displayname
local haven
if coreData.haven and #coreData.haven > 0 then
haven = {}
for _, h in pairs(coreData.haven) do
table.insert(haven, ClassPerson:formRedlink(h, 'Schauplatz'))
end
end
local ib_args = {
bodyclass = 'infobox_person',
titleclass = 'objtitle titletext',
aboveclass = 'headertext typ_' .. mw.ustring.lower(coreData.type),
headerclass = 'headertext typ_' .. mw.ustring.lower(coreData.type),
labelstyle = 'width: 40%;',
datastyle = 'width: 60%;',
title = name,
above = coreData.type,
image = coreData.image and '[[' .. coreData.image ..'|300px|' .. name .. ']]' or '[[Bild:NoCharPic.png|300px|Kein Bild vorhanden]]',
caption = coreData.displayname,
label1 = _CFG.parameter.coterie.label,
data1 = (ClassPerson.myYesno(coreData.coterie) and 'Ja' or 'Nein'),
label2 = _CFG.parameter.sect.label,
data2 = coreData.sect and '[[' .. coreData.sect .. ']]' or (coreData.type == 'Vampir' and 'unbekannt' or nil),
label3 = _CFG.parameter.clan.label,
data3 = coreData.clan and ClassPerson:formRedlink(coreData.clan, 'Clan') .. (ClassPerson.myYesno(coreData.antitribu) and ' antitribu' or '') or (coreData.type == 'Vampir' and 'unbekannt' or nil),
label5 = _CFG.parameter.sire.label,
data5 = coreData.sire and ClassPerson:formRedlink(coreData.sire, 'Person') or (coreData.type == 'Vampir' and 'unbekannt' or nil),
label6 = _CFG.parameter.generation.label,
data6 = coreData.generation and tostring(coreData.generation) or (coreData.type == 'Vampir' and 'unbekannt' or nil),
label7 = _CFG.parameter.original_generation.label,
data7 = coreData.original_generation and tostring(coreData.original_generation) or nil,
label8 = _CFG.parameter.embraced.label,
data8 = coreData.embraced and (ClassPerson.myYesno(coreData.embraced_is_estimate) and 'um ' or '') .. coreData.embraced or (coreData.type == 'Vampir' and 'unbekannt' or nil),
label9 = _CFG.parameter.apparent_age.label,
data9 = coreData.apparent_age and tostring(coreData.apparent_age) or nil,
label13 = _CFG.parameter.residence.label,
data13 = coreData.residence and ClassPerson:formRedlink(coreData.residence, 'Stadt') or nil,
label14 = _CFG.parameter.office.label,
data14 = coreData.office and coreData.office or nil,
label15 = _CFG.parameter.haven.label,
data15 = haven and mw.text.listToText(haven, ', ', ' und ') or 'unbekannt',
label17 = _CFG.parameter.chapter_of_first_appearance.label,
data17 = coreData.chapter_of_first_appearance and '[[' .. coreData.chapter_of_first_appearance .. ']]' or nil,
label18 = _CFG.parameter.died_in_chapter.label,
data18 = coreData.died_in_chapter and '[[' .. coreData.died_in_chapter .. ']]' or nil,
label22 = 'Bekannte Kinder',
data22 = (coreData.children and #coreData.children > 0) and '[[' .. mw.text.listToText(coreData.children, ']], [[', ']] und [[') ..']]' or nil,
label23 = 'Bekannte Ghule',
data23 = (coreData.ghuls and #coreData.ghuls > 0) and '[[' .. mw.text.listToText(coreData.ghuls, ']], [[', ']] und [[') ..']]' or nil,
label24 = 'Disziplinen',
-- data24 = disciplines,
data24 = coreData.ib_disciplines and mw.text.listToText(coreData.ib_disciplines, ', ', ' und ') or nil,
header26 = 'Through the looking glass',
label27 = 'Figurentyp',
data27 = FoundationClass.myYesno(coreData.coterie) and 'SC' or 'NSC',
label28 = _CFG.parameter.player.label,
data28 = coreData.player and coreData.player or nil,
label29 = 'Spielteilnahmen',
data29 = coreData.history and tostring(#coreData.history) or nil,
}
self:addOutput(require('Module:Infobox').infobox(ib_args))
return true
end
return false
end
function ClassPerson:addPageBody()
_debug(self, 1, 'entering ClassPerson:addPageBody(), from ' .. tostring(self))
_debug(self, 2, ' rendering errors and warnings and adding them to output')
local frame = mw.getCurrentFrame()
local coreData = self:getCoreData()
-- this is used in conjunction with the extension CSS and the parser function #css to disable the virtual editor on person pages
local css = [==[
#ca-ve-edit {
display: none !important;
}
]==]
frame:callParserFunction('#css:' .. css)
self:addOutput(self:renderErrors())
self:addOutput(self:renderWarnings())
self:setSortkey(coreData.displayname)
self:setDisplayTitle(coreData.displayname)
if self:goodToGo() then
local section_htmls = {}
if coreData.introtext then
section_htmls.introtext = coreData.introtext .. '\n'
end
-- assemble character history
local history = mw.html.create('')
history:wikitext('<h2>Werdegang</h2>')
:newline()
if coreData.history and #coreData.history > 0 then
for _, data in pairs(coreData.history) do
history:wikitext('* ' .. ClassPerson:formRedlink(data.place, 'Stadt') .. ', ' .. data.begin .. (data['end'] and ' - ' .. data['end'] or '') .. ': [[' .. data.PageName .. ']] (' .. data.description .. ')')
:newline()
--history:wikitext('* ' .. mw.text.nowiki(ClassPerson.myTableTools.printTable(data))):newline()
end
else
history:wikitext('keine Daten vorliegend')
:newline()
end
section_htmls.history = history
-- display the mentions in texts
if coreData.mentions and #coreData.mentions > 0 then
local mentions = mw.html.create('')
mentions:wikitext('<h2>Textuelle Erwähnungen</h2>')
:newline()
for _, data in pairs(coreData.mentions) do
mentions:wikitext('* [[' .. data.PageName .. ']] (Quelle: [[' .. data.source .. ']], Beschreibung: ' .. data.description .. ')')
:newline()
end
section_htmls.mentions = mentions
end
-- gather all infos added in chapters for this person
local sections = {'Hintergrund', 'Fähigkeiten', 'Verbindungen', 'Agenda', 'Kommentare'}
local sections2params = {
Hintergrund = 'background',
Verbindungen = 'relations',
Agenda = 'agenda',
Kommentare = 'comments',
}
sections2params['Fähigkeiten'] = 'abilities'
for _, section in pairs(sections) do
local payload
if coreData[sections2params[section]] then
payload = coreData[sections2params[section]] .. '\n'
end
if coreData.information[section] and #coreData.information[section] > 0 then
if payload then
payload = payload .. '\n<b>Automatisch hinzugefügt:</b><br>\n'
else
payload = ''
end
for _, info in pairs(coreData.information[section]) do
payload = payload .. '* ' .. info.payload .. ' (Quelle: [[' .. info.source .. ']], siehe auch [[' .. info.page .. ']])\n'
end
end
if not payload or #payload == 0 then
payload = 'Keine Informationen vorliegend'
end
local element = mw.html.create('')
element:wikitext('<h2>' .. section .. '</h2>')
:newline()
:wikitext(payload)
:newline()
section_htmls[sections2params[section]] = element
end
section_htmls.abilities:node(coreData.section_disciplines)
--[===[
local testing = mw.html.create('')
testing:wikitext('<h3>possesses_ability</h3>')
:tag('pre')
:wikitext((coreData.possesses_ability and ClassPerson.myTableTools.printTable(coreData.possesses_ability) or 'NIL'))
:done()
:wikitext('<h3>capabilies</h3>')
:tag('pre')
:wikitext((coreData.capabilies and ClassPerson.myTableTools.printTable(coreData.capabilies) or 'NIL'))
:done()
:wikitext('<h3>capabilies_data</h3>')
:tag('pre')
:wikitext((coreData.capabilies_data and ClassPerson.myTableTools.printTable(coreData.capabilies_data) or 'NIL'))
:done()
:wikitext('<h3>coreData</h3>')
:tag('pre')
:wikitext((coreData and ClassPerson.myTableTools.printTable(coreData) or 'NIL'))
:done()
--self:addOutput(testing)
--]===]
self:addOutput(section_htmls.introtext)
self:addOutput(section_htmls.background)
self:addOutput(section_htmls.history)
self:addOutput(section_htmls.mentions)
self:addOutput(section_htmls.relations)
self:addOutput(section_htmls.abilities)
self:addOutput(section_htmls.agenda)
self:addOutput(section_htmls.comments)
-- adding the navbox
local navbox = require('Module:Navbox person')._navbox
self:addOutput(navbox({clan=coreData.clan, coterie=true}))
if coreData.clan then
self:addCategory(coreData.clan)
end
return true
end
return false
end
function ClassPerson:myArgumentProcessing(coreData)
_debug(self, 1, 'entering ClassPerson:myArgumentProcessing(args) to process coreData, from ' .. tostring(self))
-- function that performs some individual transformation args --&gt; coreData
-- remember: you can add warnings to your output with self:addWarning(warning). the page, however, will not be put in any gardening category. for that, use self:addError()
-- hint: for conversion bool values, this is useful: FoundationClass.myYesno
local coreData = coreData
local thatsMe = self:getUid()
if not coreData.displayname then
coreData.displayname = thatsMe
end
coreData.displaytitle = coreData.displayname
if not coreData.type then
coreData.type = 'Vampir'
end
if not coreData.image then
coreData.image = 'Bild:NoCharPic.png'
self:addCategory('Personen ohne Portrait')
else
if mw.ustring.find(coreData.image, ':') then
coreData.image = mw.ustring.match(coreData.image, '^.*:([^:]+)$')
end
coreData.image = 'Bild:' .. coreData.image
end
if not coreData.coterie then
coreData.coterie = false
end
if coreData.heaven == 'unbekannt' then
coreData.heaven = nil
end
-- the following antitribu calculate should be done dynamically later (once, clans are in the system)
coreData.antitribu = 'Nein'
if coreData.sect and coreData.clan and coreData.sect ~= 'Anarchen' then
local sects = {
Assamiten = 'Unabhängig',
Brujah = 'Camarilla',
Caitiff = 'Camarilla',
Gangrel = 'Unabhängig',
Giovanni = 'Unabhängig',
Kappadozianer = 'Unabhängig',
Kyasid = 'Sabbat',
Lasombra = 'Sabbat',
Malkavianer = 'Camarilla',
Nosferatu = 'Camarilla',
Pander = 'Sabbat',
Ravnos = 'Unabhängig',
Salubri = 'Sabbat',
Toreador = 'Camarilla',
Tremere = 'Camarilla',
Tzimisce = 'Sabbat',
Ventrue = 'Camarilla',
}
sects['Harbinger of Skulls'] = 'Sabbat'
sects['Jünger des Set'] = 'Unabhängig'
sects['Töchter der Kakophonie'] = 'Camarilla'
if sects[coreData.clan] ~= coreData.sect
and coreData.clan ~= 'Caitiff'
and coreData.clan ~= 'Dünnblütige'
then
coreData.antitribu = 'Ja'
end
end
-- get all offsprings (children, ghuls) for the person
_debug(self, 2, 'ClassPerson:myArgumentProcessing(): get all offsprings (children, ghuls) for the person')
local children = {}
local ghuls = {}
local query = {
select = { '[[is_member_of_class::Person]]', '[[was_sired_by::' .. self:getUid() .. ']]' },
fields = { 'is_of_character_type=type', 'is_member_of_the_coterie=coterie', 'is_member_of_clan=clan' }
}
local attributes = {
sort = 'has display title',
order = 'asc',
}
local result = ClassPerson.mySmwUtil.ask(query, attributes)
if result then
for _, data in pairs(result) do
if data.sire == thatsMe then
if data.type == 'Vampir' then
table.insert(children, data.PageName)
elseif data.type == 'Ghul' then
table.insert(ghuls, data.PageName)
end
end
end
end
if #children == 0 then
children = nil
end
if #ghuls == 0 then
ghuls = nil
end
coreData.children = children
coreData.ghuls = ghuls
-- now get the characters story
_debug(self, 2, 'ClassPerson:myArgumentProcessing(): now get the characters story')
local query = {
select = { '[[is_member_of_class::Chapter]]', '[[has cast::' .. thatsMe .. ']]' },
fields = { 'Took_place_on=begin', 'Took_place_until=end', 'Took_place_in#=place', 'Is_titled=title', 'Has_short_description=description' }
}
local attributes = {
sort='has_chapter_number,has_subchapter_number',
order = 'asc,asc',
}
coreData.history = ClassPerson.mySmwUtil.ask(query, attributes)
-- get all mentions in texts
local query = {
select = { '[[is_member_of_class::Text]]', '[[concerns::' .. thatsMe .. ']]' },
fields = { 'has source#=source', 'Has_short_description=description' }
}
local attributes = {
sort='has_display_title',
order = 'asc',
}
coreData.mentions = ClassPerson.mySmwUtil.ask(query, attributes)
-- and all the information available about this person
local query = {
select = { '[[is_member_of_class::Info]]', '[[concerns::' .. thatsMe .. ']]' },
fields = { 'has_source#=source', 'holds_information=payload', 'is_about=type', 'is_associated_to_page#=page' }
}
local result = ClassPerson.mySmwUtil.ask(query, {})
local information = {}
if result and #result > 0 then
for _, data in pairs(result) do
if not information[data.type] then
information[data.type] = {}
end
table.insert(information[data.type], data)
end
end
coreData.information = information
-- lets see, if the character has any abilities entered
_debug(self, 2, 'ClassPerson:myArgumentProcessing(): abilities')
local possesses_ability
local ib_disciplines
local section_disciplines = mw.html.create('')
if coreData.disciplines and #coreData.disciplines > 0 then
-- so the disciplines parameter is filled. we work with that
possesses_ability = {}
ib_disciplines = {}
local getArgs = require('Module:Arguments').getArgs
local frame = mw.getCurrentFrame()
local args = getArgs(frame)
table.sort(coreData.disciplines)
for _, discipline in pairs(coreData.disciplines) do
local ib_discipline = '[[' .. discipline .. ']]'
local headline = discipline
local rank = 0
local html = mw.html.create('')
local ib_paths
if discipline == 'Thaumaturgie' or discipline == 'Nekromantie' then
local disciplineArg = _disciplineParamName(self, discipline)
if coreData[disciplineArg] and #coreData[disciplineArg] > 0 then
path_html = mw.html.create('')
ib_paths = {}
table.sort(coreData[disciplineArg])
for _, _path in pairs(coreData[disciplineArg]) do
local ib_path = '[[' .. _path .. ']]'
local pathRank, abilities, pathHtml = _getAbilitiesForDiscipline(self, _path, args)
if pathRank and pathRank > 0 then
ib_path = ib_path .. ' (' .. pathRank ..')'
html:wikitext('<h4>' .. _path .. ' (' .. pathRank .. ')</h4>')
:newline()
if pathRank > rank then
rank = pathRank
end
else
html:wikitext('<h4>' .. _path .. '</h4>')
:newline()
end
table.insert(ib_paths, ib_path)
if abilities and #abilities > 0 then
for _, ability in pairs(abilities) do
table.insert(possesses_ability, ability)
end
end
html:node(pathHtml)
end
else
html:wikitext('Keine Pfade hinterlegt.')
:newline()
:tag('small')
:wikitext('Um Pfade zu hinterlegen, bitte die Seite per Formular bearbeiten und auf dem Reiter \'\'Fähigkeiten\'\' im Feld \'\''
.. discipline .. '\'\' bei einem oder mehreren Pfaden Fähigkeiten aktivieren!' )
:done()
end
else
local maxRank, abilities, aHtml = _getAbilitiesForDiscipline(self, discipline, args)
rank = maxRank
if abilities and #abilities > 0 then
for _, ability in pairs(abilities) do
table.insert(possesses_ability, ability)
end
end
if aHtml then
html:node(aHtml)
end
end
if rank and rank ~= 0 then
ib_discipline = ib_discipline .. ' (' .. rank .. ')'
headline = headline .. ' (' .. rank .. ')'
end
if ib_paths and #ib_paths > 0 then
ib_discipline = ib_discipline .. ' [' .. mw.text.listToText(ib_paths, ', ', ' und ') .. ']'
end
table.insert(ib_disciplines, ib_discipline)
section_disciplines:wikitext('<h3>' .. headline .. '</h3>')
:newline()
:node(html)
end
end
coreData.possesses_ability = possesses_ability
coreData.ib_disciplines = ib_disciplines
coreData.section_disciplines = tostring(section_disciplines)
--coreData.section_disciplines = 'LENGTH OF section_disciplines: ' .. #tostring(section_disciplines)
-- and finally some bool adjusts
coreData.antitribu = FoundationClass.myYesno(coreData.antitribu) and 'Ja' or 'Nein'
coreData.coterie = FoundationClass.myYesno(coreData.coterie) and 'Ja' or 'Nein'
coreData.died = FoundationClass.myYesno(coreData.died) and 'Ja' or 'Nein'
coreData.embraced_is_estimate = FoundationClass.myYesno(coreData.embraced_is_estimate) and 'Ja' or 'Nein'
return coreData -- this is your new coreData.
end
function ClassPerson:myDataAdjustments(data)
_debug(self, 1, 'entering ClassPerson:myDataAdjustments(data) to convert data from data store into data suitable for argument processing, from ' .. tostring(self))
-- function that performs some individual transformation datastore data into argument data
-- keep in mind, when using smw data store, that data is indexed by parameter names, not properties
-- hint: for conversion bool values, this is useful: FoundationClass.myYesno
local data = data
data.coterie = FoundationClass.myYesno(data.coterie) and 'Ja' or 'Nein'
data.died = FoundationClass.myYesno(data.died) and 'Ja' or 'Nein'
return data -- this is your new data table, being passed on to initFromArgs and subsequently to plausibility testing
end
function ClassPerson:myPlausibilityTest(args)
_debug(self, 1, 'entering ClassPerson:myPlausibilityTest(args) to test arguments, from ' .. tostring(self))
-- function that performs the individual plausibility tests
-- note: before you access a field args.fieldname you should check for existance
-- use self:addError(text); this also puts the page in its class's gardening category
return false -- return value will be ignored. but if you add any error, the object's initialization will fail with the error
end
function ClassPerson:myStashAdjustments(stash, storeType)
_debug(self, 1, 'entering ClassPerson:myStashAdjustments(stash) to do some minor adjustments on data before storing, from ' .. tostring(self))
-- function that alters the stash before storing the data. if necessary, you can complate skip storing this stash, if you return false or the empty table {}
-- storeType is the actual method of storage for this call. either 'cargo', or 'smw'
-- hint: for conversion bool values, this is useful: FoundationClass.myYesno
local stash = stash
stash.antitribu = FoundationClass.myYesno(stash.antitribu)
stash.coterie = FoundationClass.myYesno(stash.coterie)
stash.embraced_is_estimate = FoundationClass.myYesno(stash.embraced_is_estimate)
stash.died = FoundationClass.myYesno(stash.died)
return stash -- this is your new stash. this will be stored. it has format (fieldname: value)
end
function ClassPerson:method()
_debug(self, 1, 'entering ClassPerson:method() to do something, from ' .. tostring(self))
return true
end
return ClassPerson