FANDOM


--WARFRAME Grineer and Corpus Script Convertor
--http://warframe.wikia.com/wiki/Template:FactionScript
 
local p = {}
 
local CharData = mw.loadData( 'Module:FactionScript/data' )
 
function p.gen_script( faction, human_words, size )
    local output_string = {}
    local human_words = string.lower(human_words)
    local human_length = string.len(human_words)
    local char_data
    local human_char
    local replacement
 
    if faction == 'corpus' then
        char_data = CharData['CorpusChar']
        if (size == '') or (size == nil) then size = '14' end
        for i=1, human_length do
            human_char = human_words:sub(i,i)
            replacement = char_data[human_char]
            if replacement then
                table.insert(output_string, get_img(replacement, size))
            else
 
            -- adding spaces between words
                table.insert(output_string,'   ')
            end
        end
    else
        char_data = CharData['GrineerChar']
        if (size == '') or (size == nil) then size = '16' end
        for i=1, human_length do
            human_char = human_words:sub(i,i)
            -- no letter "Q" in Grineer language, replace with "K" + "Q" characters
            if human_char == 'q' then
                table.insert(output_string,get_img(char_data['k'], size)..get_img(char_data['w'], size))
 
            -- no letter "X" in Grineer language, replace with "K" + "S" characters
            elseif human_char == 'x' then
                table.insert(output_string,get_img(char_data['k'], size)..get_img(char_data['s'], size))
            else
                replacement = char_data[human_char]
                if replacement then
                    table.insert(output_string, get_img(replacement, size))
 
                -- adding spaces between words
                else
                    table.insert(output_string,'   ')
                end
            end
        end
    end
    return create_span(output_string, size)
end
 
 
function get_img(replacement, size)
    return '[[File:'..replacement..'|x'..size..'px|link=]]'
end
 
function create_span(output_string, size)
    local span = mw.html.create( 'span' )
    span:css( 'font-size', size..'px' )
        :wikitext( table.concat(output_string) )
    return tostring(span)
end
 
 
function p.corpus( frame )
    local string_input = frame.args[1]
    local num_input = frame.args[2]
    return p.gen_script('corpus', string_input, num_input)
end
 
function p.grineer( frame )
    local string_input = frame.args[1]
    local num_input = frame.args[2]
    return p.gen_script('grineer', string_input, num_input)
end
 
function p._tenno (humanwords, size)
	local humanwords = string.lower(humanwords)
	if (size == nil or size == '') then size='16' end
	local tennobet_list = {}    --list of tennobet pics of the chars
	local phonetic_list = {}    --list of phonetic types (vowel/consonant) of the chars
	local output_list = {}      --final output list
 
	-- converting "normal human spelling" to English phonetic spelling
	local i=string.len(humanwords)
 
	while i > 0 do
    	local this_char = humanwords:sub(i,i)
    	local prev_char = humanwords:sub(i-1,i-1)
		if this_char == "h" then
			if (prev_char == "t" or
				prev_char == "d" or
				prev_char == "s" or
				prev_char == "z" or
				prev_char == "c" or
				prev_char == "k" or
				prev_char == "i" or
				prev_char == "e" or
				prev_char == "u") then
				table.insert(tennobet_list,CharData["TennoChar"][prev_char.."h"][1])
				table.insert(phonetic_list,CharData["TennoChar"][prev_char.."h"][2])
				i=i-2
			else
				table.insert(tennobet_list,CharData["TennoChar"]["h"][1])
				table.insert(phonetic_list,"c")
				i=i-1
			end
		elseif this_char == "g" then
			if prev_char == "n" then
				table.insert(tennobet_list,CharData["TennoChar"]["ng"][1])
				table.insert(phonetic_list,"c")
				i=i-2
			else
				table.insert(tennobet_list,CharData["TennoChar"]["g"][1])
				table.insert(phonetic_list,"c")
				i=i-1
			end
		elseif  this_char == "e" then
			if humanwords:sub(i-2,i-2)..prev_char == "ay" then
				table.insert(tennobet_list,CharData["TennoChar"]["aye"][1])
				i=i-3
			elseif (prev_char == "e" or
					prev_char == "a") then
				table.insert(tennobet_list,CharData["TennoChar"][prev_char.."e"][1])
				i=i-2
			else 
				table.insert(tennobet_list,CharData["TennoChar"]["e"][1])
				i=i-1
			end
			table.insert(phonetic_list,"v")
		elseif this_char == ("w") then
			if (prev_char == "a" or
				prev_char == "o") then
				table.insert(tennobet_list,CharData["TennoChar"][prev_char.."w"][1])
				i=i-2
			else
				table.insert(tennobet_list,CharData["TennoChar"]["oo"][1])
				i=i-1
			end
				table.insert(phonetic_list,"v")
		elseif this_char == ("o") then
			if prev_char == "o" then
				table.insert(tennobet_list,CharData["TennoChar"]["oo"][1])
				i=i-2
			else 
				table.insert(tennobet_list,CharData["TennoChar"]["o"][1])
				i=i-1
			end
				table.insert(phonetic_list,"v")
		elseif CharData["TennoChar"][this_char] == " " then
				table.insert(tennobet_list,CharData["TennoChar"]["."][1])
				table.insert(phonetic_list,"space")
			    i=i-1
		elseif CharData["TennoChar"][this_char] ~= nil then
				table.insert(tennobet_list,CharData["TennoChar"][this_char][1])
				table.insert(phonetic_list,CharData["TennoChar"][this_char][2])
			    i=i-1
		else
				table.insert(tennobet_list," ")
				table.insert(phonetic_list,"unknown")
			    i=i-1
		end
    end
 
    -- building resultant sequence of Tennobet character images 
    local j=#phonetic_list      --size of phoetic_list
 
	while j > 0 do
	    if phonetic_list[j] == "c" then         --consonant
            local stack_consonant = mw.html.create('div')
            :attr( 'class', 'tennoscript_C' )
            :wikitext("[[File:"..tennobet_list[j].."|x"..size.."px|link=]]"):done()
	    	table.insert(output_list,tostring(stack_consonant))
		    j=j-1
		elseif phonetic_list[j] == "v" then     --vowel
		    local stack_vowel = mw.html.create('div')
            :attr( 'class', 'tennoscript_V' )
            repeat
                stack_vowel:wikitext("[[File:"..tennobet_list[j].."|x"..size.."px|link=]]"):done()
                j=j-1
            until phonetic_list[j] ~= "v"
		    table.insert(output_list,tostring(stack_vowel))
		elseif phonetic_list[j] == "s" then     --signs/numbers
            local stack_symbol = mw.html.create('div')
            :attr( 'class', 'tennoscript_S' )
            :wikitext("[[File:"..tennobet_list[j].."|x"..size.."px|link=]]"):done()
		    table.insert(output_list,tostring(stack_symbol))
		    j=j-1
		elseif phonetic_list[j] == "p" then    --periods/commas
            local stack_ep = mw.html.create('div'):done()
            if (phonetic_list[j+1] == "c" and (phonetic_list[j-1] == nil or phonetic_list[j-1] == "space")) then 
                stack_ep:attr( 'class', 'tennoscript_EPeriod' ):done()
            elseif (phonetic_list[j-1] == "c" and (phonetic_list[j+1] == nil or phonetic_list[j+1] == "space")) then
                stack_ep:attr( 'class', 'tennoscript_SPeriod' ):done()
            else
                stack_ep:attr( 'class', 'tennoscript_S' ):done()
            end
            stack_ep:wikitext("[[File:"..tennobet_list[j].."|x"..size.."px|link=]]"):done()
		    table.insert(output_list,tostring(stack_ep))
		    j=j-1
		elseif phonetic_list[j] == "r" then     --r
            local stack_ep = mw.html.create('div')
            :attr( 'class', 'tennoscript_C' )
            :css('text-align','center')
            :wikitext("[[File:"..tennobet_list[j].."|x"..size.."px|link=]]"):done()
		    table.insert(output_list,tostring(stack_ep))
		    j=j-1
		elseif phonetic_list[j] == "space" then
            local stack_space = mw.html.create('div')
            :attr( 'class', 'tennoscript_S' )
            :css('visibility','hidden')
            :wikitext("[[File:"..tennobet_list[j].."|x"..size.."px|link=]]"):done()
		    table.insert(output_list,tostring(stack_space))
		    j=j-1
        else 
            local stack_space = mw.html.create('div')
            :attr( 'class', 'tennoscript_S' )
            :wikitext(" "):done()
		    table.insert(output_list,tostring(stack_space))
		    j=j-1
	    end
	end
	return table.concat(output_list)
end
 
function p.tenno ( frame )
    local string_input = frame.args[1]
    local num_input = frame.args[2]
    return p._tenno(string_input,num_input)
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.