Module:Quotes

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

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

local templates = { header = Event !Japanese !English ! style="${note_style}" | Note, footer = "|}", audio_file = "${ship}${suffix}-${line}.ogg", audio_button = [=[ [[Media:${audio_file}|Play]] ]=], line_link = "[${link} ${line}]", remodel_row_style = style="border-left: 15px solid , spoiler = ${text} , incomplete_style = "background:#fee;", incomplete_category = format_category("Ship pages with incomplete quotes"), row = [=[|- ${style} class="shipquote" data-shipquote-id="${id}" data-shipquote-form="${form}" ${en_cell}|${note}]=], note = [[|- }
 * nowrap="nowrap" |${audio_button} ${line}
 * colspan="${ja_colspan}" style="${ja_style}" class="shipquote-ja" | ${ja}
 * colspan="5" |　⇧ ${note}]],

local lines = { { name = "Introduction", id = 1 }, { name = "Library", id = 25 }, { name = "Secretary 1", id = 2 }, { name = "Secretary 2", id = 3 }, { name = "Secretary 3", id = 4 }, { name = "Idle", extra = true, id = 29 }, { name = "Secretary Married", spoiler = true, id = 28 }, { name = "Wedding", spoiler = true, id = 24 }, { name = "Looking At Scores", id = 8 }, { name = "Joining A Fleet", id = 13 }, { name = "Equipment 1", id = 9 }, { name = "Equipment 2", id = 10 }, { name = "Equipment 3", note = "shared with expedition selection, resource collection, instant repair and development", id = 26 }, { name = "Supply", id = 27 }, { name = "Docking Minor", id = 11 }, { name = "Docking Major", id = 12 }, { name = "Docking Complete", extra = true, id = 6 }, { name = "Construction", id = 5 }, { name = "Returning From Sortie", id = 7 }, { name = "Starting A Sortie", id = 14 }, { name = "Battle Start", id = 15 }, { name = "Air Battle", extra = true, id = 17 }, { name = "Attack", note = "shared with day/night special attacks, support expedition team arrival", id = 16 }, { name = "Night Battle", id = 18 }, { name = "Night Attack", extra = true, id = 17 }, { name = "MVP", id = 23 }, { name = "Minor Damage 1", id = 19 }, { name = "Minor Damage 2", id = 20 }, { name = "Major Damage", id = 21 }, { name = "Sunk", spoiler = true, id = 22 }, }

local audio_suffixes = { ["Kai"] = "Kai", ["Kai Ni"] = "Kai2", ["Kai Ni A"] = "Kai2A", ["Kai Ni B"] = "Kai2B", ["Kai Ni C"] = "Kai2C", ["Kai Ni D"] = "Kai2D", ["Due"] = "Due", ["Carrier Kai Ni"] = "CarrierKai2", ["Taiyou"] = "Taiyou", ["Taiyou Kai"] = "TaiyouKai", ["Taiyou Kai Ni"] = "TaiyouKai2", }

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

-- function isCarrier(base_ship_name, remodel)   local ship = Ship(base_ship_name .. "/" .. (remodel or ""))    return ship:type == 11 or ship:type == 16 or ship:type == 18 end --

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

function insertRow(result, remodel, args, line, count, use_suffix)

local ship = args.ship:gsub(" ", "") local suffix = audio_suffixes[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 jaEn = args[line.name .. remodel_string .. "/Both"] local link = args[line.name .. remodel_string .. "/Link"]

local same = args[line.name .. remodel_string .. "/Same"] if same then ja = ja or args[same .. remodel_string] en = en or args[same .. remodel_string .. "/En"] note = note or args[same .. remodel_string .. "/Note"] jaEn = jaEn or args[same .. remodel_string .. "/Both"] link = link or args[same .. remodel_string .. "/Link"] end

local is_empty_pre_kai_line = not remodel and not ja and not en and not jaEn and (args[line.name .. "/Kai"] or args[line.name .. "/Kai/En"] or args[line.name .. "/Kai/Both"])

--   if line.name == "Night Attack" then         line.extra = isCarrier(args.ship, remodel)    elseif line.name == "Air Battle" then         line.extra = not isCarrier(args.ship, remodel)    end    --

if (not remodel and not line.extra or jaEn or ja or en or note) and not is_empty_pre_kai_line 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 = use_suffix and suffix or ship,                    suffix = use_suffix and "" or suffix,                    line = same or line.name,                },            },            id = line.id,            form = remodel or "Base",            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 "") .. '" class="shipquote-en" |' .. 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 Utils.getTemplateArgs(frame) args.explicit.ship = args.implicit.pagename or args.explicit.ship or "" local result = {} table.insert(result, format{templates.header, note_style = args.explicit.note_style or ""}) for _, line in pairs(lines) do       local added = insertRow(result, nil, args.explicit, line, 0) added = added + insertRow(result, "Kai", args.explicit, line, added) added = added + insertRow(result, "Kai Ni", args.explicit, line, added) added = added + insertRow(result, "Carrier Kai Ni", args.explicit, line, added) added = added + insertRow(result, "Due", args.explicit, line, added) added = added + insertRow(result, "Taiyou", args.explicit, line, added, true) added = added + insertRow(result, "Taiyou Kai", args.explicit, line, added, true) added = added + insertRow(result, "Taiyou Kai Ni", args.explicit, line, added, true) 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, {explicit = {}, implicit = {pagename = "Ayanami"}})

return Quotes