Eho kuatia retepýpe

Módulo:Ficha de videojuego

Vikipetãmegua

La documentación para este módulo puede ser creada en Módulo:Ficha de videojuego/doc

local p = {}

-- Cargar módulos
local ModuloWikidata			= require('Módulo:Wikidata')
local ModuloFormatos			= require('Módulo:Wikidata/Formatos')
local ModuloPaginas				= require('Módulo:Páginas')
local ModuloArgs    			= require('Módulo:Argumentos')

-- :: Definir funciones desde módulos
local elementoTabla				= require('Módulo:Tablas').elemento
local formatoNumero				= ModuloFormatos.formatoNumero2
local numeroUnidad				= ModuloFormatos.formatoUnidad2
local obtenerEtiquetaWikidata	= ModuloWikidata.obtenerEtiquetaWikidata
local argumentos				= ModuloArgs.obtenerValorDeArgumentos

-- :: Definir variables globales
local Entidad, InstanciaDeID

-- :: Estilos por defecto
local EstiloEtiqueta	= 'width:30%;background-color:#EEF'
local EstiloDatos		= 'width:70%;'
local EstiloTitulo		= 'font-weight:bold; background-color:#CCF'

function p.Ficha(frame)
	-- :: Inicializador
	ModuloWikidata:setFrame(frame)
	ModuloArgs.obtenerTablaDeArgumentos(frame)
	Entidad		= mw.wikibase.getEntity(argumentos{'entidad', 'id'}) or {id = ''}
	local InstanciaDe	= elementoTabla(Entidad, 'claims', 'P31', 1)
	if InstanciaDe then InstanciaDeID = elementoTabla(InstanciaDe, 'mainsnak', 'datavalue', 'value', 'id') end
	
	-- :: Cabecera
	local Titulo		= argumentos{'título', 'nombre'} or obtenerEtiquetaWikidata(Entidad) or ModuloPaginas.nombrePagina({desambiguar='sí'})
	local TituloOrig	= argumentos{'título original', 'título_original', {propiedad, 'P1476'}}
	local Eslogan		= argumentos{'eslogan', {propiedad, 'P6291'}}

	local Logo			= argumentos{'logo', {ModuloWikidata.obtenerImagenWikidata, Entidad, 'P154'}}

	local Captura		= argumentos{'imagen', 'captura'}
	local Pie
	if not Captura == '' then
		Pie				= argumentos{'pie'}
	else
		Captura, Pie	= ModuloWikidata.obtenerImagenWikidata(Entidad, 'P18')
	end

	-- General
	local Genero		= argumentos{'género', 'genero', {propiedad, 'P136'}}
	local GeneroInic	= argumentos{'género inicial', 'género_inicial'}
	local Idiomas		= argumentos{'idioma', 'idiomas', {propiedad, 'P407'}}
	local Fabricante	= argumentos{'fabricante', {propiedad, 'P176'}}
	
	local Desarrollador	= argumentos{'desarrollador', 'desarrolladora', {propiedad, 'P178'}}
	local Distribuidor	= argumentos{'distribuidor', 'distribuidora', {propiedad, 'P123'}}
	local Editorial		= argumentos{'editorial', {propiedad, 'P750'}}
	local Creador		= argumentos{'creador', {propiedad, 'P50'}}
	local Disenador		= argumentos{'diseñador', {propiedad, 'P287'}}
	local Director		= argumentos{'director', {propiedad, 'P57'}}
	local Productor		= argumentos{'productor', {propiedad, 'P162'}}
	local DirectorSon	= argumentos{'director sonido', 'director_sonido', {propiedad, 'Q986888'}}
	local Programador	= argumentos{'programador', {propiedad, 'P943'}}
	local Artista		= argumentos{'artista'}
	local Escritor		= argumentos{'escritor', {propiedad, 'P58'}}
	local Compositor	= argumentos{'compositor', {propiedad, 'P86'}}
	local Modos			= argumentos{'modo', 'modos', {propiedad, 'P404'}}

	-- Software
	local Motor			= argumentos{'motor', {propiedad, 'P408'}}
	local Version		= argumentos{'versión', 'version', {propiedad, 'P348', {['calificador'] = 'P577', ['uno'] = 'último', ['ordenar'] = 'por fecha'}}}
	local VersionDesa	= (function()
		local Version		= argumentos{'versión desarrollo', 'versión_desarrollo'}
		local VersionFecha	= argumentos{'versión desarrollo', 'versión_desarrollo_fecha'}
		if Version and VersionFecha then return Version .. '<small>(' .. VersionFecha .. ')</small>' end
		return Version
	end)()
	local Plataformas	= argumentos{'plataforma', 'plataformas', 'sistema arcade', 'sistema_arcade', {propiedad, 'P400'}}
	local PlatafInic	= argumentos{'plataforma inicial'}
	local Requisitos	= argumentos{'requisitos'}
	local Licencias		= argumentos{'licencia', 'licencias', {propiedad, 'P275'}}
	
	-- :: Hardware
	local Formato		= argumentos{'formato', {propiedad, 'P437'}}
	local Mueble		= argumentos{'mueble'}
	local Hardware		= argumentos{'hardware'}
	local CPU			= argumentos{'cpu', {propiedad, 'P880'}}
	local GPU			= argumentos{'gpu', {propiedad, 'P2560'}, {propiedad, 'P6948'}}
	local Audio			= argumentos{'audio', {propiedad, 'P7501'}}
	local Pantalla		= argumentos{'pantalla', {propiedad, 'P5307'}}
	local PantallaHardware, PantallaPinball
	if InstanciaDeID == 'Q653928' then
		PantallaPinball = Pantalla
	else
		PantallaHardware = Pantalla
	end
	local Entrada		= argumentos{'entradas', {propiedad, 'P479'}}
	
	-- :: Mesa de pinball
	local Tecnologia= argumentos{'tecnologia'}
	local Lanzador	= argumentos{'lanzador'}
	local Flippers	= argumentos{'flippers'}
	local Anchura	= argumentos{'anchura'}
	local Rampas	= argumentos{'rampas'}
	local Bucles	= argumentos{'bucles'}
	local Dianas	= argumentos{'dianas'}
	local DianasAbat= argumentos{'dianas abatibles', 'dianas_abatibles'}
	local Bumpers	= argumentos{'bumpers'}
	local Accesorios= argumentos{'accesorios'}

	-- :: Desarrollo
	local Lanzamiento	= argumentos{'lanzamiento'} or frame:preprocess('{{Lanzamientovj|id='..Entidad.id..'}}')
	local ZonaPruebas	= argumentos{'location test'}
	local Estado		= argumentos{'estado actual'}
	local MotivoEstado	= argumentos{'motivo estado'}

	local Serie			= argumentos{'serie', {propiedad, 'P179'}}
	local Anterior		= argumentos{'anterior', {propiedad, 'P155'}}
	local Posterior		= argumentos{'posterior', {propiedad, 'P156'}}
	
	local Derivadas		= argumentos{'derivada', {propiedad, 'P4969'}}
	local Expansiones	= argumentos{'expansión', 'contenido descargable', 'dlc'}
	
	local Clasificaciones = (function()
		if string.len(argumentos{'clasificación', 'clasificacion'} or '') < 0 then return argumentos{'clasificación', 'clasificacion'} end
		if string.len(frame:preprocess('{{Clasificaciónvj|id='..Entidad.id..'}}')) < 1 then return frame:preprocess('{{Clasificaciónvj|id='..Entidad.id..'}}') end
	end)()
	local SitiosWeb		= obtenerEnlaces()
	
	local TablaFicha = {
		titulo  			= Titulo,
		subtitulo			= Eslogan,
		tipocabecera		= 'videojuego',
		clasetitulo			= ClaseTitulo,
		estilotitulo		= EstiloTitulo,
		estiloseccion		= EstiloTitulo,
		estiloetiqueta		= EstiloEtiqueta,
		estilodatos			= EstiloDatos,
		imagen				= Logo,
		['tamañoimagen']	= '250x250px',
		imagen2				= Captura,
		['tamañoimagen2']	= '250x250px',
		pie2				= Pie,
		estilopie			= 'font-size:88%',
		{tipo='sección',
			titulo = 'Información general',
			{'Creador', Creador},
			{'Fabricante', Fabricante},
			
			{'Desarrollador', Desarrollador},
			{'Distribuidor', (Distribuidor or Editorial)},
			{'Diseñador', Disenador},
			{'Director', Director},
			{'Productor', Productor},
			{'Director de sonido', DirectorSon},
			{'Programador', Programador},
			{'Artista', Artista},
			{'Escritor', Escritor},
			{'Compositor', Compositor},
		},
		{tipo='sección',
			titulo = 'Datos del juego',
			{'Género', Genero},
			{'Género Inicial', GeneroInic},
			{'Idiomas', Idiomas},
			{'Obras derivadas', Derivadas},
			{'Modos de juego', Modos},
			{'Clasificaciones', Clasificaciones},
		},
		{tipo='sección',
			titulo = 'Datos del software',
			{'Motor', Motor},
			{'Versión actual', Version},
			{'Version en desarrollo', VersionDesa},
			{'Plataformas', Plataformas},
			{'Plataforma inicial', PlatafInic},
			Requisitos,
			{'Licencias', Licencias},
		},
		{tipo='sección',
				titulo = 'Datos del la mesa',
				{'Tecnología', Tecnologia},
				{'Tipo de lanzador', Lanzador},
				{'Tipo de pantalla', PantallaPinball},
				{'Anchura', Anchura},
				{"''Flippers''", Flippers},
				{'Rampas', Rampas},
				{'Bucles', Bucles},
				{'Dianas', Dianas},
				{'Bumpers', Bumpers},
				{'Accesorios', Accesorios},
		},
		{tipo='sección',
			titulo = 'Datos del hardware',
			{'Formato', Formato},
			{'Mueble', Mueble},
			{'Hardware', Hardware},
			{'CPU', CPU},
			{'Video', GPU},
			{'Pantalla', PantallaHardware},
			{'Audio', Audio},
			{'Dispositivos de entrada', Entrada},
		},
		{tipo='sección',
			titulo = 'Desarrollo',
			{'Lanzamiento', Lanzamiento},
			{'Zona de pruebas', ZonaPruebas},
			{'Estado de desarrollo', Estado},
			{'Expansiones', Expansiones},
		},
		{tipo='sección',
			titulo = Serie,
			{tipo='sucesión',
				anterior = Anterior,
				actual = Titulo,
				siguiente = Posterior,
			},
		},
		{tipo='sección',
			titulo = 'Enlaces',
			--estilodatos	= 'text-align:left',
			{'', SitiosWeb}
		},
	}
	
	return require('Módulo:Ficha').infobox(TablaFicha)
end

-- :: Función para obtener y formatear enlaces externos
function obtenerEnlaces()
	local SitiosWeb = {}
	
	local SitioWeb	= argumentos{'sitio_web', 'sitio web', 'web', {propiedad, 'P856',{['enlace']='no', uno='sí'}}}
	local Blog		= argumentos{'blog_oficial', {propiedad, 'P1581',{['enlace']='no', uno='sí'}}}
	local Repo		= argumentos{'repositorio', {propiedad, 'P1324', {['enlace']='no', uno='sí'}}}
	local SegErrores= argumentos{'seguimiento_de_errores', {propiedad, 'P1401', {['enlace']='no', uno='sí'}}}

	if SitioWeb then table.insert(SitiosWeb, generarEnlace(SitioWeb, 'Sitio web oficial')) end
	if Blog then table.insert(SitiosWeb, generarEnlace(Blog, 'Blog')) end
	if Repo then table.insert(SitiosWeb, generarEnlace(Repo, 'Repositorio de código')) end
	if SegErrores then table.insert(SitiosWeb, generarEnlace(SegErrores, 'Seguimiento de errores')) end

	return table.concat(SitiosWeb, '\n')
end

function generarEnlace(enlace, texto)
	local enlazar = require('Módulo:URL').enlazar
	enlace = enlace:match('.+:?//(.+) .+$') or enlace
	enlace = enlazar(enlace, texto) or ''
	enlace = enlace and '<div>'..enlace..'</div>\n'
	return enlace
end


-- Función, propiedad() personalizada
function propiedad(idPropiedad, opciones, entidad)
	if not entidad then entidad = Entidad end

	if entidad and entidad.claims and entidad.claims[idPropiedad] then
		if not opciones then
			opciones = {['linkback']='sí'}
		end
		
		opciones['idioma'] = 'es'

		local ValorPosicional = 1
		if type(opciones['valor_posicional']) == 'number' then ValorPosicional = opciones['valor_posicional'] end
		
		local ValorPosicionalCalif = 1
		if type(opciones['valor_posicional_calif']) == 'number' then ValorPosicional = opciones['valor_posicional_calif'] end

		local Calificador = opciones['calificador']

		local Obj = (function()
			local Obj = (function()
				local Obj = elementoTabla(entidad, 'claims', idPropiedad)
				if type(ValorPosicional) == 'number' then return elementoTabla(Obj, ValorPosicional) end
				if ValorPosicional == 'último' then return elementoTabla(Obj, #Obj) end
			end)()

			if Calificador then
				Obj = (function()
					local Obj = elementoTabla(Obj, 'qualifiers', Calificador)
					if type(ValorPosicionalCalif) == 'number' then return elementoTabla(Obj, ValorPosicionalCalif) end
					if ValorPosicionalCalif == 'último' then return elementoTabla(Obj, #Obj) end
				end)()
			end
			return elementoTabla(Obj, 'mainsnak')
		end)()

		Tipo	= elementoTabla(Obj, 'datavalue', 'type')
		
		if opciones['formato'] == 'archivo' then
			if not opciones['uno'] then opciones['uno'] = 'último' end
			opciones['ordenar'] = 'por fecha'
			if Calificador then return elementoTabla(Obj, 'datavalue', 'value') end
		end

		-- Devolver el ID de la entidad, para propiedades de entidad
		if opciones['formato'] == 'entidadID' then
			return elementoTabla(Obj, 'datavalue', 'value', 'id')
		end

		if opciones['formato'] == 'cadena' then
			opciones['linkback'] = 'no'
			if Tipo == 'string' then
				return elementoTabla(Obj, 'datavalue', 'value')
			end
		end

		if opciones['formato'] == 'número' then
			if Tipo == 'quantity' then
				return formatoNumero(elementoTabla(Obj, 'datavalue', 'value', 'amount'))
			end
		end

		-- Valores cuya unidad deba ir a la derecha, separada de un espacio
		if opciones['formato'] == 'unidad' then
			if elementoTabla(entidad, 'claims', idPropiedad, 2, 'mainsnak', 'datavalue') then
				return formatoNumero(elementoTabla(entidad, 'claims', idPropiedad, 1, 'mainsnak', 'datavalue', 'value', 'amount')) .. '&nbsp;-&nbsp;' .. numeroUnidad(elementoTabla(entidad, 'claims', idPropiedad, 2, 'mainsnak', 'datavalue'), opciones)
			else
				return numeroUnidad(elementoTabla(entidad, 'claims', idPropiedad, 1, 'mainsnak', 'datavalue'), opciones)
			end
		end

		-- Invocar a la función fallback si no se cumplen las condiciones anteriores
		opciones.entityId  = entidad.id
		opciones.propiedad = idPropiedad
		return ModuloWikidata.getPropiedad(opciones, entidad.claims[idPropiedad])
	end
end

return p