• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Difference between revisions of "Module:Seasonal"

From Kancolle Wiki
Jump to navigation Jump to search
(Created page with " local seiyuus = { ["Bridcut Sarah Emi"] = { url = "http://myanimelist.net/people/19371/Sarah_Emi_Bridcut", ships = {"Hatsukaze", "Kumano", "Maikaze", "Su...")
 
m (47 revisions imported)
 
(46 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
local U = require('Module:Core')
 +
local Utils = require('Module:Core')
 +
local format = require('Module:Core').format
 +
local getArgs = require('Module:GetArgs')
  
local seiyuus = {
+
local artists = require('Module:Collection/Artists')
    ["Bridcut Sarah Emi"] = {
+
local seiyuus = require('Module:Collection/Seiyuus')
        url = "http://myanimelist.net/people/19371/Sarah_Emi_Bridcut",
+
local types = require('Module:Collection/ShipsByType')
        ships = {"Hatsukaze", "Kumano", "Maikaze", "Suzuya", "Yuubari", },
 
    },
 
    ["Endou Aya"] = {
 
        url = "http://myanimelist.net/people/54/Aya_Endou",
 
        ships = {"Bismarck", "Z1", "Z3", },
 
    },
 
    ["Fujita Saki"] = {
 
        url = "http://myanimelist.net/people/504",
 
        ships = {"Akagi", "Fusou", "Kagerou", "Kuroshio", "Shiranui", "Tokitsukaze", "Yamashiro", "Yukikaze", },
 
    },
 
    ["Hayami Saori"] = {
 
        url = "http://myanimelist.net/people/869/Saori_Hayami",
 
        ships = {"Graf Zeppelin", "Hagikaze", },
 
    },
 
    ["Hayasaka Kozue"] = {
 
        url = null,
 
        ships = {"Akebono", "Oboro", "Sazanami", "Ushio", },
 
    },
 
    ["Hidaka Rina"] = {
 
        url = "http://myanimelist.net/people/5250/Rina_Hidaka",
 
        ships = {"Fumizuki", "Kikuzuki", "Kisaragi", "Mikazuki", "Mochizuki", "Mutsuki", "Nagatsuki", "Ryuujou", "Satsuki", "Uzuki", "Yayoi", },
 
    },
 
    ["Horie Yui"] = {
 
        url = "http://myanimelist.net/people/28/Yui_Horie",
 
        ships = {"Amagi", "Asagumo", "Yamagumo", },
 
    },
 
    ["Iguchi Yuka"] = {
 
        url = "http://myanimelist.net/people/885/Yuka_Iguchi",
 
        ships = {"Chikuma", "Isuzu", "Kaga", "Nagara", "Natori", "Tatsuta", "Tenryuu", "Tone", },
 
    },
 
    ["Ise Mariya"] = {
 
        url = "http://myanimelist.net/people/655/Mariya_Ise",
 
        ships = {"I-401", },
 
    },
 
    ["Ishigami Shizuka"] = {
 
        url = "http://myanimelist.net/people/28755/Shizuka_Ishigami",
 
        ships = {"Kawakaze", "Mizuho", "Umikaze", },
 
    },
 
    ["Kanemoto Hisako"] = {
 
        url = "http://myanimelist.net/people/8555/Hisako_Kanemoto",
 
        ships = {"Harusame", "Hayashimo", "Kiyoshimo", },
 
    },
 
    ["Kawasumi Ayako"] = {
 
        url = "http://myanimelist.net/people/13/Ayako_Kawasumi",
 
        ships = {"Isokaze", "Ooyodo", "Unryuu", },
 
    },
 
    ["Kayano Ai"] = {
 
        url = "http://myanimelist.net/people/10765/",
 
        ships = {"Arashi", "Asashimo", "Kashima", "Katori", "Katsuragi", "Ro-500", "U-511", },
 
    },
 
    ["Kitou Akari"] = {
 
        url = "https://ja.wikipedia.org/wiki/%E9%AC%BC%E9%A0%AD%E6%98%8E%E9%87%8C",
 
        ships = {"Kazagumo", "Libeccio", },
 
    },
 
    ["Kobayashi Motoko"] = {
 
        url = "http://myanimelist.net/people/12285/Motoko_Kobayashi",
 
        ships = {"Hatsuharu", "Hatsushimo", "Nenohi", "Wakaba", },
 
    },
 
    ["Komatsu Mana"] = {
 
        url = "http://myanimelist.net/people/12941/Mana_Komatsu",
 
        ships = {"Hamakaze", "Tanikaze", "Urakaze", "Zuihou", },
 
    },
 
    ["Komatsu Mikako"] = {
 
        url = "http://myanimelist.net/people/10071/Komatsu_Mikako",
 
        ships = {"Akitsushima", "Teruzuki", },
 
    },
 
    ["Kuno Misaki"] = {
 
        url = "http://myanimelist.net/people/11641/Misaki_Kuno",
 
        ships = {"Littorio", "Roma", "Takanami", },
 
    },
 
    ["Misato"] = {
 
        url = "http://myanimelist.net/people/12759/Misato",
 
        ships = {"I-19", "I-8", "Musashi", },
 
    },
 
    ["Miyagawa Wakana"] = {
 
        url = "http://www.animenewsnetwork.com.au/encyclopedia/people.php?id=98235",
 
        ships = {"Arare", "Arashio", "Asashio", "Chitose", "Chiyoda", "Kasumi", "Michishio", "Ooshio", },
 
    },
 
    ["Nakajima Megumi"] = {
 
        url = "http://myanimelist.net/people/1105/Megumi_Nakajima",
 
        ships = {"I-168", "I-58", "Kinugasa", "Mikuma", },
 
    },
 
    ["Nomizu Iori"] = {
 
        url = "http://myanimelist.net/people/8956/Iori_Nomizu",
 
        ships = {"Abukuma", "Hayasui", "Kinu", "Shoukaku", "Zuikaku", },
 
    },
 
    ["Noto Mamiko"] = {
 
        url = "http://myanimelist.net/people/40/Mamiko_Noto",
 
        ships = {"Akitsu Maru", "Maruyu", "Taihou", },
 
    },
 
    ["Ogura Yui"] = {
 
        url = "http://myanimelist.net/people/10981/Yui_Ogura",
 
        ships = {"Amatsukaze", "Ryuuhou", "Taigei", },
 
    },
 
    ["Ootsubo Yuka"] = {
 
        url = "http://myanimelist.net/people/12452/Yuka_Ootsubo",
 
        ships = {"Furutaka", "Hiyou", "Hyuuga", "Ise", "Junyou", "Kako", "Kitakami", "Ooi", },
 
    },
 
    ["Ozawa Ari"] = {
 
        url = "http://myanimelist.net/people/27395/Ari_Ozawa",
 
        ships = {"Akizuki", "Nowaki", "Prinz Eugen", },
 
    },
 
    ["Sakura Ayane"] = {
 
        url = "http://myanimelist.net/people/11622/Ayane_Sakura",
 
        ships = {"Jintsuu", "Kiso", "Kuma", "Mutsu", "Nagato", "Naka", "Sendai", "Shimakaze", "Tama", },
 
    },
 
    ["Suzaki Aya"] = {
 
        url = "http://myanimelist.net/people/19834/Aya_Suzaki",
 
        ships = {"Akatsuki", "Aoba", "Hibiki", "Houshou", "Ikazuchi", "Inazuma", "Mogami", },
 
    },
 
    ["Taketatsu Ayana"] = {
 
        url = "http://myanimelist.net/people/6996/Ayana_Taketatsu",
 
        ships = {"Akigumo", "Makigumo", "Naganami", "Yamato", "Yuugumo", },
 
    },
 
    ["Taneda Risa"] = {
 
        url = "http://myanimelist.net/people/16135/Risa_Taneda",
 
        ships = {"Akashi", "Ashigara", "Haguro", "Myoukou", "Nachi", "Samidare", "Shouhou", "Suzukaze", },
 
    },
 
    ["Tanibe Yumi"] = {
 
        url = "http://myanimelist.net/people/35951",
 
        ships = {"Murasame", "Shigure", "Shiratsuyu", "Yura", "Yuudachi", },
 
    },
 
    ["Touyama Nao"] = {
 
        url = "http://myanimelist.net/people/11184/Nao_Touyama",
 
        ships = {"Atago", "Ayanami", "Choukai", "Haruna", "Hiei", "Kirishima", "Kongou", "Maya", "Shikinami", "Takao", },
 
    },
 
    ["Uesaka Sumire"] = {
 
        url = "http://myanimelist.net/people/14441/Sumire_Uesaka",
 
        ships = {"Fubuki", "Hatsuyuki", "Hiryuu", "Isonami", "Miyuki", "Murakumo", "Shirayuki", "Souryuu", },
 
    },
 
    ["Yamada Yuki"] = {
 
        url = "http://myanimelist.net/people/28053/Yuki_Yamada",
 
        ships = {"Agano", "Noshiro", "Sakawa", "Yahagi", },
 
    },
 
}
 
  
local Seasonal = {}
+
local function requireSeasonModule(name)
 +
  local success, data = U.requireModule('Data/Season/' .. name)
 +
  if not success then
 +
    success, data = U.requireModule('Seasonal/' .. name)
 +
  end
 +
  if not success then
 +
    data = {index = {}, ships = {}}
 +
  end
 +
  return data
 +
end
  
local Utils = require('Module:Utils')
+
function findType(ship)
 +
    for type, data in pairs(types) do
 +
        if data.ships and Utils.find(data.ships, ship) then
 +
            return type
 +
        end
 +
    end
 +
    return "?"
 +
end
  
function Seasonal.toc(frame)
+
function genToc(args, tbl, format)
    local args = frame.args
 
 
     local result = ""
 
     local result = ""
 
     local i = 0
 
     local i = 0
     for seiyuu, data in pairs(seiyuus) do
+
    local n = 0
 +
     for _, k in ipairs(tbl.index) do
 +
        local data = tbl[k]
 
         local ships = Utils.filter(data.ships, function(ship) return Utils.find(args, ship) end)
 
         local ships = Utils.filter(data.ships, function(ship) return Utils.find(args, ship) end)
 
         if #ships > 0 then
 
         if #ships > 0 then
 
             i = i + 1
 
             i = i + 1
             local ships_str = table.concat(Utils.map(ships, function(ship) return string.format("[[#%s|%s]]", ship, ship) end), ", ")
+
            n = n + #ships
 +
             local ships_str = table.concat(Utils.map(ships, function(ship) return string.format("[[#%s|%s]]", args.art and (tbl.type == "types" and k or findType(ship)) or ship, ship) end), ", ")
 
             if data.url then
 
             if data.url then
                 result = result .. string.format("|-\n|[%s %s]\n|%s\n", data.url, seiyuu, ships_str)
+
                 result = result .. string.format("|-\n|[%s %s]\n|%s\n", data.url, k, ships_str)
 +
            elseif tbl.type == "types" then
 +
                result = result .. string.format("|-\n|[[#%s|%s]] (%s)\n|%s\n", args[k] and (k .. " 2") or k, k, #ships, ships_str)
 
             else
 
             else
                 result = result .. string.format("|-\n|%s\n|%s\n", seiyuu, ships_str)
+
                 result = result .. string.format("|-\n|%s\n|%s\n", k, ships_str)
 
             end
 
             end
 
         end
 
         end
 
     end
 
     end
     result = string.format([===[{| class="mw-collapsible mw-collapsed wikitable typography-xl-optout" style="width:100%%"
+
     return format(result, i, n)
 +
end
 +
 
 +
local Seasonal = {}
 +
 
 +
-- Template:SeasonalTOC
 +
function Seasonal.toc(frame)
 +
    local args = getArgs{frame = frame:getParent()}
 +
    return
 +
        genToc(args, types, function(r, i, n) return string.format([===[{| class="mw-collapsible mw-collapsed wikitable typography-xl-optout" style="width:100%%"
 
|-
 
|-
!width=20%%|[[Glossary#List_of_Vessels_by_Seiyuu|Seiyuu]] (%s)
+
!width=20%%|Class
 +
!%s (%s)
 +
]===], args.text or "Ship girls", n) .. r .. "|}" end)
 +
        .. "\n" ..
 +
        genToc(args, args.art and artists or seiyuus, function(r, i, n) return string.format([===[{| class="mw-collapsible mw-collapsed wikitable typography-xl-optout" style="width:100%%"
 +
|-
 +
!width=20%%|[[%s]] (%s)
 
!
 
!
]===], i) .. result .. "|}"
+
]===], args.art and "Glossary#List_of_Vessels_by_Artist|Artist" or "Glossary#List_of_Vessels_by_Seiyuu|Seiyuu", i) .. r .. "|}" end)
     return result
+
 
 +
end
 +
 
 +
-- Template:SeasonalQuotesInclude
 +
function Seasonal.include(frame)
 +
 
 +
    local ship_row_template = [=[|align="center" rowspan="${rowspan}"|[[${ship}]]
 +
]=]
 +
 
 +
    local id_string_template = [[id="${ship}"]]
 +
 
 +
    local quote_template = [=[|- ${id_string}
 +
${ship_row}|align="center"|<span class="audio-button click-parent">[[File:${ship}${form} ${season}${line}.ogg|Play]]</span>
 +
|lang="ja"|${ja}
 +
|${en}
 +
|${note}]=]
 +
 
 +
    local args = getArgs{frame = frame:getParent()}
 +
    local season, type = args[1], args[2]
 +
    local only = args.only
 +
    local result = {
 +
        "|-",
 +
        string.format([=[!colspan="5"|From [[Seasonal/%s|%s]]]=], season, season)
 +
    }
 +
    local seasonal_data = requireSeasonModule(season)
 +
    for _, ship in ipairs(seasonal_data.index[type]) do
 +
        if only and Utils.find(args, ship) or not only and not Utils.find(args, ship) then
 +
            local ship_data = seasonal_data.ships[ship]
 +
            local quotes = Utils.ifilter(ship_data, function(quote)
 +
                return not Utils.find(args, string.format("%s/%s", ship, quote.line or ""))
 +
            end)
 +
            for i, quote in ipairs(quotes) do
 +
                local note = args[ship .. "." .. "note"]
 +
                if note and note == "nil" then
 +
                    note = ""
 +
                elseif note and note:sub(-1) == "+" then
 +
                    note = note:sub(1, -2) .. (quote.note or "")
 +
                end
 +
                table.insert(result, format{
 +
                    quote_template,
 +
                    id_string = i > 1 and "" or format{
 +
                        id_string_template,
 +
                        ship = ship,
 +
                    },
 +
                    ship_row = i > 1 and "" or format{
 +
                        ship_row_template,
 +
                        rowspan = #quotes,
 +
                        ship = ship,
 +
                    },
 +
                    ship = quote.ship or ship,
 +
                    form = quote.form or "",
 +
                    season = quote.season or season,
 +
                    line = quote.line and " " .. quote.line or "",
 +
                    ja = quote.ja or "",
 +
                    en = quote.en or "",
 +
                    note = (quote.ship and "''As " .. quote.ship .. "''<br>" or "") .. (quote.line and "''" .. quote.line .. "''<br>" or "") .. (note or quote.note or ""),
 +
                })
 +
            end
 +
        end
 +
    end
 +
     return table.concat(result, "\n")
 +
 
 
end
 
end
  
 
return Seasonal
 
return Seasonal

Latest revision as of 12:41, 12 May 2021

Documentation for this module may be created at Module:Seasonal/doc

local U = require('Module:Core')
local Utils = require('Module:Core')
local format = require('Module:Core').format
local getArgs = require('Module:GetArgs')

local artists = require('Module:Collection/Artists')
local seiyuus = require('Module:Collection/Seiyuus')
local types = require('Module:Collection/ShipsByType')

local function requireSeasonModule(name)
  local success, data = U.requireModule('Data/Season/' .. name)
  if not success then
    success, data = U.requireModule('Seasonal/' .. name)
  end
  if not success then
    data = {index = {}, ships = {}}
  end
  return data
end

function findType(ship)
    for type, data in pairs(types) do
        if data.ships and Utils.find(data.ships, ship) then
            return type
        end
    end
    return "?"
end

function genToc(args, tbl, format)
    local result = ""
    local i = 0
    local n = 0
    for _, k in ipairs(tbl.index) do
        local data = tbl[k]
        local ships = Utils.filter(data.ships, function(ship) return Utils.find(args, ship) end)
        if #ships > 0 then
            i = i + 1
            n = n + #ships
            local ships_str = table.concat(Utils.map(ships, function(ship) return string.format("[[#%s|%s]]", args.art and (tbl.type == "types" and k or findType(ship)) or ship, ship) end), ", ")
            if data.url then
                result = result .. string.format("|-\n|[%s %s]\n|%s\n", data.url, k, ships_str)
            elseif tbl.type == "types" then
                result = result .. string.format("|-\n|[[#%s|%s]] (%s)\n|%s\n", args[k] and (k .. " 2") or k, k, #ships, ships_str)
            else
                result = result .. string.format("|-\n|%s\n|%s\n", k, ships_str)
            end
        end
    end
    return format(result, i, n)
end

local Seasonal = {}

-- Template:SeasonalTOC
function Seasonal.toc(frame)
    local args = getArgs{frame = frame:getParent()}
    return
        genToc(args, types, function(r, i, n) return string.format([===[{| class="mw-collapsible mw-collapsed wikitable typography-xl-optout" style="width:100%%"
|-
!width=20%%|Class
!%s (%s)
]===], args.text or "Ship girls", n) .. r .. "|}" end)
        .. "\n" ..
        genToc(args, args.art and artists or seiyuus, function(r, i, n) return string.format([===[{| class="mw-collapsible mw-collapsed wikitable typography-xl-optout" style="width:100%%"
|-
!width=20%%|[[%s]] (%s)
!
]===], args.art and "Glossary#List_of_Vessels_by_Artist|Artist" or "Glossary#List_of_Vessels_by_Seiyuu|Seiyuu", i) .. r .. "|}" end)

end 

-- Template:SeasonalQuotesInclude
function Seasonal.include(frame)

    local ship_row_template = [=[|align="center" rowspan="${rowspan}"|[[${ship}]]
]=]

    local id_string_template = [[id="${ship}"]]

    local quote_template = [=[|- ${id_string}
${ship_row}|align="center"|<span class="audio-button click-parent">[[File:${ship}${form} ${season}${line}.ogg|Play]]</span>
|lang="ja"|${ja}
|${en}
|${note}]=]

    local args = getArgs{frame = frame:getParent()}
    local season, type = args[1], args[2]
    local only = args.only
    local result = {
        "|-",
        string.format([=[!colspan="5"|From [[Seasonal/%s|%s]]]=], season, season)
    }
    local seasonal_data = requireSeasonModule(season)
    for _, ship in ipairs(seasonal_data.index[type]) do
        if only and Utils.find(args, ship) or not only and not Utils.find(args, ship) then
            local ship_data = seasonal_data.ships[ship]
            local quotes = Utils.ifilter(ship_data, function(quote)
                return not Utils.find(args, string.format("%s/%s", ship, quote.line or ""))
            end)
            for i, quote in ipairs(quotes) do
                local note = args[ship .. "." .. "note"]
                if note and note == "nil" then
                    note = ""
                elseif note and note:sub(-1) == "+" then
                    note = note:sub(1, -2) .. (quote.note or "")
                end
                table.insert(result, format{
                    quote_template,
                    id_string = i > 1 and "" or format{
                        id_string_template,
                        ship = ship,
                    },
                    ship_row = i > 1 and "" or format{
                        ship_row_template,
                        rowspan = #quotes,
                        ship = ship,
                    },
                    ship = quote.ship or ship,
                    form = quote.form or "",
                    season = quote.season or season,
                    line = quote.line and " " .. quote.line or "",
                    ja = quote.ja or "",
                    en = quote.en or "",
                    note = (quote.ship and "''As " .. quote.ship .. "''<br>" or "") .. (quote.line and "''" .. quote.line .. "''<br>" or "") .. (note or quote.note or ""),
                })
            end
        end
    end
    return table.concat(result, "\n")

end

return Seasonal