• 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
Line 13: Line 13:
 
     line_link = "[${link} ${line}]",
 
     line_link = "[${link} ${line}]",
 
     first_row_style = [[style=""]],
 
     first_row_style = [[style=""]],
 +
    spoiler = [[<span style="background-color:#3A3A3A">${text}</span>]],
 
     row = [=[|- ${style}
 
     row = [=[|- ${style}
 
| nowrap="nowrap" |${audio_button}${line}
 
| nowrap="nowrap" |${audio_button}${line}
Line 34: Line 35:
 
     ["Modernization"] = "Modernization is shared with remodeling line.",
 
     ["Modernization"] = "Modernization is shared with remodeling line.",
 
}
 
}
 +
 +
local spoilers = {
 +
    "Secretary Married", "Wedding", "Sunk",
 +
}
 +
 +
function format_text(text, line)
 +
    return text and spoilers[line] and format{templates.spoiler, text = text} or text or ""
 +
end
  
 
function insertRow(result, remodel, args, line, extra)
 
function insertRow(result, remodel, args, line, extra)
Line 54: Line 63:
 
             },
 
             },
 
             line = link and format{templates.line_link, link = link, line = line} or line,
 
             line = link and format{templates.line_link, link = link, line = line} or line,
             ja = jaEn or ja or "",
+
             ja = format_text(jaEn or ja),
 
             ja_colspan = jaEn and "2" or "1",
 
             ja_colspan = jaEn and "2" or "1",
             en_cell = jaEn and "" or "|" .. (en or "") .. "\n",
+
             en_cell = jaEn and "" or "|" .. format_text(en) .. "\n",
             note = note or "",
+
             note = format_text(note),
 
         })
 
         })
 
         return 1
 
         return 1

Revision as of 19:18, 23 February 2016

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

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

local templates = {
    header = [[{| class="wikitable typography-xl-optout" style="width:100%;"
! style="width:10%;" | Event
!Japanese
!English
!Note]],
    footer = "|}",
    audio_file = "${ship}${suffix}-${line}.ogg",
    audio_button = [=[<span class="audio_button">[[Media:${audio_file}|Play]]</span>]=],
    line_link = "[${link} ${line}]",
    first_row_style = [[style=""]],
    spoiler = [[<span style="background-color:#3A3A3A">${text}</span>]],
    row = [=[|- ${style}
| nowrap="nowrap" |${audio_button}${line}
| colspan="${ja_colspan}" | <span lang="ja" style="font-family: sans-serif;">${ja}</span>
${en_cell}| ${note}]=],
    note = [[|-
| colspan="5" |${note}]],
}

local lines = {
    "Introduction", "Library", "Secretary 1", "Secretary 2", "Secretary 3", "Idle", "Secretary Married", "Wedding",
    "Looking At Scores", "Joining A Fleet", "Equipment 1", "Equipment 2", "Equipment 3", "Supply", {extra = "Modernization"},
    "Docking Minor", "Docking Major", "Docking Complete", "Construction",
    "Returning From Sortie", "Starting A Sortie", "Battle Start", "Attack", "Night Battle", "Night Attack", "MVP",
    "Minor Damage 1", "Minor Damage 2", "Major Damage", "Sunk",
}

local notes = {
    ["Equipment 3"] = "Equipment 3 is shared with expedition selection, resource collection, instant repair and development.",
    ["Night Attack"] = "Night attack is shared with [[Combat#Artillery_Spotting|Artillery Spotting]], [[Combat#Night_Special_Attack_Modifier|Night Special Attack]] and [[Expedition#Support_expedition|support expedition team]] arrival.",
    ["Modernization"] = "Modernization is shared with remodeling line.",
}

local spoilers = {
    "Secretary Married", "Wedding", "Sunk",
}

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

function insertRow(result, remodel, args, line, extra)
    local remodel_string = remodel == 0 and "" or "/" .. remodel
    local ja, en, note = args[line .. remodel_string], args[line .. remodel_string .. "/En"], args[line .. remodel_string .. "/Note"]
    local jaEn = args[line .. remodel_string .. "/Both"]
    local link = args[line .. remodel_string .. "/Link"]
    if remodel == 0 and not extra or jaEn or ja or en or note then
        table.insert(result, format{
            templates.row,
            style = remodel == 0 and templates.first_row_style or "",
            audio_button = args.no_audio and "" or format{
                templates.audio_button,
                audio_file = format{
                    templates.audio_file,
                    ship = args.ship,
                    suffix = ({[0] = "", [1] = "Kai", [2] = "Kai2"})[remodel],
                    line = line,
                },
            },
            line = link and format{templates.line_link, link = link, line = line} or line,
            ja = format_text(jaEn or ja),
            ja_colspan = jaEn and "2" or "1",
            en_cell = jaEn and "" or "|" .. format_text(en) .. "\n",
            note = format_text(note),
        })
        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, templates.header)
    for _, line in pairs(lines) do
        local extra, line = line.extra and true or false, line.extra or line
        local added = insertRow(result, 0, args, line, extra)
        added = added + insertRow(result, 1, args, line, extra)
        added = added + insertRow(result, 2, args, line, extra)
        local note = notes[line]
        if note and added > 0 then
            table.insert(result, format{templates.note, note = note})
        end
    end
    table.insert(result, templates.footer)
    return table.concat(result, "\n")
end

return Quotes