モジュール:Infobox creature

提供:ARK Wiki
ナビゲーションに移動 検索に移動
Note.png
このページはこのテンプレート • モジュールは日本語に合わせて編集されています。
このページを編集する際は気を付けてください。

local p = {}

local Arguments = require('dev:Arguments')
local Arkitexure = require('Module:Arkitexure')
local ItemList = require('Module:ItemList').create
local Version = require('Module:Version')

local Class = Arkitexure.Class
local Cell = Arkitexure.Cell


-- Forward declarations
local DossierDisplay
local ReleaseInformation


DossierDisplay = Class( function(self, parent, config)
	Arkitexure.UnitRow.constructor(self, parent)

	self.addBook = config.addBook
	self.image = config.image

	local innerWikitext
	if self.addBook then
		innerWikitext = string.format('{{DossierImage|%s|298}}', self.image)
	else
		innerWikitext = string.format('[[File:%s|298x198px]]', self.image)
	end

	self:cell({ Cell.X1W100, Cell.Column })
		:text(innerWikitext)
	:done()
end, Arkitexure.UnitRow )


ReleaseInformation = Class( function(self, parent, config)
	Arkitexure.Unit.constructor(self, parent, '[[パッチノート|リリースバージョン]]')

	if (config.Steam or config.Xbox or config.PS or config.Switch or config.Epic) or not config.Mobile then
		self:row()
			:newCell(ReleaseInformation.VersionCell, ReleaseInformation.Platform.Steam, {
				size = { Cell.Left, Cell.X3W33 },
				version = config.Steam
			}):done()
			:newCell(ReleaseInformation.VersionCell, ReleaseInformation.Platform.Xbox, {
				size = { Cell.X3W33 },
				version = config.Xbox
			}):done()
			:newCell(ReleaseInformation.VersionCell, ReleaseInformation.Platform.PS, {
				size = { Cell.Right, Cell.X3W33 },
				version = config.PS
			}):done()
		:done()
		self:row()
			:newCell(ReleaseInformation.VersionCell, ReleaseInformation.Platform.Switch, {
				size = { Cell.Left, Cell.X2W50 },
				version = config.Switch
			}):done()
			:newCell(ReleaseInformation.VersionCell, ReleaseInformation.Platform.Epic, {
				size = { Cell.Right, Cell.X2W50 },
				version = config.Epic
			}):done()
		:done()
	end

	if config.Mobile then
		self:row()
			:newCell(ReleaseInformation.VersionCell, ReleaseInformation.Platform.Mobile, {
				size = { Cell.X1W100, Cell.ForceBackground },
				version = config.Mobile
			})
		:done()
	end

	self:addCategoriesFor(ReleaseInformation.Platform.Steam, config.Steam)
	self:addCategoriesFor(ReleaseInformation.Platform.Xbox, config.Xbox)
	self:addCategoriesFor(ReleaseInformation.Platform.PS, config.PS)
	self:addCategoriesFor(ReleaseInformation.Platform.Switch, config.Switch)
	self:addCategoriesFor(ReleaseInformation.Platform.Epic, config.Epic)
	self:addCategoriesFor(ReleaseInformation.Platform.Mobile, config.Mobile)
end, Arkitexure.Unit )
	ReleaseInformation.Platform = {
		Steam = {
			name = 'Steam',
			icon = 'Steam.svg',
			branch = Version.Platform.PC
		},
		Xbox = {
			name = 'Xbox',
			icon = 'Xbox One.svg',
			branch = Version.Platform.Xbox,
			linkPrefix = 'Xbox_'
		},
		PS = {
			name = 'PlayStation',
			icon = 'PS.svg',
			branch = Version.Platform.PS,
			linkPrefix = 'PS_'
		},
		Switch = {
			name = 'Switch',
			icon = 'Nintendo Switch.svg',
			branch = Version.Platform.Switch,
			linkPrefix = 'Switch_'
		},
		Epic = {
			name = 'Epic Games',
			icon = 'Epic Games.svg',
			branch = Version.Platform.PC,
			noReleaseCategories = true
		},
		Mobile = {
			name = 'Mobile',
			icon = 'Logo Mobile.svg',
			branch = Version.Platform.Mobile,
			linkPrefix = 'Mobile:'
		}
	}

	ReleaseInformation.VersionCell = Class( function(self, parent, platform, config)
		Cell.constructor(self, parent, config.size)

		if config.version == 'Unreleased' then
			config.version = nil
		end

		self.platform = platform
		self.version = config.version
	end, Arkitexure.Cell )
		function ReleaseInformation.VersionCell.methods.toString(self)
			if self.version ~= nil then
				local vIndex = Version.getVersionIndex(self.platform.branch, self.version)
				local date = '???'
				local patchLink
				if self.platform.linkPrefix then
					patchLink = string.format('[[%s%s|%s]]', self.platform.linkPrefix, self.version, self.version)
				else
					patchLink = string.format('[[%s]]', self.version)
				end
				if vIndex then
					date = mw.language.getContentLanguage():formatDate('Y年n月j日',
						Version.getReleaseDate(self.platform.branch, vIndex) )
				end

				return string.format('<div class="info-arkitex %s">[[File:%s|20px|frameless|link=]] %s<br/><small>%s</small></div>',
					table.concat( self.classes, ' ' ), self.platform.icon, patchLink, date)
			else
				return string.format('<div class="info-arkitex %s">[[File:%s|20px|frameless|link=]]<br/><small>未リリース</small></div>',
					table.concat( self.classes, ' ' ), self.platform.icon)
			end
		end

	function ReleaseInformation.methods.addCategoriesFor(self, platform, version)
		if version then
			if not platform.noReleaseCategories then
				local major = version:match('(%d+)%.')
				local vIndex = Version.getVersionIndex(platform.branch, version)

				local versionCategory = 'にリリースされた生物'
				local yearCategory = 'にリリースされた生物'

				if platform == ReleaseInformation.Platform.Mobile then
					versionCategory = 'にモバイルでリリースされた生物'
				end

				if platform == ReleaseInformation.Platform.Switch then
					versionCategory = 'にSwitchでリリースされた生物'
				end

				if platform == ReleaseInformation.Platform.Xbox then
					versionCategory = 'にXboxでリリースされた生物'
				end

				self:addCategory('v' .. major .. versionCategory)

				if vIndex then
					local year = mw.language.getContentLanguage():formatDate('Y',
						Version.getReleaseDate(platform.branch, vIndex) )
					self:addCategory(year .. yearCategory)
				end
			end
		else
			self:addCategory(platform.name .. 'では利用不可')
		end
	end


function p.buildReleaseInformation(frame)
	local args = Arguments.getArgs(frame, {
		trim = true,
		removeBlanks = true,
	})

	local wiring = Arkitexure.ServiceWiring()
	local releaseInfo = ReleaseInformation(wiring, {
		Steam = args.releaseVersionSteam,
		Xbox = args.releaseVersionXbox,
		PS = args.releaseVersionPS,
		Switch = args.releaseVersionSwitch,
		Epic = args.releaseVersionEpic,
		Mobile = args.releaseVersionMobile
	})
	return wiring:toString() .. releaseInfo:toString()
end


function p.build(frame)
	local args = Arguments.getArgs(frame, {
		trim = true,
		removeBlanks = true,
	})

	return Arkitexure.Infobox {
			withDinoHead = true,
			title = args.name
		}
		:getHeader()
			:unit()
				:row()
					:newCell(DossierDisplay, {
						addBook = args.addBook == 'yes',
						image = args.image
					} )
				:done()
				:row()
					-- TODO: sound player
				:done()
			:done()
		:done()
		:module()
			:newUnit(ReleaseInformation, {
				Steam = args.releaseVersionSteam,
				Xbox = args.releaseVersionXbox,
				PS = args.releaseVersionPS,
				Switch = args.releaseVersionSwitch,
				Epic = args.releaseVersionEpic,
				Mobile = args.releaseVersionMobile
			})
		:done()
	:done()
end

return p