FANDOM


local p = {}
local h = require("Module:HF")
local getArgs = require('Dev:Arguments').getArgs
local list_of_realities = mw.loadData( 'Module:Disambiguation/Realities' )
--local special_names = { "Mojoverse", "Brilliant City", "Otherworld", "Weirdworld", "Unknown Reality", "Unknown" }
 
-- separate 'pagename' into name and reality. If reality is not empty, then information about it is returned from 'list_of_realities'
function p.lua_get_name_and_reality(pagename)
    local s_reverse
    local s_name = pagename
    local info = {}
    local s_reality = {}
    local i
 
    if not h.isempty(pagename)
        then
            pagename = string.gsub(pagename,'_',' ')
            s_reverse = string.reverse(pagename)
            i = string.find(s_reverse,'( ',1,true)
            j = string.find(s_reverse,')',1,true)
            if not h.isempty(i)
                then
                    s_name = string.reverse( string.sub(s_reverse, i+2, #s_reverse) )
                    s_reality = string.reverse( string.sub(s_reverse, j+1, i-1) )
                    info = p.get_reality_info({s_reality})
                    if not h.isempty(info)
                        then s_reality = info
                        else s_reality = ''
                    end
                else
                    info = p.get_reality_info({pagename})
                    if not h.isempty(info)
                        then s_reality = info
                        else s_reality = ''
                    end
                    s_name = ''
            end
    end
 
    return s_name, s_reality
end
 
 
function p.get_reality_info(frame)
    local args = getArgs (frame)
    local reality = args[1]
    local part = args[2]
    local info
    local s2
    local s3
    local output = ''
 
    if not h.isempty(reality)
        then
            reality = string.gsub(reality, 'Earth%-', '')
            info = list_of_realities[reality]
            if info ~= nil
                then output = { ['name'] = info[2], ['description'] = info[1], ['type'] = info[3], ['number'] = reality }
                elseif tonumber(reality) ~= nil or string.match(reality, '^TRN%d+') ~= nil
                    then output = { ['name'] = "Earth-"..reality, ['description'] = "Earth-"..reality, ['type'] = "Comic", ['number'] = reality }
                    --else output = { ['name'] = reality, ['description'] = reality, ['type'] = "Comic" }
            end
    end
 
    if not h.isempty(part)
        then
            part = tonumber(part)
            if part == 3
                then output = output.type
                elseif part == 2
                    then output = output.description
                else output = output.name
            end
    end
 
    return output
end
 
 
return p
Community content is available under CC-BY-SA unless otherwise noted.

Fandom may earn an affiliate commission on sales made from links on this page.

Stream the best stories.

Fandom may earn an affiliate commission on sales made from links on this page.

Get Disney+