Changes

Jump to: navigation, search

Module:Limitation status list

8,599 bytes added, 4 months ago
`-` needs to be escaped in patterns
-- Shell object for the list itselflocal List = { name = nil, medium = nil, locality = nil, startDate = nil, prev = nil, next = nil, items = {},  -- If there is a column for non-English names -- The text to display in the column heading localColumnHeading = nil, -- The name of the SMW property to find the names in localColumnProperty = nil,  errors = {}} -- Shell object for an item in the listlocal ListItem = {CardTable2|dename -- Link to card page. `nil` if not a specific card card = nil, -- Name of the card page, if applicable cardName = nil, localCardName = nil, -- Final text to display in the cell displayText = nil, cardType = nil, status = nil, prevStatus = Kreuzangriffnil,|itname prevStatusNote = Attacco Incrociatonil} -- Main function that gets invoked-- Create a new list from the user input, then render itfunction List.list(frame) -- Get the template parameters|kanji local args = クロス・アタック frame:getParent().args|phon local l = Kurosu AtakkuList:new(args) return l:render()end -- Create a new instance of a list-- @param args table-- @return Listfunction List:new(args)|image local l = CrossAttackmw.clone(List)  l:setData(args or {})  return lend -- Main function for setting data for the list-PHSW-EN@param args table - data from the user inputfunction List:setData(args) self.name = args.name or mw.title.getCurrentTitle().text self.medium = args.medium self.locality = args.locality self.startDate = args.start_date self.prev = args.prev self.next = args.next self:setLocalisationAttributes()  self.items = {} self:addItems('Forbidden', args.forbidden) self:addItems('Limited', args.limited) self:addItems('Semi-Limited', args.semi_limited) self:addItems('Unlimited', args.no_longer_on_list)  self:setSmwData()end function List:setLocalisationAttributes() if ( self.locality == 'Simplified Chinese' or self.locality == 'Traditional Chinese' or self.locality == 'Japanese' or self.locality == 'Korean' ) then self.localColumnHeading = self.locality self.localColumnProperty = self.locality .. ' name'  elseif self.medium == 'OCG' or self.medium == 'Yu-CGi-1EOh! Official Card Game' then self.localColumnHeading = 'Japanese' self.jpglocalColumnProperty = 'Japanese name'  else self.localColumnHeading = nil self.localColumnProperty = nil endend -- Add items based on user input-- @param status string-- @param listInput stringfunction List:addItems(status, listInput) -- Exit early if there is no input if not isFilled(listInput) then return end  -- Split the input by new line and loop through each line|attribute local listItems = Spellmw.text.split(listInput, '\n')|typest for _, line in pairs(listItems) do -- Split the line input by `//` and get data from each piece local lineData = Normalmw.text.split(line, '%s*//%s*')|number local itemText = 46961802lineData[1]|animelore local options = lineData[2]  -- Extract data from content after the `//` local prevStatus = options and options:match('prev::([Target^;]*)') local prevStatusNote = options and options:match('prev%-note::([^;] 2 *)')  -- Create a new list item object local listItem = mw.clone(ListItem)  listItem.status = status listItem.prevStatus = prevStatus listItem.prevStatusNote = prevStatusNote listItem.displayText = itemText  -- Assume it's a card if there's no manual link syntax local isCard = not itemText:find('%[%[face')  -- If it's a card, look up the card's data and fill in more of the attributes if isCard then local cardData = self:lookupCardData(itemText)  if (not cardData) then table.insert(self.errors, 'Failed to look up]] details for card: "' .. itemText .. '"') end  listItem.card = itemText listItem.cardName = cardData and cardData.name or itemText listItem.localCardName = cardData and cardData.localName or '' listItem.cardType = cardData and cardData.cardType listItem.displayText = '"[[monster' .. listItem.card .. '|' .. listItem.cardName .. ']]s with "' end  -- Add the card to the same list table.insert(self.items, listItem) endend function List:setSmwData() mw.smw.set({ ['Effective date'] = self.startDate, [ATK'Medium']]; during this = self.medium, [[turn]'Release'] = self.medium, 1 of the targeted monsters can [[attack'Locality']] your opponent = self.locality, [[Direct attack|directly]'Page type'] = 'Status list' })  -- Go through each list item to add a subobject for _, item in pairs(self.items) do -- If it's not a card, but the other target cannot attackdon't store any data if (not item.card) then return end  mw.smw.subobject({ 'List contains = ' .. item.card,|lore 'Status = [[Target]] 2 [[face' .. item.status, }) endend --up]] Find data on a card by suppyling its namefunction List:lookupCardData(pageName) local queryParams = { '[[Attack Position' .. pageName .. ']] ', '?English name = name', '?Card type# = cardType', }  if (self.localColumnProperty) then table.insert(queryParams, '?' .. self.localColumnProperty .. ' = localName') end  local cardData = mw.smw.ask(queryParams)  return cardData and cardData[[monster]1]or nilend -- Filter a list's you [[control]] `cards` attribute by a status-- @return tablefunction List:getItemsByStatus(status) -- New array to contain list items with just the specified status local filteredItems = {}  -- Loop through the list of all cards for _, item in pairs(self.items) do -- If the item has the specified status, add it to the new array if (item.status == status) then table.insert(filteredItems, item) end end  return filteredItemsend -- Render the overall output-- @return stringfunction List:render() local output = '' output = output .. self:renderErrors() output = output .. self:renderNavigation() output = output .. self:renderStatusList('Forbidden') output = output .. self:renderStatusList('Limited') output = output .. self:renderStatusList('Semi-Limited') output = output .. self:renderStatusList('Unlimited', 'No longer on list') output = output .. self:renderCategories()  return outputend function List:renderErrors() -- Exit early with empty string if there are no errors. if (#self.errors == 0) then return '' end;  local output = '<div style="color: #d33;">' output = output .. '\nThis list contains the following issues:\n'  for _, error in pairs(self.errors) do output = output .. '\n* ' .. error .. '' end  output = output .. '\n</div>'  return outputend -- Render the same navigation section-- @return stringfunction List:renderNavigation() -- If prev and next are both empty, don't show a navigation menu if (not isFilled(self.prev) and not isFilled(self.next)) then return '' end  local currText = self:pageNameToShortName(self.name) local prevText = self.prev and ('← [[ATK' .. self.prev .. '|' .. self:pageNameToShortName(self.prev) .. ']]') or '&nbsp; this ' local nextText = self.next and ('[[turn' .. self.next .. '|' .. self:pageNameToShortName(self.next) .. ']]→') or '&nbsp;'  local output = '<div class="toccolours" style="clear: both; display: flex; margin-bottom: .5em;">' output = output .. '<div style="flex: 1; text-align: left;">' .. prevText .. '</div>' output = output .. '<div style="flex: 1; text-align: center;">' .. currText .. '</div>' output = output .. '<div style="flex: 1; text-align: right;">' .. nextText .. '</div>' output = output .. '</div>'  return outputend -- Convert a page name to a short name-- e.g. "March 2020 Lists (Duel Links)" -> "March 2020 Lists"-- e.g. "OCG April 2014 Lists" -> "April 2014 Lists"-- @param pageName string-- @return stringfunction List:pageNameToShortName(pageName) -- Strip out disambiguation text local shortName = mw.text.split(pageName, one ' %(')[1]  -- Remove mention of the them can medium shortName = shortName:gsub(self.medium, '')  -- Clear any leading/trailing spaces return mw.text.trim(shortName)end function List:renderCategories() -- Don't render any categories if this is outside of the main namespace if (isFilled(mw.title.getCurrentTitle().nsText)) then return '' end  local output = '[[attackCategory:' .. (self.region or '') .. ' ' .. (self.medium or '') .. ' Forbidden & Limited Lists]] your opponent '  if (#self.errors > 0) then output = output .. '[[Direct attack|directlyCategory:Pages with validation errors]] ' end  return outputend -- Render a section with a list fora given status-- @param status string-- @param heading status - The text to appear in the heading, if different than the status-- @return stringfunction List:renderStatusList(status, heading) -- Get all list items for the given status local items = self:getItemsByStatus(status)  -- If there are no cards, return empty string and the other cannot attackend early if (#items == 0) then return '' end  local heading = mw.html.create('h2'):wikitext(heading or status)|jplore local list = 自分フィールド上に表側攻撃表示で存在する、同じ攻撃力を持つモンスター2体を選択して発動する。このターン、選択したモンスター1体は相手プレイヤーに直接攻撃する事ができる。もう1体のモンスターは攻撃する事ができない。mw.html.create('table'):addClass('wikitable sortable')|en_sets local headingRow =list:tag('tr') headingRow:tag('th'):wikitext('Card') if self.localColumnHeading then headingRow:tag('th'):wikitext(self.localColumnHeading) end headingRow:tag('th'):wikitext('Card type') headingRow:tag('th'):wikitext('Status') headingRow:tag('th'):wikitext('Changes')  for _, item in pairs(items) do local cardTypeLink = item.cardType and ('[[Photon Shockwave' .. item.cardType .. '|' .. string.gsub(item.cardType, ' Card', '') .. ']]') or '' ([[PHSW  --EN048]] Form the CSS class that styles the cells in the status column local statusClass = 'status- [[C]]' .. (item.status):lower()|jp_sets local row =list:tag('tr') row:tag('td'):wikitext(item.displayText) if self.localColumnHeading then row:tag('td'):wikitext(item.localCardName) end row:tag('td'):wikitext(cardTypeLink) row:tag('td'):addClass(statusClass):wikitext('[[Photon Shockwave' .. item.status .. ']]') row:tag('td' ):wikitext( (item.prevStatus and 'was [[PHSW-JP048' .. item.prevStatus .. ']] ' or '') .. (item.prevStatusNote or '') ) end  return tostring(heading) .. tostring(list)end -- Check if something has been filled out-- i.e. check that it's neither `nil` nor empty string-- @param value mixed-- [[C]]@return boolfunction isFilled(value)|attack1 return value ~= Allows direct attacks|attack2 nil and value ~= Prevents your monsters from attacking''|misc1 = Femaleend|anime_zx = 014, 027|manga_zx = 009}}return List

Navigation menu