local ____lualib = require("lualib_bundle")
local __TS__New = ____lualib.__TS__New
local Set = ____lualib.Set
local __TS__ArraySort = ____lualib.__TS__ArraySort
local __TS__ArrayEntries = ____lualib.__TS__ArrayEntries
local __TS__Iterator = ____lualib.__TS__Iterator
local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
local ____exports = {}
local isRacingPlusSandboxEnabled
local ____ReadonlySet = require("types.ReadonlySet")
local ReadonlySet = ____ReadonlySet.ReadonlySet
local ____debugFunctions = require("functions.debugFunctions")
local getTraceback = ____debugFunctions.getTraceback
local isLuaDebugEnabled = ____debugFunctions.isLuaDebugEnabled
local traceback = ____debugFunctions.traceback
local logExports = require("functions.log")
local ____log = require("functions.log")
local log = ____log.log
local logEntitiesExports = require("functions.logEntities")
local logMiscExports = require("functions.logMisc")
local ____set = require("functions.set")
local addSetsToSet = ____set.addSetsToSet
local copySet = ____set.copySet
local ____sort = require("functions.sort")
local sortTwoDimensionalArray = ____sort.sortTwoDimensionalArray
function isRacingPlusSandboxEnabled(self)
    return SandboxGetParentFunctionDescription ~= nil
end
local DEFAULT_GLOBALS = __TS__New(ReadonlySet, {
    "ActionTriggers",
    "ActiveSlot",
    "BabySubType",
    "BackdropType",
    "BatterySubType",
    "BedSubType",
    "BitSet128",
    "BombSubType",
    "BombVariant",
    "ButtonAction",
    "CacheFlag",
    "Card",
    "Challenge",
    "ChampionColor",
    "ChestSubType",
    "CoinSubType",
    "CollectibleType",
    "Color",
    "CppContainer",
    "DamageFlag",
    "Difficulty",
    "Direction",
    "DoorSlot",
    "DoorState",
    "DoorVariant",
    "EffectVariant",
    "Entity",
    "EntityBomb",
    "EntityCollisionClass",
    "EntityEffect",
    "EntityFamiliar",
    "EntityFlag",
    "EntityGridCollisionClass",
    "EntityKnife",
    "EntityLaser",
    "EntityNPC",
    "EntityPartition",
    "EntityPickup",
    "EntityPlayer",
    "EntityProjectile",
    "EntityPtr",
    "EntityRef",
    "EntityTear",
    "EntityType",
    "FamiliarVariant",
    "Font",
    "Game",
    "GameStateFlag",
    "GetPtrHash",
    "GridCollisionClass",
    "GridEntity",
    "GridEntityDesc",
    "GridEntityDoor",
    "GridEntityPit",
    "GridEntityPoop",
    "GridEntityPressurePlate",
    "GridEntityRock",
    "GridEntitySpikes",
    "GridEntityTNT",
    "GridEntityType",
    "GridRooms",
    "HUD",
    "HeartSubType",
    "Input",
    "InputHook",
    "Isaac",
    "ItemConfig",
    "ItemPool",
    "ItemPoolType",
    "ItemType",
    "KColor",
    "KeySubType",
    "Keyboard",
    "LaserOffset",
    "LaserSubType",
    "Level",
    "LevelCurse",
    "LevelStage",
    "LevelStateFlag",
    "LocustSubtypes",
    "ModCallbacks",
    "Mouse",
    "Music",
    "MusicManager",
    "NpcState",
    "NullItemID",
    "Options",
    "PathFinder",
    "PickupPrice",
    "PickupVariant",
    "PillColor",
    "PillEffect",
    "PlayerForm",
    "PlayerSpriteLayer",
    "PlayerType",
    "PlayerTypes",
    "PoopPickupSubType",
    "PoopSpellType",
    "ProjectileFlags",
    "ProjectileParams",
    "ProjectileVariant",
    "QueueItemData",
    "REPENTANCE",
    "RNG",
    "Random",
    "RandomVector",
    "RegisterMod",
    "RenderMode",
    "Room",
    "RoomConfig",
    "RoomDescriptor",
    "RoomShape",
    "RoomTransitionAnim",
    "RoomType",
    "SFXManager",
    "SackSubType",
    "SeedEffect",
    "Seeds",
    "SkinColor",
    "SortingLayer",
    "SoundEffect",
    "Sprite",
    "StageType",
    "StartDebug",
    "TearFlags",
    "TearParams",
    "TearVariant",
    "TemporaryEffect",
    "TemporaryEffects",
    "TrinketType",
    "UseFlag",
    "Vector",
    "WeaponType",
    "_G",
    "_VERSION",
    "assert",
    "collectgarbage",
    "coroutine",
    "error",
    "getmetatable",
    "include",
    "ipairs",
    "load",
    "math",
    "next",
    "pairs",
    "pcall",
    "print",
    "rawequal",
    "rawget",
    "rawlen",
    "rawset",
    "require",
    "select",
    "setmetatable",
    "string",
    "table",
    "tonumber",
    "tostring",
    "type",
    "utf8",
    "xpcall"
})
local LUA_DEBUG_ADDED_GLOBALS = __TS__New(ReadonlySet, {
    "debug",
    "dofile",
    "loadfile",
    "io",
    "os",
    "package"
})
local RACING_PLUS_SANDBOX_ADDED_GLOBALS = __TS__New(ReadonlySet, {"sandboxTraceback", "sandboxGetTraceback", "getParentFunctionDescription"})
--- Helper function to get a set containing all of the global variable names that are contained
-- within the Isaac environment by default.
-- 
-- Returns a slightly different set depending on whether the "--luadebug" flag is enabled.
function ____exports.getDefaultGlobals(self)
    local defaultGlobals = copySet(nil, DEFAULT_GLOBALS)
    if isLuaDebugEnabled(nil) then
        addSetsToSet(nil, defaultGlobals, LUA_DEBUG_ADDED_GLOBALS)
    end
    if isRacingPlusSandboxEnabled(nil) then
        addSetsToSet(nil, defaultGlobals, RACING_PLUS_SANDBOX_ADDED_GLOBALS)
    end
    return defaultGlobals
end
--- Helper function to get an array of any added global variables in the Isaac Lua environment.
-- Returns a sorted array of key/value tuples.
function ____exports.getNewGlobals(self)
    local defaultGlobals = ____exports.getDefaultGlobals(nil)
    local newGlobals = {}
    for key, value in pairs(_G) do
        if not defaultGlobals:has(key) then
            local keyValueTuple = {key, value}
            newGlobals[#newGlobals + 1] = keyValueTuple
        end
    end
    __TS__ArraySort(newGlobals, sortTwoDimensionalArray)
    return newGlobals
end
--- Helper function to log any added global variables in the Isaac Lua environment.
function ____exports.logNewGlobals(self)
    local newGlobals = ____exports.getNewGlobals(nil)
    log("List of added global variables in the Isaac environment:")
    if #newGlobals == 0 then
        log("- n/a (no extra global variables found)")
    else
        for ____, ____value in __TS__Iterator(__TS__ArrayEntries(newGlobals)) do
            local i = ____value[1]
            local tuple = ____value[2]
            local key, value = table.unpack(tuple)
            log((((tostring(i + 1) .. ") ") .. tostring(key)) .. " - ") .. tostring(value))
        end
    end
end
--- Converts every `isaacscript-common` function that begins with "log" to a global function.
-- 
-- This is useful when printing out variables from the in-game debug console.
function ____exports.setLogFunctionsGlobal(self)
    local globals = _G
    for ____, exports in ipairs({logExports, logMiscExports, logEntitiesExports}) do
        for ____, ____value in ipairs(__TS__ObjectEntries(exports)) do
            local logFuncName = ____value[1]
            local logFunc = ____value[2]
            globals[logFuncName] = logFunc
        end
    end
end
--- Sets the `traceback` and `getTraceback` functions to be global functions.
-- 
-- This is useful when editing Lua files when troubleshooting.
function ____exports.setTracebackFunctionsGlobal(self)
    local globals = _G
    globals.getTraceback = getTraceback
    globals.traceback = traceback
end
return ____exports
