• 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:Quotes"

From Kancolle Wiki
Jump to navigation Jump to search
m
(Support Kai+ lines)
Line 73: Line 73:
 
local complete = true
 
local complete = true
  
function insertRow(result, remodel, args, line)
+
function insertRow(result, remodel, args, line, count)
 
     local remodel_string = remodel and "/" .. remodel or ""
 
     local remodel_string = remodel and "/" .. remodel or ""
 
     local ja, en, note = args[line.name .. remodel_string], args[line.name .. remodel_string .. "/En"], args[line.name .. remodel_string .. "/Note"]
 
     local ja, en, note = args[line.name .. remodel_string], args[line.name .. remodel_string .. "/En"], args[line.name .. remodel_string .. "/Note"]
 
     local jaEn = args[line.name .. remodel_string .. "/Both"]
 
     local jaEn = args[line.name .. remodel_string .. "/Both"]
 
     local link = args[line.name .. remodel_string .. "/Link"]
 
     local link = args[line.name .. remodel_string .. "/Link"]
     if not remodel and not line.extra or jaEn or ja or en or note then
+
     if (not remodel and not line.extra or jaEn or ja or en or note) and ja ~= "hide" then
         local line_name = remodel or line.name
+
         local line_name = count == 0 and (remodel and line.name .. " (" .. remodel .. ")" or line.name) or remodel or line.name
 
         local ja_style = not jaEn and (not ja or ja == "" or ja == "?") and templates.incomplete_style
 
         local ja_style = not jaEn and (not ja or ja == "" or ja == "?") and templates.incomplete_style
 
         local en_style = not jaEn and (not en or en == "" or en == "?") and templates.incomplete_style
 
         local en_style = not jaEn and (not en or en == "" or en == "?") and templates.incomplete_style
Line 88: Line 88:
 
         table.insert(result, format{
 
         table.insert(result, format{
 
             templates.row,
 
             templates.row,
             style = remodel and templates.remodel_row_style or "",
+
             style = remodel and count > 0 and templates.remodel_row_style or "",
 
             audio_button = args.no_audio and "" or format{
 
             audio_button = args.no_audio and "" or format{
 
                 templates.audio_button,
 
                 templates.audio_button,
Line 117: Line 117:
 
     table.insert(result, format{templates.header, note_style = args.note_style or ""})
 
     table.insert(result, format{templates.header, note_style = args.note_style or ""})
 
     for _, line in pairs(lines) do
 
     for _, line in pairs(lines) do
         local added = insertRow(result, nil, args, line)
+
         local added = insertRow(result, nil, args, line, 0)
         added = added + insertRow(result, "Kai", args, line)
+
         added = added + insertRow(result, "Kai", args, line, added)
         added = added + insertRow(result, "Kai Ni", args, line)
+
         added = added + insertRow(result, "Kai Ni", args, line, added)
 
         if line.note and added > 0 then
 
         if line.note and added > 0 then
 
             table.insert(result, format{templates.note, note = line.note})
 
             table.insert(result, format{templates.note, note = line.note})

Revision as of 00:07, 3 June 2016

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

local format = require('Module:StringInterpolation').format
local getArgs = require('Module:GetArgs')

function format_category(name)
    return "[[Category:" .. name .. "]]"
end

local templates = {
    header = [[{| class="wikitable typography-xl-optout" style="width:100%;"
! style="width:10%;" | Event
!Japanese
!English
! style="${note_style}" | Note]],
    footer = "|}",
    audio_file = "${ship}${suffix}-${line}.ogg",
    audio_button = [=[<span class="audio_button">[[Media:${audio_file}|Play]]</span>]=],
    line_link = "[${link} ${line}]",
    remodel_row_style = [[style="border-left: 15px solid #aaa;"]],
    spoiler = [[<span style="background-color:#3a3a3a">${text}</span>]],
    incomplete_style = "background:#fee;",
    incomplete_category = format_category("Ship pages with incomplete quotes"),
    row = [=[|- ${style}
| nowrap="nowrap" |${audio_button} ${line}
| colspan="${ja_colspan}" style="${ja_style}" |<span lang="ja" style="font-family: sans-serif;">${ja}</span>
${en_cell}|${note}]=],
    note = [[|-
| colspan="5" | ⇧ ${note}]],
}

local lines = {
    { name = "Introduction" },
    { name = "Library" },
    { name = "Secretary 1" },
    { name = "Secretary 2" },
    { name = "Secretary 3" },
    { name = "Idle" },
    { name = "Secretary Married", spoiler = true },
    { name = "Wedding", spoiler = true },
    { name = "Looking At Scores" },
    { name = "Joining A Fleet" },
    { name = "Equipment 1" },
    { name = "Equipment 2" },
    { name = "Equipment 3", note = "shared with expedition selection, resource collection, instant repair and development" },
    { name = "Supply" },
    { name = "Modernization", extra = true, note = "shared with remodeling line (modernization/remodeling lines are only present in [[KanColle Kai]])" },
    { name = "Docking Minor" },
    { name = "Docking Major" },
    { name = "Docking Complete", extra = true },
    { name = "Construction" },
    { name = "Returning From Sortie" },
    { name = "Starting A Sortie" },
    { name = "Battle Start" },
    { name = "Attack", note = "shared with [[Combat#Artillery_Spotting|day]]/[[Combat#Night_Special_Attack_Modifier|night]] special attacks, [[Expedition#Support_expedition|support expedition team]] arrival" },
    { name = "Night Battle" },
    { name = "Night Attack" },
    { name = "MVP" },
    { name = "Minor Damage 1" },
    { name = "Minor Damage 2" },
    { name = "Major Damage" },
    { name = "Sunk", spoiler = true },
}

local audio_suffixes = {
    ["Kai"] = "Kai",
    ["Kai Ni"] = "Kai2",
}

function format_text(text, line)
    return text and line.spoiler and format{templates.spoiler, text = text} or text or ""
end

-- Global variable, potentially altered by insertRow, checked by Quotes.ShipQuotes.
local complete = true

function insertRow(result, remodel, args, line, count)
    local remodel_string = remodel and "/" .. remodel or ""
    local ja, en, note = args[line.name .. remodel_string], args[line.name .. remodel_string .. "/En"], args[line.name .. remodel_string .. "/Note"]
    local jaEn = args[line.name .. remodel_string .. "/Both"]
    local link = args[line.name .. remodel_string .. "/Link"]
    if (not remodel and not line.extra or jaEn or ja or en or note) and ja ~= "hide" then
        local line_name = count == 0 and (remodel and line.name .. " (" .. remodel .. ")" or line.name) or remodel or line.name
        local ja_style = not jaEn and (not ja or ja == "" or ja == "?") and templates.incomplete_style
        local en_style = not jaEn and (not en or en == "" or en == "?") and templates.incomplete_style
        local jaEn_style = jaEn and (jaEn == "" or jaEn == "?") and templates.incomplete_style
        if ja_style or en_style or jaEn_style then
            complete = false
        end
        table.insert(result, format{
            templates.row,
            style = remodel and count > 0 and templates.remodel_row_style or "",
            audio_button = args.no_audio and "" or format{
                templates.audio_button,
                audio_file = format{
                    templates.audio_file,
                    ship = args.ship,
                    suffix = audio_suffixes[remodel] or "",
                    line = line.name,
                },
            },
            line = link and format{templates.line_link, link = link, line = line_name} or line_name,
            ja = format_text(jaEn or ja, line),
            ja_colspan = jaEn and "2" or "1",
            ja_style = ja_style or jaEn_style or "",
            en_cell = jaEn and "" or '| style="' .. (en_style or "") .. '"|' .. format_text(en, line) .. "\n",
            note = format_text(note, line),
        })
        return 1
    end
    return 0
end

local Quotes = {}

function Quotes.ShipQuotes(frame, args)
    args = args or getArgs{frame = frame:getParent()}
    local result = {}
    table.insert(result, format{templates.header, note_style = args.note_style or ""})
    for _, line in pairs(lines) do
        local added = insertRow(result, nil, args, line, 0)
        added = added + insertRow(result, "Kai", args, line, added)
        added = added + insertRow(result, "Kai Ni", args, line, added)
        if line.note and added > 0 then
            table.insert(result, format{templates.note, note = line.note})
        end
    end
    table.insert(result, templates.footer)
    if not complete then
        table.insert(result, templates.incomplete_category)
    end
    return table.concat(result, "\n")
end

-- Quotes.t = Quotes.ShipQuotes(nil, {ship = "Ayanami"})

return Quotes