Changes

Jump to: navigation, search

Module:Limitation status list

5,809 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 = {Unofficial name|Croatian}},
-- 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| hr_name -- Link to card page. `nil` if not a specific card card = nil, -- Name of the card page, if applicable cardName = Križani Napadnil,| de_name localCardName = Kreuzangriffnil,| fr_name -- Final text to display in the cell displayText = Attaque Croiséenil,| it_name cardType = Attacco Incrociatonil,| ko_name status = 크로스 어택nil,| pt_name prevStatus = Ataque Cruzadonil,| es_name prevStatusNote = Ataque Cruzadonil} -- Main function that gets invoked| ja_name -- Create a new list from the user input, then render itfunction List.list(frame) -- Get the template parameters local args = クロス・アタックframe:getParent().args| romaji_name local l = Kurosu AtakkuList:new(args) return l:render()end -- Create a new instance of a list| image -- @param args table-- @return Listfunction List:new(args) local l = CrossAttackmw.clone(List)  l:setData(args or {})  return lend -SP14-ENMain function for setting data for the list-C-1E@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.pnglocality == 'Traditional Chinese' or| card_type self.locality == Spell'Japanese' or| property self.locality == Normal'Korean'| passcode ) then self.localColumnHeading = 46961802self.locality| effect_types self.localColumnProperty = Effectself.locality .. ' name'| lore elseif self.medium == 'OCG' or self.medium == [[Target]] 2 [[face'Yu-Gi-up]] [[Attack Position]] [[Monster Oh! Official Card|monster]]Game' then self.localColumnHeading = 'Japanese' self.localColumnProperty = '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 local listItems = mw.text.split(listInput, '\n')  for _, line in pairs(listItems) do -- Split the line input by `//` and get data from each piece local lineData = mw.text.split(line, '%s*//%s you *') local itemText = lineData[1] local options = lineData[control2]] with   -- Extract data from content after the same `//` local prevStatus = options and options:match('prev::([[ATK]]^; this [[turn]], one of them can *)') local prevStatusNote = options and options:match('prev%-note::([[attack^;]] your opponent *)')  -- 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('%[%[Direct attack|directly]] ')  -- If it's a card, look up the card's data and fill in more of the other cannot attack.attributes if isCard then| fr_lore local cardData = Ciblez 2 monstres en Position dself:lookupCardData(itemText)  if (not cardData) then table.insert(self.errors, 'Attaque face recto que vous contrôlez avec la même ATK ; ce tour, lFailed to look up details for card: "'un d.. itemText .. 'eux peut attaquer directement votre adversaire et l"'autre ne peut pas attaquer) end  listItem.card = itemText| de_lore listItem.cardName = cardData and cardData.name or itemText listItem.localCardName = cardData and cardData.localName or '' listItem.cardType = Wähle 2 Monster in offener Angriffsposition, die du kontrollierst und die dieselben ATK haben; in diesem Spielzug kann eins von ihnen deinen Gegner direkt angreifen und das andere kann nicht angreifencardData and cardData.cardType| it_lore listItem.displayText = '"[[Target' .. listItem.card .. '|Scegli come bersaglio' .. listItem.cardName .. ']] 2 mostri scoperti in Posizione di Attacco che "' end  -- Add the card to the list table.insert(self.items, listItem) endend function List:setSmwData() mw.smw.set({ ['Effective date'] = self.startDate, [control'Medium']]li con lo stesso ATK; in questo turno = self.medium, uno di essi può attaccare il tuo avversario [[Direct attack|direttamente]'Release'] = self.medium, e l ['Locality'altro non può attaccare] = self.locality,| pt_lore ['Page type'] = 'Status list'| es_lore = Selecciona 2 monstruos con el mismo ATK en Posición de Ataque boca arriba que controles; este turno })  -- Go through each list item to add a subobject for _, uno de ellos puede atacar item in pairs(self.items) do -- If it's not a tu adversario directamentecard, y el otro no puede atacardon't store any data if (not item.card) then return end | ja_lore = 自分フィールド上に表側攻撃表示で存在する、同じ攻撃力を持つモンスター2体を選択して発動する。このターン、選択したモンスター1体は相手プレイヤーに直接攻撃する事ができる。もう1体のモンスターは攻撃する事ができない。 mw.smw.subobject({| ko_lore 'List contains = ' .. item.card,| en_sets 'Status = ' .. item.status,{{Card table set/header|en} }) endend -- Find data on a card by suppyling its namefunction List:lookupCardData(pageName) local queryParams = {{ '[[' .. pageName .. ']]', '?English name = name', '?Card table set|PHSW-EN048|Photon Shockwave|Common}type# = cardType', }{{Card if (self.localColumnProperty) then table set|SP14.insert(queryParams, '?' .. self.localColumnProperty .. ' = localName') end  local cardData = mw.smw.ask(queryParams)  return cardData and cardData[1] or nilend --EN032|Star Pack 2014|Common}}Filter a list's `cards` attribute by a status{{Card -- @return table set|SP14function List:getItemsByStatus(status) --EN032|Star Pack 2014|Starfoil Rare}}New array to contain list items with just the specified status local filteredItems = {{Card table set/footer}}| fr_sets -- 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{{Card table set/header|fr}}.insert(filteredItems, item) end end  return filteredItemsend -- Render the overall output{{Card table set|PHSW-FR048|Photon Shockwave|Common}}- @return stringfunction List:render() local output = '' output = output .. self:renderErrors() output = output .. self:renderNavigation() output = output .. self:renderStatusList('Forbidden') output = output .. self:renderStatusList('Limited'){{Card table set|SP14 output = output .. self:renderStatusList('Semi-FR032|Star Pack 2014|Common}}Limited') output = output .. self:renderStatusList('Unlimited', 'No longer on list') output = output .. self:renderCategories()  return outputend function List:renderErrors(){{Card table set|SP14 --FR032|Star Pack 2014|Starfoil Rare}}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' {{Card table set/footer}} for _, error in pairs(self.errors) do| de_sets output = output .. '\n* ' .. error .. '' end {{Card table set output = output .. '\n</header|de}}div>'  return outputend -- Render the navigation section-- @return stringfunction List:renderNavigation(){{Card table set|PHSW --DE048If 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 ('← [[' .. self.prev .. '|Photon Shockwave' .. self:pageNameToShortName(self.prev) .. ']]') or '&nbsp;' local nextText = self.next and ('[[' .. self.next .. '|Common}}' .. self:pageNameToShortName(self.next) .. ']] →') or '&nbsp;' {{Card table set|SP14 local output = '<div class="toccolours" style="clear: both; display: flex; margin-DE032|Star Pack 2014|Common}}bottom: .5em;">'{{Card table set|SP14 output = output .. '<div style="flex: 1; text-DE032|Star Pack 2014|Starfoil Rare}}align: left;">' .. prevText .. '</div>'{{Card table set output = output .. '<div style="flex: 1; text-align: center;">' .. currText .. '</footer}}div>'| it_sets output = output .. '<div style= "flex: 1; text-align: right;">' .. nextText .. '</div>'{{Card table set output = output .. '</header|it}}div>'  return outputend -- Convert a page name to a short name{{Card table set|PHSW-IT048|Photon Shockwave|Common}}- e.g. "March 2020 Lists (Duel Links)" -> "March 2020 Lists"{{Card table set|SP14-IT032|Star Pack - e.g. "OCG April 2014 Lists" -> "April 2014|Common}}Lists"-- @param pageName string-- @return stringfunction List:pageNameToShortName(pageName){{Card table set|SP14 --IT032|Star Pack 2014|Starfoil Rare}}Strip out disambiguation text local shortName = mw.text.split(pageName, ' %(')[1] {{Card table set/footer}} -- Remove mention of the medium| pt_sets shortName = shortName:gsub(self.medium, '') {{Card table set -- Clear any leading/header|pt}}trailing spaces return mw.text.trim(shortName)end function List:renderCategories(){{Card table set|SP14 --PT032|Star Pack 2014|Common}}Don't render any categories if this is outside of the main namespace if (isFilled(mw.title.getCurrentTitle().nsText)) then return '' end  local output = '[[Category:' .. (self.region or '') .. ' ' .. (self.medium or '') .. ' Forbidden & Limited Lists]]'{{Card table set|SP14-PT032|Star Pack 2014|Starfoil Rare}}{{Card table set/footer}} if (#self.errors > 0) then| sp_sets output = output .. '[[Category:Pages with validation errors]]' end  return outputend {{Card table set/header|sp}}-- Render a section with a list fora given status{{Card table set|PHSW-SP048|Photon Shockwave|Common}}- @param status string{{Card table set|SP14-SP032|Star Pack 2014|Common}}- @param heading status - The text to appear in the heading, if different than the status{{Card table set|SP14-SP032|Star Pack 2014|Starfoil Rare}}- @return stringfunction List:renderStatusList(status, heading){{Card table set/footer}} -- Get all list items for the given status| jp_sets local items = self:getItemsByStatus(status){{Card table set/header|jp}}{{Card table set|PHSW --JP048|Photon Shockwave|Common}}If there are no cards, return empty string and end early if (#items == 0) then return '' end  local heading = mw.html.create('h2'):wikitext(heading or status){{Card local list = mw.html.create('table set/footer}}'):addClass('wikitable sortable') | kr_sets local headingRow = list:tag('tr'){{ headingRow:tag('th'):wikitext('Card table set/header|kr}}') if self.localColumnHeading then headingRow:tag('th'):wikitext(self.localColumnHeading) end{{ headingRow:tag('th'):wikitext('Card table settype') headingRow:tag('th'):wikitext('Status') headingRow:tag('th'):wikitext('Changes')  for _, item in pairs(items) do local cardTypeLink = item.cardType and ('[[' .. item.cardType .. '|PHSW' .. string.gsub(item.cardType, ' Card', '') .. ']]') or ''  --KR048|Photon Shockwave|Common}}Form the CSS class that styles the cells in the status column local statusClass = 'status-' .. (item.status):lower(){{Card table set/footer}}| attack 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('[[' .. item.status .. ']]') row:tag('td'):wikitext( (item.prevStatus and 'was [[' .. 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* Allows direct attacks-- @param value mixed-- @return bool* Prevents your monsters from attackingfunction isFilled(value)| misc return value ~= nil and value ~= Female''end| database_id = 9766}}return List

Navigation menu