Difference between revisions of "Module:OCG-TCG card"

From Yugipedia
Jump to: navigation, search
(These don't need to be section headings)
(Can't figure out why it's not working, but try to fetch the OCG and TCG debut dates. Feed them into the limitation history objects to they can properly draw the tables.)
Line 115: Line 115:
 
or self:getFirstSetDate()
 
or self:getFirstSetDate()
  
-- If the card exists in the OCG, find all limitation statuses its had in the OCG.
+
-- If the card exists in the OCG, get its OCG debut date and limitation history.
 
if (self.isOcg) then
 
if (self.isOcg) then
self.ocgLimitations = LimitationHistory:new(self.pageName, 'OCG')
+
self.ocgDebutDate = self:getFirstSetDateInGame(OCG)
 +
self.ocgLimitations = LimitationHistory:new(self.pageName, 'OCG', self.ocgDebutDate)
 
end
 
end
  
-- If the card exists in the TCG, find all limitation statuses its had in the TCG.
+
-- If the card exists in the TCG, get its TCG debut date and limitation history.
 
if (self.isTcg) then
 
if (self.isTcg) then
self.tcgLimitations = LimitationHistory:new(self.pageName, 'Advanced Format')
+
self.tcgDebutDate = self:getFirstSetDateInGame(TCG)
 +
self.tcgLimitations = LimitationHistory:new(self.pageName, 'Advanced Format', self.tcgDebutDate)
 
end
 
end
  

Revision as of 17:10, 10 December 2023

Card = require('Module:Card')

require('Module:Card/traits/has sets')
require('Module:Card/traits/accepts image input')
local LimitationHistory = require('Module:Card/models/Limitation history')

local Parent = mw.clone(Card)

-- ------------------------------------
-- Overwrite `Module:Card` data
-- ------------------------------------
Card.config.defaultImage    = 'Back-EN.png'
Card.config.enableMainLinks = false
Card.config.langs           = { 'en', 'fr', 'de', 'it', 'pt', 'es', 'ja', 'tc', 'sc', 'ko' }
Card.config.rows            = {
	'cardType',
	'property',
	'attribute',
	'type',
	'level',
	'rank',
	'pendulumScale',
	'linkArrows',
	'atkDef',
	'atkLink',
	'effectType',
	'lore',
	'limitationText',
	'limitationStatus',
	'password'
}
Card.config.allowedCardTypes = {
	'Monster', 'Spell', 'Trap',
	'Skill', 'Token', 'Counter',
	'Ticket', 'Non-game',
	'Tip', 'Strategy', 'FAQ',
	'???'
}
Card.config.allowedAttributes = {
	'LIGHT', 'DARK', 'FIRE', 'WATER', 'WIND', 'EARTH', 'DIVINE', 'LAUGH', '???'
}
Card.config.allowedTypes = {
	'Dragon', 'Spellcaster', 'Zombie', 'Warrior', 'Beast-Warrior', 'Beast',
	'Winged Beast', 'Fiend', 'Fairy', 'Insect', 'Dinosaur', 'Reptile', 'Fish',
	'Sea Serpent', 'Machine', 'Thunder', 'Aqua', 'Pyro', 'Rock', 'Plant',
	'Divine-Beast', 'Psychic',	'Creator God', 'Wyrm', 'Cyberse', 'Illusion',
	'Charisma', 'Human',
	'Fusion', 'Ritual', 'Synchro', 'Xyz', 'Link',
	'Flip', 'Toon', 'Spirit', 'Union', 'Gemini',
	'Tuner', 'Pendulum',
	'Normal', 'Effect',
	'?', '???'
}

Card.setsConfig.breakdown = {
	{
		abbr      = 'tcg',
		shortName = 'TCG',
		name      = 'Yu-Gi-Oh! Trading Card Game',
		languages = { 'en', 'fr', 'de', 'it', 'pt', 'es' }
	},
	{
		abbr      = 'ocg',
		shortName = 'OCG',
		name      = 'Yu-Gi-Oh! Official Card Game',
		languages = { 'ja', 'en', 'sc', 'tc', 'ko' }
	}
}

-- Filter sets search to only include sets in this space.
Card.setsConfig.filter = '[[-Has subobject.Release::OCG||TCG]]'

-- Set defaults for some extra params, not present in the base module.
Card.isOcg = false
Card.isTcg = false
Card.ocgLimitations = {}
Card.tcgLimitations = {}

-- Constants containing full names
local TCG = 'Yu-Gi-Oh! Trading Card Game'
local OCG = 'Yu-Gi-Oh! Official Card Game'



-- ------------------------------------
-- Override `Module:Card` methods
--     These functions exist in `Module:Card`, but are overridden here to
--     make them more specific to OCG/TCG cards
-- ------------------------------------

-- Set data on initialization
function Card:setData(args)
	-- Call the original `setData` method.
	Parent.setData(self, args)

	-- Set OCG/TCG booleans based on what sets the card appears in
	self.isOcg = self:hasSetsInGame(OCG)
	self.isTcg = self:hasSetsInGame(TCG)
	self.isOcgOnly = self.isOcg and not self.isTcg
	self.isTcgOnly = self.isTcg and not self.isOcg

	if self.isOcg     then table.insert(self.categories, 'OCG cards') end
	if self.isTcg     then table.insert(self.categories, 'TCG cards') end
	if self.isOcgOnly then table.insert(self.categories, 'OCG-only cards') end
	if self.isTcgOnly then table.insert(self.categories, 'TCG-only cards') end

	-- Change the default image, if the card is OCG-only.
	if (self.isOcgOnly) then
		self.config.defaultImage = 'Back-JP.png'
	end

	-- Set the debut date equal to the release date of the first set, unless suppressed
	self.debutDate = args.unknown_debut_date
		and nil
		or self:getFirstSetDate()

	-- If the card exists in the OCG, get its OCG debut date and limitation history.
	if (self.isOcg) then
		self.ocgDebutDate = self:getFirstSetDateInGame(OCG)
		self.ocgLimitations = LimitationHistory:new(self.pageName, 'OCG', self.ocgDebutDate)
	end

	-- If the card exists in the TCG, get its TCG debut date and limitation history.
	if (self.isTcg) then
		self.tcgDebutDate = self:getFirstSetDateInGame(TCG)
		self.tcgLimitations = LimitationHistory:new(self.pageName, 'Advanced Format', self.tcgDebutDate)
	end

	-- Add category to cards with no debut date.
	if (self.debutDate == nil and not self:isUnprintedToken()) then
		table.insert(self.categories, 'Cards with an unknown debut date')
	end

	-- Add category if the debut date is suppressed.
	if (args.unknown_debut_date) then
		table.insert(self.categories, 'Cards not using the automatic debut date')
	end
end

-- Override the `renderAdditionalSections` method to include a 'limitation history' section
function Card:renderAdditionalSections()
	-- Call the parent function
	local sections = Parent.renderAdditionalSections(self)

	-- Add limitation history to the additional sections
	sections = sections .. renderLimitationHistorySection(self)

	-- Return the combined section
	return sections
end


-- ------------------------------------
-- Custom methods
-- ------------------------------------
-- Check if the card is an unprinted Token
-- i.e. The Token exists in concept, but doesn't have a physical card
-- @return bool
function Card:isUnprintedToken()
	local isToken = self.cardTypes[1] and self.cardTypes[1].name == 'Token'

	return (isToken and #self.sets == 0)
end

-- Add a row for the current limitation statuses
function Card:addLimitationStatusRow()
	-- Get the current status for each format
	local tcgStatus = self.tcgLimitations.currentStatus
	local ocgStatus = self.ocgLimitations.currentStatus

	-- If there are none, don't add the row
	if (not tcgStatus and not ocgStatus) then return end

	-- Render badges for each format that has a status
	local tcgBadge = tcgStatus and LimitationHistory.renderStatusBadge(tcgStatus, '<i>[[' .. TCG .. '|TCG]]</i>') or ''
	local ocgBadge = ocgStatus and LimitationHistory.renderStatusBadge(ocgStatus, '<i>[[' .. OCG .. '|OCG]]</i>') or ''

	-- Join the badges together, space them out and put them in a card table row
	self:addRow('[[Status]]', '<div style="display: flex; flex-wrap: wrap; gap: .5em;">' .. tcgBadge .. ocgBadge .. '</div>')
end

-- Render a section for limitation histories
-- @param card Card
-- @return string
function renderLimitationHistorySection(card)
	local content = ''

	-- Get lists of each time the status was changed in each format
	local tcgHistory = card.tcgLimitations.groupedHistory or {}
	local ocgHistory = card.ocgLimitations.groupedHistory or {}

	-- No status history, just return the empty string.
	if (#tcgHistory == 0 and #ocgHistory == 0) then
		return ''
	end

	-- If there is TCG history, render a subsection
	if (#tcgHistory ~= 0) then
		content = content .. "<div>\n'''''" .. TCG .. "'''''\n"
		content = content .. card.tcgLimitations:renderHistoryTable()
		content = content .. '\n</div>'
	end

	-- If there is OCG history, render a subsection
	if (#ocgHistory ~= 0) then
		content = content .. "<div>\n'''''" .. OCG .. "'''''\n"
		content = content .. card.ocgLimitations:renderHistoryTable()
		content = content .. '\n</div>'
	end

	-- Put subsections side-by-side if they fit
	content = '<div style="display: flex; flex-wrap: wrap; gap: 1em;">' .. content .. '</div>'

	-- Put everything inside a section
	return card.renderSection('Limitation history', tostring(content))
end

return Card