Module:Tscript

From Puella Magi Wiki
Jump to navigation Jump to search
Module Documentation    [edit]

Supplementary functions for Template:Story Transcript.

Functions

Function name Associated template Parameters Description
icon Template:Story Transcript/Dialogue
  • 1 - character's ID
  • 2 - image filename
Returns code to embed an icon for the specified character, either [[File:{value of 2}]] or [[File:Story_Icon_{value of 1}.png]]. If both arguments are blank, returns an empty string.
ch Template:Story Transcript/Dialogue
  • 1 - character's English name
  • 2 - character's Japanese name
  • 3 - name of the character's article
Returns code for identifying and potentially linking a character's name.
v Template:Story Transcript/Dialogue, Template:Story Transcript/Narration
  • 1 - sound file name without .ogg
  • 2 - sound file name without .ogg
  • 3 - sound file name without .ogg
  • 4 - sound file name without .ogg
Returns code for embedding a character's voice lines.

If no value is specified, returns an empty string.

If values are specified, for every (max 4) parameter before an unspecified parameter are output so that every valid parameter is turned into [[File:{valid parameter}.ogg]].[Explanation 1]

d Template:Story Transcript/Dialogue
  • 1 - dialogue line in English
  • 2 - dialogue line in Japanese
Returns code for embedding the text of a character's dialogue. If 1 is unspecified, returns an empty string. If 1 is specified and 2 is unspecified, returns 1 in a single table column. If both 1 and 2 are specified, returns both in separate table columns.
cs Template:Story Transcript/Narration, Template:Story Transcript/Illustration, Template:Story Transcript/Music, Template:Story Transcript/Video
  • 1 - any value
If 1 is unspecified, returns colspan="2".

If 1 is specified, returns colspan="3".

Explanation

  1. See the following table
1 2 3 4 Output
(empty string)
my_file [[File:my_file.ogg]]
file1 file2 file3 file4 [[File:file1.ogg]][[File:file2.ogg]][[File:file3.ogg]][[File:file4.ogg]]
file1 file4 [[File:file1.ogg]]

-- A set of modules to deal with transcripts. See Template:Story_Transcript .

local _ = {}

function iconAlt (char_id, img_override, gametitle)
    local result = ""
    if img_override ~= nil and img_override ~= "" then
        result = img_override
    elseif char_id ~= nil and char_id ~= "" then
        result = "Story Icon " .. char_id .. ".png"
        -- this will have to be fixed in the python script, for now I have no magireco transcripts to worry about so I'm leaving "empty" as an option in
        if gametitle == "Exedra" or gametitle == nil or gametitle == "" then
        	result = "Exedra " .. result
        elseif gametitle == "MagiReco" then
        	result = "MagiReco " .. result
        end
    end

    if result ~= "" then
        result = "[[File:" .. result .. "|80px]]"
    end

    return result
end

function chAlt (charname_en, charname_jp, charlink_initial)
	local charlink_final = ""
    local result = charname_en
    local category = ""
    --also prepare nonmagireco link characters one day
    local categorizable_chars = mw.loadJsonData [[Module:Tscript/categorizable_chars.json]]
	local nonexedra_link_characters = mw.loadJsonData [[Module:Tscript/nonexedra_link_characters.json]]
    
    if charname_jp ~= nil and charname_jp ~= "" then
        result = charname_en .. " / " .. charname_jp
    end
    

    for i, value in ipairs(categorizable_chars) do
        if value == charname_en then
            category = "[[Category:" .. charname_en .. " in Story]]"
			if charlink_initial == nil or charlink_initial == "" then
                charlink_final = charname_en .. " in Magia Exedra"
            end
            break
		end
    end
    if (charlink_initial == nil or charlink_initial == "") and nonexedra_link_characters[charname_en] ~= nil then
        charlink_final = nonexedra_link_characters[charname_en]     
	elseif charlink_initial ~= nil and charlink_initial ~= "" then
        charlink_final = charlink_initial
    end
    if charlink_final ~= nil and charlink_final ~= "" then
        result = "[[" .. charlink_final .. "|" .. result .. "]]"
    end
    if result == nil then
        result = ""
    end
    return result .. category


end

function vAlt (v1,v2,v3,v4)
    local r = ""
    
    if v1 ~= nil and v1 ~= "" then
        r = "[[File:" .. v1 .. ".ogg]]"
        if v2 ~= nil and v2 ~= "" then
            r = r .. "[[File:" .. v2 .. ".ogg]]"
            if v3 ~= nil and v3 ~= "" then
                r = r .. "[[File:" .. v3 .. ".ogg]]"
                if v4 ~= nil and v4 ~= "" then
                    r = r .. "[[File:" .. v4 .. ".ogg]]"
                end
            end
        end
    end
return r
end


-- icon - A function to deal with character icon
_.icon = function(frame)
    local char_id = frame.args[1]
    local img_override = frame.args[2]
    local gametitle = frame.args[3]
    local result = ""

    if img_override ~= nil and img_override ~= "" then
        result = img_override
    elseif char_id ~= nil and char_id ~= "" then
        result = "Story Icon " .. char_id .. ".png"
        -- this will have to be fixed in the python script, for now I have no magireco transcripts to worry about so I'm leaving "empty" as an option in
        if gametitle == "Exedra" or gametitle == nil or gametitle == "" then
        	result = "Exedra " .. result
        elseif gametitle == "MagiReco" then
        	result = "MagiReco " .. result
        end
    end

    if result ~= "" then
        result = "[[File:" .. result .. "|80px]]"
    end

    return result
end

-- ch - A function to deal with character naming, linking, categorizing.
_.ch = function(frame)
    -- first argument is also the en charname
    local charname_en = frame.args[1]
    local charname_jp = frame.args[2]
    local charlink_initial = frame.args[3]
	local charlink_final = ""
    local result = charname_en
    local category = ""
    --also prepare nonmagireco link characters one day
    local categorizable_chars = mw.loadJsonData [[Module:Tscript/categorizable_chars.json]]
	local nonexedra_link_characters = mw.loadJsonData [[Module:Tscript/nonexedra_link_characters.json]]
    
    if charname_jp ~= nil and charname_jp ~= "" then
        result = charname_en .. " / " .. charname_jp
    end
    

    for i, value in ipairs(categorizable_chars) do
        if value == charname_en then
            category = "[[Category:" .. charname_en .. " in Story]]"
			if charlink_initial == nil or charlink_initial == "" then
                charlink_final = charname_en .. " in Magia Exedra"
            end
            break
		end
    end
    if (charlink_initial == nil or charlink_initial == "") and nonexedra_link_characters[charname_en] ~= nil then
        charlink_final = nonexedra_link_characters[charname_en]     
	elseif charlink_initial ~= nil and charlink_initial ~= "" then
        charlink_final = charlink_initial
    end
    if charlink_final ~= nil and charlink_final ~= "" then
        result = "[[" .. charlink_final .. "|" .. result .. "]]"
    end
    if result == nil then
        result = ""
    end
    return result .. category
end

-- v - a function for dealing with voicelines.
_.v = function(frame)
    local v1 = frame.args[1]
    local v2 = frame.args[2]
    local v3 = frame.args[3]
    local v4 = frame.args[4]
    local r = ""
    
    if v1 ~= nil and v1 ~= "" then
        r = "[[File:" .. v1 .. ".ogg]]"
        if v2 ~= nil and v2 ~= "" then
            r = r .. "[[File:" .. v2 .. ".ogg]]"
            if v3 ~= nil and v3 ~= "" then
                r = r .. "[[File:" .. v3 .. ".ogg]]"
                if v4 ~= nil and v4 ~= "" then
                    r = r .. "[[File:" .. v4 .. ".ogg]]"
                end
            end
        end
    end
return r
end

-- d - a function for dialogue.
_.d = function(frame)
    local en = frame.args[1]
    local jp = frame.args[2]
    local result = ""

    if en == nil then
        en = ""
    end
    if jp ~= nil and jp ~= "" then
        result = '<td style="width: 40%;">' .. en .. '</td><td style="width: 40%;">' .. jp .. '</td>'
    else
        result = '<td style="width: 80%;">' .. en .. '</td>'
    end

    return result
end

-- n - a function for narration. should be almost identical to d
_.n = function(frame)
	local en = frame.args[1]
	local jp = frame.args[2]
	local result = ""
	    if en == nil then
        en = ""
    end
    if jp ~= nil and jp ~= "" then
        result = '<td style="width: 40%;"><i style="opacity:80%">' .. en .. '</i></td><td style="width: 40%;"><i style="opacity:80%">' .. jp .. '</i></td>'
    else
        result = '<td style="width: 80%;"><i style="opacity:80%">' .. en .. '</i></td>'
    end

    return result
end

-- cs - a function for proper colspan for Music and Illustration, depending on whether the transcript is a legacy English-only one, or a bilingual one.
_.cs = function(frame)
    local a = frame.args[1]
    local result = 'colspan=2'
    if a ~= nil and a ~= "" then
        result = 'colspan=3'
    end
    return result
end

-- nm - a function for the side nameplate in Dialogue and Narration 
_.nm = function(frame)
    local name_en = frame.args[1]
    local name_jp = frame.args[2]
    local charlink = frame.args[3]
    local char_id = frame.args[4]
    local img_override = frame.args[5]
    local gametitle = frame.args[6]
    local narration = frame.args[7]
    local voicefile1 = frame.args[8]
    local voicefile2 = frame.args[9]
    local voicefile3 = frame.args[10]
    local voicefile4 = frame.args[11]
    local result = ""
    local iconimg = iconAlt(char_id, img_override, gametitle)

    if narration ~= nil and narration ~= "" then
        result = result .. "<div style=\"width:80px;\" class=\"littlecontainer\">(Narration)</div>"
    elseif iconimg ~= "" then
        result = result .. "<div style=\"width:80px;\" class=\"littlecontainer\">" .. iconimg .. "</div>"
    end
    
    if (name_en ~= nil and name_en ~= "") or (name_jp ~= nil and name_jp ~= "") then
        result = result .. "<div class=\"littlecontainer\">" .. chAlt(name_en, name_jp, charlink) .. "</div>"
    end

    if result ~= "" then
       result = "<center><div class=\"bigcontainer\">" .. result .. "</div></center>" 
    end

    if voicefile1 ~= nil and voicefile1 ~= "" then
        result = result .. "<div>" .. vAlt(voicefile1, voicefile2, voicefile3, voicefile4) .. "</div>"
    end
    
    result = "<th style=\"width: 20%\">" .. result .. "</th>"
    return result
end

return _