Module:HF/Infobox/Jutsu

local Infobox = {}

-- Libraries and Global functions --

-- "High Frequency" functions local HF = require('Module:HF') -- Parses invocation and template parameters, trims whitespace, and removes blanks. local getArgs = require('Dev:Arguments').getArgs -- Generates lists local L = require('Dev:List') -- Language functions local language = mw.language.new('en')

-- Helper functions (local to not have to worry about namespaces) local arraymap = require('Module:HF/Infobox').arraymap local arrayTable = require('Module:HF/Infobox').arrayTable local base = require('Module:HF/Infobox').base local extra1 = require('Module:HF/Infobox').extra1

-- The page title of whatever page is calling the function local pageTitle = mw.title.getCurrentTitle.text

-- Convenient constants local stripLinkToTarget = '^%[*([^%[|]*)|?' local stripPageTitleToBase = "[^(]*" local basepattern = '^[^~]*' local extra1pattern = '^[^~]*~([^~]*)'

-- Local functions (used only in this Module) --

-- Replaces local function nameCheck ( target ) local nq = mw.smw.ask{ HF.Link(target:match(stripLinkToTarget)), '?Maintenance' } if type(nq) == 'table' and nq[1]['Maintenance'] == 'Name' then return true else return nil end end

-- -- Public functions (called from a Template or article) -- -- -- Creates the infobox main title function Infobox.titleJutsu(frame) local args = getArgs(frame) local out = {} if mw.title.getCurrentTitle.isContentPage == true then table.insert( out, HF.Category('Jutsu') ) local _editFormURL = mw.html.create('span') :css('float','right'):css('font-size','x-small') :wikitext( HF.Link('Special:FormEdit/Jutsu/' .. pageTitle, 'edit') ):allDone local editFormURL = tostring(_editFormURL) if args['english'] then mw.smw.set { ['English name'] = args['english'], ['Names'] = args['english'] }		end if args['kanji'] then mw.smw.set { ['Kanji name'] = args['kanji'], ['Names'] = args['kanji'] }		else mw.smw.set { ['Maintenance'] = 'Kanji' } end if args['romaji'] then mw.smw.set{ ['Romaji_name'] = args['romaji']:match(stripLinkToTarget), ['Names'] = args['romaji'] }		end if args['teams'] then local teams = mw.text.split( args['teams'], ',%s*' ) for _, v in ipairs(teams) do				mw.smw.set{ ['Team'] = mw.text.trim(v) } end end if args['image'] then local images = mw.text.split( args['image'], '\n') for _, image in ipairs(images) do				if type(image) == 'string' then mw.smw.set{ ['Picture'] = 'File:' .. image:match("[^:;]*") } end end else mw.smw.set{ ['Maintenance'] = 'Missing image' } end if args['unnamed jutsu'] == 'Yes' then mw.smw.set{ ['Maintenance'] = 'Name' } table.insert( out, ("%s"):format( pageTitle:match("[^(]*") ) )		else				table.insert( out, pageTitle:match("[^(]*") ) end local popup = frame:newParserValue(			" " ..			" "		) return table.concat( out ) .. popup:expand .. ( args['ref'] or '' ) .. editFormURL elseif mw.title.getCurrentTitle.namespace == 10 and not pageTitle:match('/testcases') then return nil else if args['unnamed jutsu'] == 'Yes' then table.insert( out, ("%s"):format( args['english'] or pageTitle:match("[^(]*") ) )		else			table.insert( out, args['english'] or pageTitle:match("[^(]*") ) end return table.concat( out ) .. ( args['ref'] or '' ) end end

function Infobox.jutsuClassification(frame) local args = getArgs(frame) local classifications = type(args['jutsu classification']) == 'string' and mw.text.split( args['jutsu classification'], ',%s*' ) if type(classifications) == 'table' then local out = {} local icons = {} local kekkei = { ['kekkei mōra'] = true, ['kekkei tōta'] = true, ['kekkei genkai'] = true }		for _,classification in ipairs(classifications) do			if classification:match(extra1pattern) then if classification:match(basepattern):lower == 'hiden' then local options = { ['SemanticPropertyName'] = 'Clan', ['PrependText'] = 'Icon Type=Ninja clan', ['PrependTemplate'] = 'Infobox_icon', ['Print'] = 'none', ['Link'] = 'default' }					local clans = arrayTable( classification:match('^[^~]*~(.*)'), '~', options, frame ) table.insert( icons, table.concat( clans ) ) elseif kekkei[classification:match(basepattern):lower] then local options = { ['SemanticPropertyName'] = 'Kekkei Genkai', ['PrependText'] = 'Icon Type=Kekkei Genkai', ['PrependTemplate'] = 'Infobox_icon', ['Print'] = 'none', ['Link'] = 'default' }					local clans = arrayTable( classification:match('^[^~]*~(.*)'), '~', options, frame ) table.insert( icons, table.concat( clans ) ) end end if classification:match(basepattern) and #classification > 1 then mw.smw.set { ['Jutsu classification'] = classification:match(basepattern) } table.insert( out, HF.Link(classification:match(basepattern)) ) end end return table.concat( icons ) .. table.concat( out, ', ' ) else return nil end end

function Infobox.jutsuType(frame) local args = getArgs(frame) local options = { ['SemanticPropertyName'] = 'Chakra Nature', ['PrependText'] = 'Nature', ['PrependTemplate'] = 'Infobox_icon', ['Link'] = 'default' }	local values = arrayTable ( args['jutsu type'], ',%s*', options, frame ) return L.makeList( 'unbulleted', values ) end

function Infobox.jutsuRank(frame) local args = getArgs(frame) local array = mw.text.split( args['jutsu rank'], ',' ) local out = {} for _, v in ipairs( array ) do		table.insert( out, HF.Link('Jutsu rank::'..v, v..'-rank') ) end return table.concat( out, ',' ) end

function Infobox.jutsuClass(frame) local args = getArgs(frame) local options = { ['SemanticPropertyName'] = 'Jutsu class type', ['Link'] = 'none' }	local classes = arrayTable ( args['jutsu class type'], ',%s*', options, frame ) return table.concat( classes, ', ' ) end

function Infobox.jutsuRange(frame) local args = getArgs(frame) local ranges = { ['Short, Mid, Long'] = 'All ranges', ['Short, Mid'] = 'Short to Mid range', ['Mid, Long'] = 'Mid to Long range', ['Short, Long'] = 'Short or Long range' }	arrayTable ( args['jutsu range'], ',%s*', { ['SemanticPropertyName'] = 'Jutsu range' } ) return ranges[args['jutsu range']] or args['jutsu range']..'-range' end

function Infobox.jutsuParent(frame) local args = getArgs(frame) local options = { ['SemanticPropertyName'] = 'Parent', ['Link'] = 'Unnamed', ['UnnamedFormat'] = true }	local parents = arrayTable ( args['parent jutsu'], ',%s*', options ) return L.makeList( 'unbulleted', parents ) end

function Infobox.jutsuMedia(frame) local args = getArgs(frame) local out = {} local mtypes = { ['Movie'] = 'Jutsu/NonCanon', ['Game'] = 'Jutsu/NonCanon', ['Game, Movie'] = 'Jutsu/NonCanon' }	local mq = mw.smw.ask { (HF.Link('Concept:%s')):format( mtypes[args['jutsu media']] or 'Jutsu/Canon' ), (HF.Link('Parent::%s')):format( mw.title.getCurrentTitle.prefixedText ), '?Appears in', '?Maintenance', ('userparam=%s'):format(args['jutsu media']), 'mainlabel=main', 'limit=200' }	if type(mq) == 'table' then for _, parent in ipairs(mq) do			local mainlink = parent['Maintenance'] == 'Name' and ("%s"):format(					HF.Link( parent['main']:match(stripLinkToTarget), parent['main']:match('%[%[:?([^|]*)|?'):match(stripPageTitleToBase) )				)				or HF.Link(					parent['main']:match(stripLinkToTarget),					parent['main']:match('%[%[:?([^|]*)|?'):match(stripPageTitleToBase)				) local dq = mw.smw.ask { (HF.Link('Concept:%s')):format( mtypes[args['jutsu media']] or 'Jutsu/Canon' ), (HF.Link('Parent::%s')):format( parent['main']:match(stripLinkToTarget) ), ('userparam=%s'):format( args['jutsu media'] or 'Anime, Manga' ), 'mainlabel=main', 'named args=yes', 'limit=20' }			local derivatives = {} if type( dq ) == 'table' then for _, derived in ipairs(dq) do					local dlink = derived['Maintenance'] == 'Name' and ("%s"):format(						HF.Link( derived['main']:match(stripLinkToTarget), derived['main']:match('%[%[:?([^|]*)|?'):match(stripPageTitleToBase) )					)					or HF.Link(						derived['main']:match(stripLinkToTarget),						derived['main']:match('%[%[:?([^|]*)|?'):match(stripPageTitleToBase)					) table.insert( derivatives, dlink ) end table.insert( out, mainlink .. L.makeList( 'bulleted', derivatives ) ) else table.insert( out, mainlink ) end end return L.makeList( 'bulleted', out ) end end

function Infobox.jutsuRelated(frame) local args = getArgs(frame) return arraymap( args['related jutsu'], ',%s*', HF.Link('%s'), ', ' ) end

function Infobox.jutsuUsers(frame) local args = getArgs(frame) local out = {} local mtypes = { anime = true, manga = true, novel = true, game = true, movie = true, ['movie canon'] = true }	local users = mw.text.split( args['users'], ',%s*' ) for _,user in ipairs( users ) do		local userX = mw.text.split( user, '~') local link = nameCheck( base( user ) ) == true and ("%s"):format(				HF.Link( base( user ):match(stripLinkToTarget), base( user ):match(stripLinkToTarget):match(stripPageTitleToBase) )			)			or HF.Link(				base( user ):match(stripLinkToTarget),				base( user ):match(stripLinkToTarget):match(stripPageTitleToBase)			) local AdditionalInfo = ( userX[3] and userX[3] == 'puppet' ) and (' (Puppetry using %s)'):format( table.concat( userX, " and ", 4 ) ) or ( userX[3] and userX[3] == 'with' ) and (' (with %s)'):format(userX[4]) or '' local Media = ( userX[2] and mtypes[userX[2]:lower] and mtypes[userX[2]:lower] ~= 'movie canon' ) and ('(%s only)'):format( language:ucfirst( userX[2] ) ) or ( userX[2] and mtypes[userX[2]:lower] and mtypes[userX[2]:lower] == 'movie canon' ) and '(Movie only)' or '' local cq = mw.smw.ask { (HF.Link('Contract::%s')):format( user:match(stripLinkToTarget) ), 'mainlabel=main' }		local sl = {} if type(cq) == 'table' then for _,v in ipairs( cq ) do				table.insert( sl, v['main'] ) end end local Summons = ((#sl > 0)			and ( pageTitle == 'Summoning Technique' or pageTitle == 'Destruction Bug Host Technique' )) and ( ' (%s)' ):format( table.concat( sl, ", " ) ) or '' local setmtype = ( extra1( user ) and mtypes[ extra1( user ):lower ] ) and language:ucfirst( extra1( user ):lower ) or 'null' mw.smw.set { ['User tech'] = base( user ) .. ';' .. setmtype }		table.insert( out, link .. AdditionalInfo .. Summons .. Media ) end return L.makeList( 'bulleted', out ) end - -- Exported functions (used in this and other Modules) -- - -- None. - -- Output (send it back to whatever called it) -- - return Infobox