Difference between revisions of "Module:Sandbox/Chao"

From BlazBlue Wiki
Jump to: navigation, search
m
m
(7 intermediate revisions by the same user not shown)
Line 12: Line 12:
 
local p = {}
 
local p = {}
 
local cargo = mw.ext.cargo
 
local cargo = mw.ext.cargo
 
frame = { character = 'Noel Vermillion '}
 
  
 
local sections = {
 
local sections = {
Line 21: Line 19:
 
source = 'BlazBlue: Calamity Trigger',
 
source = 'BlazBlue: Calamity Trigger',
 
section = 'Arcade Mode',
 
section = 'Arcade Mode',
limit = '',
+
header="plain",
widths = '',
 
header = 'h3',
 
title = 'BlazBlue: Calamity Trigger',
 
sort = '',
 
see_all = '',
 
see_cameos = '',
 
 
},{
 
},{
 
template = 'Gallery Section (Cargo)',
 
template = 'Gallery Section (Cargo)',
 
source = 'BlazBlue: Continuum Shift',
 
source = 'BlazBlue: Continuum Shift',
 
section = 'Arcade Mode',
 
section = 'Arcade Mode',
header = 'h3'
+
header="plain",
 
},{
 
},{
 
template = 'Gallery Section (Cargo)',
 
template = 'Gallery Section (Cargo)',
 
source = 'BlazBlue: Chrono Phantasma',
 
source = 'BlazBlue: Chrono Phantasma',
 
section = 'Arcade Mode',
 
section = 'Arcade Mode',
header = 'h3'
+
header="plain",
 +
}
 +
},
 +
['Story'] = {
 +
{
 +
template = 'Gallery Section (Cargo)',
 +
source = 'BlazBlue: Calamity Trigger',
 +
section = 'Story',
 +
header="plain",
 
}
 
}
 
}
 
}
Line 52: Line 52:
 
t = {}
 
t = {}
 
for k2,v2 in pairs (v) do
 
for k2,v2 in pairs (v) do
 +
 +
--fill in any missing template arguments
 
v2.character = _char
 
v2.character = _char
 +
v2.source = v2.source or ''
 +
v2.section = v2.section or ''
 +
v2.limit = v2.limit or ''
 +
v2.widths = v2.widths or ''
 +
v2.header = v2.header or ''
 +
v2.title = v2.title or ''
 +
v2.sort = v2.sort or ''
 +
v2.see_all = v2.see_all or ''
 +
v2.see_combos = v2.see_combos or ''
  
 
if v2.template == 'Gallery Section (Cargo)' then
 
if v2.template == 'Gallery Section (Cargo)' then
Line 59: Line 70:
 
if v2.count_all > 0 then
 
if v2.count_all > 0 then
 
table.insert(t, dump(v))
 
table.insert(t, dump(v))
table.insert(text, frame:expandTemplate{ v })
+
table.insert(text, frame:expandTemplate{ title = v2.template, args = v2 })
 
else
 
else
 
mw.log("count returned 0: " .. v2.count_all)
 
mw.log("count returned 0: " .. v2.count_all)
Line 66: Line 77:
 
end
 
end
 
 
templates = concatvalues(t,"")
+
--templates = concatvalues(t,"")
 +
templates = concathtml(t)
 
if not templates == "" then
 
if not templates == "" then
 
-- insert the section, prepended by its header, to the final text
 
-- insert the section, prepended by its header, to the final text
 
table.insert(text, k .. templates)
 
table.insert(text, k .. templates)
 
end
 
end
 
mw.log(dump(text))
 
return text
 
 
end
 
end
 
 
gallery = concatvalues(text,"")
+
gallery = concathtml(text)
 
mw.log(dump(gallery))
 
mw.log(dump(gallery))
 
return gallery
 
return gallery
Line 97: Line 106:
 
table.insert(where_clause_parts, "Files.Gallery_Sections = '" .. section .. "'")
 
table.insert(where_clause_parts, "Files.Gallery_Sections = '" .. section .. "'")
 
end
 
end
where_clause = concatvalues(where_clause_parts, ",")
+
where_clause = concatvalues(where_clause_parts, ", AND ")
  
 
local args = {
 
local args = {
Line 140: Line 149:
  
 
return gallery
 
return gallery
 +
end
 +
 +
-- concat values in a table as html nodes?
 +
function concathtml(s)
 +
local div = mw.html.create('div')
 +
for k,v in ipairs(s) do
 +
div:node(v)
 +
end
 +
mw.log(div)
 +
return div
 
end
 
end
  

Revision as of 01:36, 14 September 2019

Main Visuals

... further results

Character Crest

Chibi

Gameplay

Arcade

BlazBlue: Calamity Trigger

see cameos (6)

BlazBlue: Continuum Shift

see cameos (2)

BlazBlue: Chrono Phantasma

see cameos (10)

BlazBlue: Central Fiction

see all 7
see cameos (13)

Story

Portraits

... further results

Short Stories

BlazBlue: Calamity Trigger

see all 15
see cameos (5)

BlazBlue: Continuum Shift

see all 12
see cameos (4)

BlazBlue: Chrono Phantasma

see all 13

BlazBlue: Central Fiction

see all 11

BlazBlue: Cross Tag Battle

BlazBlue: Clone Phantasma

see cameos (1)

Novels

BlazBlue: Calamity Trigger - Part 1

BlazBlue: Calamity Trigger - Part 2

... further results

BlazBlue: Continuum Shift - Part 1

BlazBlue: Continuum Shift - Part 2

Manga

BlazBlue: Remix Heart

... further results

BlazBlue: Variable Heart

Radio Show

Chibi Portraits

see all 51

Blazblue Radio

see all 117

Blazblue Radio Continued

see all 151

Blazblue Radio Wide

see all 130

Blazblue Radio Hyper

see all 70

Blazblue Radio Ace

see all 57

Blazblue Radio Quick

see all 51

Blazblue Radio Dynamic

see all 42

Blazblue Radio NEO

see all 30

Blazblue Radio Repeat

see all 5

Blazblue Radio Repeat 2

see all 1

Artwork

Staff Extras

... further results

Pre-order Bonuses

... further results

Wallpapers

... further results

Stickers

... further results

Production Art

Model Sheets

... further results

Early Designs

Storyboards

... further results

Collaborations

Destiny Child

... further results

Girls' Frontline

... further results

Lord of Vermilion Re:2

... further results

Mabinogi Duel

Unlimited VS

... further results
--[[
{{#invoke:Sandbox/Chao|GallerySection|character=Noel Vermillion|section=Portraits}}
simulate passing a frame to the function in the console with:
myFrame = { args = { character='Noel Vermillion', section='Portraits' } }
=p.GallerySection ( myFrame )
=p.testExpandTemplate( myFrame )
=p.render(myFrame)

local itemData = mw.loadData('Module:ItemData')
--]]

local p = {}
local cargo = mw.ext.cargo

local sections = {
	['Arcade'] = {
		{
			template = 'Gallery Section (Cargo)',
			source = 'BlazBlue: Calamity Trigger',
			section = 'Arcade Mode',
			header="plain",
		},{
			template = 'Gallery Section (Cargo)',
			source = 'BlazBlue: Continuum Shift',
			section = 'Arcade Mode',
			header="plain",
		},{
			template = 'Gallery Section (Cargo)',
			source = 'BlazBlue: Chrono Phantasma',
			section = 'Arcade Mode',
			header="plain",
		}
	},
	['Story'] = {
		{
			template = 'Gallery Section (Cargo)',
			source = 'BlazBlue: Calamity Trigger',
			section = 'Story',
			header="plain",
		}
	}
}

function p.render(frame)
	text = {}
	_char = frame.args['character'] or ''
	
	for k,v in pairs (sections) do
		section = k

		-- v is a table of templates in this section
		t = {}
		for k2,v2 in pairs (v) do

			--fill in any missing template arguments
			v2.character = _char
			v2.source = v2.source or ''
			v2.section = v2.section or ''
			v2.limit = v2.limit or ''
			v2.widths = v2.widths or ''
			v2.header = v2.header or ''
			v2.title = v2.title or ''
			v2.sort = v2.sort or ''
			v2.see_all = v2.see_all or ''
			v2.see_combos = v2.see_combos or ''

			if v2.template == 'Gallery Section (Cargo)' then
				v2.count_all = p.countImagesCargo(v2) or 0
				
				if v2.count_all > 0 then
					table.insert(t, dump(v))
					table.insert(text, frame:expandTemplate{ title = v2.template, args = v2 })
				else
					mw.log("count returned 0: " .. v2.count_all)
				end
			end
		end
		
		--templates = concatvalues(t,"")
		templates = concathtml(t)
		if not templates == "" then
			-- insert the section, prepended by its header, to the final text
			table.insert(text, k .. templates)
		end
	end
	
	gallery = concathtml(text)
	mw.log(dump(gallery))
	return gallery
end

function p.countImagesCargo(v)
	tables = 'Files'
	fields = 'COUNT(Files._pageName)'

	character = v.character or ''
	source = v.source or ''
	section = v.section or ''

	where_clause_parts = {}
	table.insert(where_clause_parts, "Files.Characters HOLDS '" .. character .. "'")
	if not source == '' then
		table.insert(where_clause_parts, "Files.Source HOLDS '" .. source .. "'")
	end
	if not section == '' then
		table.insert(where_clause_parts, "Files.Gallery_Sections = '" .. section .. "'")
	end
	where_clause = concatvalues(where_clause_parts, ", AND ")

	local args = {
		where = where_clause
	}

	result = cargo.query( tables, fields, args )
	count = result[1][fields] or '0'

	return tonumber(count)
end

function p.testExpandTemplate(frame)
	
	text = p._testExpandTemplate(frame, 'BlazBlue: Central Fiction', '', 8, 'title', 'h3', 'y', 'y', '7')
	
	return text
end

function p._testExpandTemplate(frame, source, section, limit, title, header, see_all, see_cameo, count_all)
	_character = frame.args.character or ''
	_source = frame.args.source or source or ''
	_section = section or ''
	_limit = tonumber(limit) or 4
	_title = title or ''
	_header = header or ''
	_see_all = see_all or ''
	_see_cameo = see_cameo or ''
	_count_all = count_all or ''
	
	gallery = frame:expandTemplate{ title = 'Gallery Section (Cargo)', args = { 
		  character = _character
		    ,source = _source
		   ,section = _section
		     ,limit = _limit
		     ,title = _title
		    ,header = _header
		   ,see_all = _see_all
		 ,see_cameo = _see_cameo
		 ,count_all = _count_all
	} }

	return gallery
end

-- concat values in a table as html nodes?
function concathtml(s)
	local div = mw.html.create('div')
	for k,v in ipairs(s) do
		div:node(v)
	end
	mw.log(div)
	return div
end

-- concat all the strings in table s together with the given delimiter
function concatvalues(s,delimiter)
    local t = { }
    for k,v in ipairs(s) do
        t[#t+1] = tostring(v)
    end
    return table.concat(t,delimiter)
end

-- concat all the strings in table s together with the given delimiter
-- skips blank entries (where value v = "")
function concatvaluesonly(s,delimiter)
    local t = { }
    for k,v in ipairs(s) do
    	if not (v == '') then
    		t[#t+1] = tostring(v)
    	end
    end
    return table.concat(t,delimiter)
end

function html_escape(s)
    return (string.gsub(s, "[<>\"'/ ,]", {
        ["<"] = "%3C",
        [">"] = "%3E",
        ['"'] = "%22",
        ["'"] = "%27",
        ["/"] = "%2F",
        [" "] = "+",
        [","] = "%2C"
    }))
end

-- helpful for printing tables
function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '['..k..'] = ' .. dump(v) .. ','
      end
      return s .. '} '
   else
      return tostring(o)
   end
end

return p