FANDOM


local utils = require('Module:Utils')
local class_icon = require('Module:Class icon')
local class_tags = require('Module:Class tags')
local api = require('Module:API')
local classes = mw.loadData('Module:APIDump').Classes
local p = {}
 
local function make_class_link(classname, icon)
    local class_link = "[[Class:" .. classname .. "|" .. classname .. "]]"
    if class_tags.has_tag(classname, 'Deprecated') then
        class_link = "<s>" .. class_link .. "</s>"
    end
    if icon then
        return icon .. class_link
    else
        return class_link
    end
end
 
function p.get_superclass(class_name)
    if p.superclass_data[class_name] then
        return p.superclass_data[class_name]
    end
    if class_name == 'Instance' then
        return
    end
    local class_data = api.get_class_data(class_name)
    if class_data then
        return class_data.Superclass
    end
end
 
function p._class_link(args)
    return make_class_link(args.class, class_icon.get_custom_class_icon(args.class, false))
end
 
p.class_link = utils.make_wrapper_function(p._class_link)
 
function p._class_link_with_fallback_icon(args)
    return make_class_link(args.class, class_icon.get_custom_class_icon(args.class, true))
end
 
p.class_link_with_fallback_icon = utils.make_wrapper_function(p._class_link_with_fallback_icon)
 
function p._superclass(args)
    return p.get_superclass(args.class)
end
 
p.superclass = utils.make_wrapper_function(p._superclass)
 
function p._superclass_level(args)
    if args.level == "0" then
        return args.class
    else
        local current_superclass = args.class
        for i = 1, tonumber(args.level) do
            current_superclass = p.get_superclass(current_superclass)
        end
        return current_superclass
    end
end
 
p.superclass_level = utils.make_wrapper_function(p._superclass_level)
 
function p._superclass_list(args)
    local list = ''
    local current_superclass = p.get_superclass(args.class)
    while current_superclass do
        list = list .. "<li>" .. p._class_link_with_fallback_icon {class = current_superclass} .. "</li>"
        current_superclass = p.get_superclass(current_superclass)
    end
    return '<ol>' .. list .. '</ol>'
end
 
p.superclass_list = utils.make_wrapper_function(p._superclass_list)
 
-- Returns an array of a class' subclasses, sorted
function p.get_subclasses(class_name)
    local subclasses = {}
    for _, class in pairs(classes) do
       if class.Superclass == class_name then
           subclasses[class.Name] = true
       end
    end
    for class, superclass in pairs(p.superclass_data) do
        if superclass == class_name then
            subclasses[class] = true
        end
    end
    subclasses = utils.set_to_array(subclasses)
    table.sort(subclasses)
    return subclasses
end
 
function p._subclass_tree(args)
    local list = ''
    for _, subclass in pairs(p.get_subclasses(args.class)) do
        list = list .. '<li>' .. p._class_link_with_fallback_icon{class = subclass} .. p._subclass_tree{class = subclass} .. '</li>\n'
    end
    if list ~= '' then
        return '<ul>' .. list .. '</ul>'
    end
    return list
end
 
p.subclass_tree = utils.make_wrapper_function(p._subclass_tree)
 
function p._class_reference()
    return '<ul>' .. p._class_link_with_fallback_icon{class = 'Instance'} .. p._subclass_tree{class = 'Instance'} .. '</ul>'
end
 
p.class_reference = utils.make_wrapper_function(p._class_reference)
 
-- Keys are class names; values are their superclass.
-- This overrides information from the API dump.
-- Information about removed classes should preferably be added to [[Module:RemovedAPI]].
p.superclass_data = {
    -- Removed classes
    App = 'DataModel';
    LoadingGui = 'Instance';
    LobbyService = 'Instance';
    LocalBackpack = 'GuiItem';
    LocalWorkspace = 'Instance';
    NavigationPath = 'Instance';
    NavigationService = 'Instance';
    NavigationWaypoint = 'Instance';
    ParallelRampPart = 'BasePart';
    PathWaypoint = 'Instance';
    PersonalServerService = 'Instance';
    PlayerHUD = 'GuiItem';
    PlayerJoinData = 'Instance';
    PresenceService = 'Instance';
    PrismPart = 'BasePart';
    ProfilingItem = 'StatsItem';
    PseudoPlayer = 'Instance';
    PyramidPart = 'BasePart';
    RenderHooksService = 'Instance';
    RightAngleRampPart = 'BasePart';
    RootInstance = 'Model';
    ScriptInformationProvider = 'Instance';
    SocialService = 'Instance';
    SpatialQueryCache = 'Instance';
    StarterScript = 'CoreScript';
    StockSound = 'Sound';
    StudioTool = 'Instance';
    TextureContentProvider = 'CacheableContentProvider';
    UniverseService = 'Instance';
    WeldConstraint = 'Instance';
}
 
return p
Community content is available under CC-BY-SA unless otherwise noted.