local Q=25 local h=game:GetService("\080\108\097\121\101\114\115")local N=game:GetService("\082\117\110\083\101\114\118\105\099\101")local H=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local O=require(((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"))local U=O:GetResource("\069\120\116\101\114\110\097\108\085\116\105\108\046\078\101\120\117\115\073\110\115\116\097\110\099\101\046\078\101\120\117\115\079\098\106\101\099\116")local T=O:GetResource("\071\097\109\101\068\097\116\097\046\071\101\110\101\114\097\116\105\111\110\046\076\097\110\100\109\097\114\107\115")local J=O:GetResource("\085\073\046\066\117\116\116\111\110\046\073\109\097\103\101\069\118\101\110\116\066\105\110\100\101\114")local t=O:GetResource("\085\073\046\066\117\116\116\111\110\046\087\105\100\101\084\101\120\116\066\117\116\116\111\110\068\101\099\111\114\097\116\111\114")local P=O:GetResource("\085\073\046\065\115\112\101\099\116\082\097\116\105\111\083\119\105\116\099\104\101\114")local b=O:GetResource("\083\116\097\116\101\046\066\111\111\108\071\114\105\100")local B=O:GetResource("\083\116\097\116\101\046\068\105\115\112\108\097\121\079\114\100\101\114\067\111\110\116\114\111\108\108\101\114")local L=O:GetResource("\083\116\097\116\101\046\080\108\097\121\101\114\068\097\116\097")local K=require(script.Parent:WaitForChild("\077\097\112"))local W=U:Extend()W:SetClassName("\067\111\114\110\101\114\077\097\112")function W.__new(W,U)W:InitializeSuper()local g=Instance.new("\073\109\097\103\101\076\097\098\101\108")g.Size=UDim2.new(1.8,0,1.8,0)g.SizeConstraint="\082\101\108\097\116\105\118\101\089\089"g.Position=UDim2.new(1,0,0,0)g.AnchorPoint=Vector2.new(.8,.325)g.BackgroundTransparency=1 g.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\055\050\053\051\057\056"g.Parent=U local u=Instance.new("\073\109\097\103\101\066\117\116\116\111\110")u.BackgroundTransparency=1 u.Size=UDim2.new(.6,0,.6,0)u.Position=UDim2.new(.13,0,.21,0)u.ClipsDescendants=true u.Parent=g local q=Instance.new("\083\099\114\101\101\110\071\117\105")q.Name="\077\097\112"q.Parent=script.Parent.Parent local I=Instance.new("\073\109\097\103\101\076\097\098\101\108")I.BackgroundTransparency=1 I.Position=UDim2.new(.5,0,1.5,0)I.AnchorPoint=Vector2.new(.5,.5)I.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\050\055\052\053\057\053"I.Parent=q P.new(q,1.4,function()I.Size=UDim2.new(1.26,0,.9,0)I.SizeConstraint=Enum.SizeConstraint.RelativeYY end,function()I.Size=UDim2.new(.9,0,.64285714285714,0)I.SizeConstraint=Enum.SizeConstraint.RelativeXX end)local r=Instance.new("\070\114\097\109\101")r.Size=UDim2.new(.8,0,.8,0)r.SizeConstraint=Enum.SizeConstraint.RelativeYY r.Position=UDim2.new(.04,0,.1,0)r.ClipsDescendants=true r.Parent=I local p=Instance.new("\073\109\097\103\101\076\097\098\101\108")p.BackgroundTransparency=1 p.AnchorPoint=Vector2.new(1,0)p.Size=UDim2.new(.065,0,.065,0)p.SizeConstraint=Enum.SizeConstraint.RelativeYY p.Position=UDim2.new(1,0,0,0)p.Parent=I local y=J.new(p,UDim2.new(1,0,1,0),"\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\051\048\050\052\056\056","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\051\048\050\052\051\056","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\051\048\050\052\054\053")local v=Instance.new("\073\109\097\103\101\076\097\098\101\108")v.BackgroundTransparency=1 v.Size=UDim2.new(.82,0,.82,0)v.SizeConstraint=Enum.SizeConstraint.RelativeYY v.Position=UDim2.new(.03,0,.09,0)v.ZIndex=5 v.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\050\055\053\050\054\050"v.Parent=I local n=Instance.new("\073\109\097\103\101\076\097\098\101\108")n.BackgroundTransparency=1 n.Size=UDim2.new(.1,0,.1,0)n.SizeConstraint=Enum.SizeConstraint.RelativeYY n.Position=UDim2.new(.625,0,.65,0)n.Parent=I local l=J.new(n,UDim2.new(1,0,1,0),"\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\050\055\053\050\048\056","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\050\055\053\049\056\055","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\050\055\053\050\048\052")local d=Instance.new("\073\109\097\103\101\076\097\098\101\108")d.BackgroundTransparency=1 d.Size=UDim2.new(.1,0,.1,0)d.SizeConstraint=Enum.SizeConstraint.RelativeYY d.Position=UDim2.new(.625,0,.775,0)d.Parent=I local E=J.new(d,UDim2.new(1,0,1,0),"\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\050\055\053\049\054\053","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\050\055\053\049\051\054","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\050\055\053\049\052\056")local w=Instance.new("\073\109\097\103\101\076\097\098\101\108")w.BackgroundTransparency=1 w.Size=UDim2.new(.35,0,.6,0)w.SizeConstraint=Enum.SizeConstraint.RelativeYY w.Position=UDim2.new(.715,0,.35,0)w.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\050\055\052\057\053\051"w.Parent=I local c=Instance.new("\073\109\097\103\101\076\097\098\101\108")c.BackgroundTransparency=1 c.AnchorPoint=Vector2.new(.5,1)c.Size=UDim2.new(.36153846153846,0,.1,0)c.SizeConstraint=Enum.SizeConstraint.RelativeYY c.Position=UDim2.new(.5,0,.95,0)c.ZIndex=8 c.Visible=false c.Parent=r local Z=t.new(c,"\082\069\067\069\078\084\069\082")W.RecenterImage=c local V=Instance.new("\083\099\114\111\108\108\105\110\103\070\114\097\109\101")V.BackgroundTransparency=1 V.BorderSizePixel=0 V.AnchorPoint=Vector2.new(1,0)V.Position=UDim2.new(.94,12,.07,0)V.Size=UDim2.new(.22596153846154,12,.25,0)V.TopImage="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\055\048\054\056\051\055\050\048\053"V.MidImage="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\055\048\054\056\051\054\057\054\048"V.BottomImage="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\055\048\054\056\051\054\055\052\054"V.Parent=I local f=L.GetPlayerData(h.LocalPlayer)local C=b.new(200,200)local Y=K.new(u,9,C)W.MiniMap=Y local R=K.new(r,19,C)R:EnableWarping()W.FullMap=R C:LoadFromString(f:GetValue("\068\105\115\099\111\118\101\114\101\100\077\097\112\067\101\108\108\115"));(f:GetValueChangedSignal("\068\105\115\099\111\118\101\114\101\100\077\097\112\067\101\108\108\115")):Connect(function()C:LoadFromString(f:GetValue("\068\105\115\099\111\118\101\114\101\100\077\097\112\067\101\108\108\115"))Y:UpdateCells()R:UpdateCells()end)local z={}for Q,h in pairs(T)do table.insert(z,Q)end table.sort(z)V.CanvasSize=UDim2.new(0,0,.0625*#z,0)local A for h,H in pairs(z)do local O=Instance.new("\073\109\097\103\101\076\097\098\101\108")O.BackgroundTransparency=1 O.Size=UDim2.new(1,-12,1/#z,0)O.Position=UDim2.new(0,0,(h-1)/#z,0)O.Parent=V local U=t.new(O,H)local J=T[H]local P=true U.Button.MouseButton1Down:Connect(function()if P then P=false local h,H=R.LastX,R.LastY local O,U=J[1]-h,J[2]-H local T=(O^2+U^2)^.5 local t=T/Q local b=tick()A=b W.MainMapAttached=false c.Visible=true while not W.DraggingMainMap and(not W.MainMapAttached and(A==b and tick()-b<=t))do local Q=(tick()-b)/t Q=(1-math.cos(Q*math.pi))/2 local T,J=h+O*Q,H+U*Q R:SetCenter(T,J)N.RenderStepped:Wait()end P=true end end)end local M=script.Parent.Parent:WaitForChild("\071\117\105\079\112\101\110\083\116\097\116\101\115")local m=Instance.new("\066\111\111\108\086\097\108\117\101")m.Name="\077\097\112"m.Value=false m.Parent=M B:Register(q,m)local D=true m.Changed:Connect(function()I:TweenPosition(UDim2.new(.5,0,m.Value and.5 or 1.5),"\079\117\116","\081\117\097\100",.5,true)end)u.MouseButton1Down:Connect(function()if D then D=false m.Value=not m.Value wait()D=true end end)y.Button.MouseButton1Down:Connect(function()if D then D=false m.Value=false wait()D=true end end)local s=6 local S W.DraggingMainMap=false W.MainMapAttached=true l.Button.MouseButton1Down:Connect(function()if D then D=false wait()s=math.clamp(s-2,6,16)R:SetViewableWidth(s)D=true end end)E.Button.MouseButton1Down:Connect(function()if D then D=false wait()s=math.clamp(s+2,6,16)R:SetViewableWidth(s)D=true end end)r.InputBegan:Connect(function(Q,h)if not h and(not W.DraggingMainMap and(Q.UserInputType==Enum.UserInputType.MouseButton1 or Q.UserInputType==Enum.UserInputType.Touch))then S=Q.Position W.DraggingMainMap=true W.MainMapAttached=false c.Visible=true end end)H.InputEnded:Connect(function(Q)if W.DraggingMainMap and(Q.UserInputType==Enum.UserInputType.MouseButton1 or Q.UserInputType==Enum.UserInputType.Touch)then W.DraggingMainMap=false end end)H.InputChanged:Connect(function(Q)if W.DraggingMainMap and(Q.UserInputType==Enum.UserInputType.MouseMovement or Q.UserInputType==Enum.UserInputType.Touch)then local h=Q.Position-S local N=r.AbsoluteSize.X/s local H,O=h.X/N,h.Y/N S=Q.Position R:SetCenter(R.LastX+O,R.LastY-H)end end)Z.Button.MouseButton1Down:Connect(function()if D and not W.DraggingMainMap then D=false W.MainMapAttached=true c.Visible=false wait()D=true end end)for Q,h in pairs(h:GetPlayers())do(coroutine.wrap(function()W:PlayerAdded(h)end))()end h.PlayerAdded:Connect(function(Q)W:PlayerAdded(Q)end)h.PlayerRemoving:Connect(function(Q)W.MiniMap:RemoveCharacterIndicator(Q)W.FullMap:RemoveCharacterIndicator(Q)end);(coroutine.wrap(function()local Q=O:GetResource("\078\101\120\117\115\065\100\109\105\110\067\108\105\101\110\116")Q.Registry:LoadCommand({Keyword="\115\104\111\119\109\097\112\099\111\110\102\105\100\101\110\099\101";Prefix=Q.Configuration.CommandPrefix,Category="\071\097\109\101\068\101\098\117\103";Description="\068\105\115\112\108\097\121\115 \116\104\101 \099\111\110\102\105\100\101\110\099\101 \111\102 \116\104\101 \109\097\112 \100\097\116\097\046 \071\114\101\101\110 \105\115 \099\111\110\102\105\114\109\101\100 \098\121 \118\105\100\101\111\044 \114\101\100 \105\115 \110\111\116 \099\111\110\102\105\114\109\101\100\044 \097\110\100 \098\108\117\101 \105\115 \097\114\098\105\116\114\097\114\121\046";AdminLevel=-1,Arguments={{Type="\098\111\111\108\101\097\110";Name="\083\104\111\119";Default=true,Description="\087\104\101\116\104\101\114 \116\104\101 \099\111\110\102\105\100\101\110\099\101 \118\097\108\117\101\115 \115\104\111\117\108\100 \098\101 \115\104\111\119\110\046"}};Run=function(Q,h,N)W.MiniMap:SetMapConfidence(N)W.FullMap:SetMapConfidence(N)return"\067\111\110\102\105\100\101\110\099\101 \116\111\103\103\108\101\100\046"end})end))()end function W.PlayerAdded(h,Q)Q.CharacterAdded:Connect(function(N)h:CharacterAdded(N,Q)end)if Q.Character then h:CharacterAdded(Q.Character,Q)end end function W.CharacterAdded(H,Q,N)local O=Q:WaitForChild("\072\101\097\100")H.MiniMap:AddCharacterIndicator(N)H.FullMap:AddCharacterIndicator(N)if N==h.LocalPlayer then while Q.Parent do local Q,h=O.CFrame.X/100,O.CFrame.Z/100 H.MiniMap:SetCenter(Q,h)if H.MainMapAttached then H.FullMap:SetCenter(Q,h)end wait()end end end return W
--[[
TheNexusAvenger

Map for the bottom bar.
--]]

local MAP_LANDMARK_MAX_MOVE_SPEED = 25



local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local ReplicatedStorageProject = require(game:GetService("ReplicatedStorage"):WaitForChild("Project"):WaitForChild("ReplicatedStorage"))

local NexusObject = ReplicatedStorageProject:GetResource("ExternalUtil.NexusInstance.NexusObject")
local Landmarks = ReplicatedStorageProject:GetResource("GameData.Generation.Landmarks")
local ImageEventBinder = ReplicatedStorageProject:GetResource("UI.Button.ImageEventBinder")
local WideTextButtonDecorator = ReplicatedStorageProject:GetResource("UI.Button.WideTextButtonDecorator")
local AspectRatioSwitcher = ReplicatedStorageProject:GetResource("UI.AspectRatioSwitcher")
local BoolGrid = ReplicatedStorageProject:GetResource("State.BoolGrid")
local DisplayOrderController = ReplicatedStorageProject:GetResource("State.DisplayOrderController")
local PlayerData = ReplicatedStorageProject:GetResource("State.PlayerData")
local Map = require(script.Parent:WaitForChild("Map"))

local CornerMap = NexusObject:Extend()
CornerMap:SetClassName("CornerMap")



--[[
Creates a corner map.
--]]
function CornerMap:__new(BottomFrame)
    self:InitializeSuper()
    
    --Create the bottom bar container.
    local MapBottomBarBackground = Instance.new("ImageLabel")
    MapBottomBarBackground.Size = UDim2.new(1.8,0,1.8,0)
    MapBottomBarBackground.SizeConstraint = "RelativeYY"
    MapBottomBarBackground.Position = UDim2.new(1,0,0,0)
    MapBottomBarBackground.AnchorPoint = Vector2.new(0.8,0.325)
    MapBottomBarBackground.BackgroundTransparency = 1
    MapBottomBarBackground.Image = "rbxassetid://132725398"
    MapBottomBarBackground.Parent = BottomFrame

    local MiniMapContainer = Instance.new("ImageButton")
    MiniMapContainer.BackgroundTransparency = 1
    MiniMapContainer.Size = UDim2.new(0.6,0,0.6,0)
    MiniMapContainer.Position = UDim2.new(0.13,0,0.21,0)
    MiniMapContainer.ClipsDescendants = true
    MiniMapContainer.Parent = MapBottomBarBackground

    --Create the window.
    local MapScreenGui = Instance.new("ScreenGui")
    MapScreenGui.Name = "Map"
    MapScreenGui.Parent = script.Parent.Parent

    local Background = Instance.new("ImageLabel")
    Background.BackgroundTransparency = 1
    Background.Position = UDim2.new(0.5,0,1.5,0)
    Background.AnchorPoint = Vector2.new(0.5,0.5)
    Background.Image = "rbxassetid://131274595"
    Background.Parent = MapScreenGui
    
    AspectRatioSwitcher.new(MapScreenGui,1.4,function()
        Background.Size = UDim2.new(0.9 * 1.4,0,0.9,0)
        Background.SizeConstraint = Enum.SizeConstraint.RelativeYY
    end,function()
        Background.Size = UDim2.new(0.9,0,0.9/1.4,0)
        Background.SizeConstraint = Enum.SizeConstraint.RelativeXX
    end)

    local MapContainer = Instance.new("Frame")
    MapContainer.Size = UDim2.new(0.8,0,0.8,0)
    MapContainer.SizeConstraint = Enum.SizeConstraint.RelativeYY
    MapContainer.Position = UDim2.new(0.04,0,0.1,0)
    MapContainer.ClipsDescendants = true
    MapContainer.Parent = Background

    local MapCloseImage = Instance.new("ImageLabel")
    MapCloseImage.BackgroundTransparency = 1
    MapCloseImage.AnchorPoint = Vector2.new(1,0)
    MapCloseImage.Size = UDim2.new(0.065,0,0.065,0)
    MapCloseImage.SizeConstraint = Enum.SizeConstraint.RelativeYY
    MapCloseImage.Position = UDim2.new(1,0,0,0)
    MapCloseImage.Parent = Background
    local MapCloseButton = ImageEventBinder.new(MapCloseImage,UDim2.new(1,0,1,0),"rbxassetid://131302488","rbxassetid://131302438","rbxassetid://131302465")

    local MapCover = Instance.new("ImageLabel")
    MapCover.BackgroundTransparency = 1
    MapCover.Size = UDim2.new(0.82,0,0.82,0)
    MapCover.SizeConstraint = Enum.SizeConstraint.RelativeYY
    MapCover.Position = UDim2.new(0.03,0,0.09,0)
    MapCover.ZIndex = 5
    MapCover.Image = "rbxassetid://131275262"
    MapCover.Parent = Background

    local ZoomInImage = Instance.new("ImageLabel")
    ZoomInImage.BackgroundTransparency = 1
    ZoomInImage.Size = UDim2.new(0.1,0,0.1,0)
    ZoomInImage.SizeConstraint = Enum.SizeConstraint.RelativeYY
    ZoomInImage.Position = UDim2.new(0.625,0,0.65,0)
    ZoomInImage.Parent = Background
    local ZoomInButton = ImageEventBinder.new(ZoomInImage,UDim2.new(1,0,1,0),"rbxassetid://131275208","rbxassetid://131275187","rbxassetid://131275204")

    local ZoomOutImage = Instance.new("ImageLabel")
    ZoomOutImage.BackgroundTransparency = 1
    ZoomOutImage.Size = UDim2.new(0.1,0,0.1,0)
    ZoomOutImage.SizeConstraint = Enum.SizeConstraint.RelativeYY
    ZoomOutImage.Position = UDim2.new(0.625,0,0.775,0)
    ZoomOutImage.Parent = Background
    local ZoomOutButton = ImageEventBinder.new(ZoomOutImage,UDim2.new(1,0,1,0),"rbxassetid://131275165","rbxassetid://131275136","rbxassetid://131275148")

    local Legend = Instance.new("ImageLabel")
    Legend.BackgroundTransparency = 1
    Legend.Size = UDim2.new(0.35,0,0.6,0)
    Legend.SizeConstraint = Enum.SizeConstraint.RelativeYY
    Legend.Position = UDim2.new(0.715,0,0.35,0)
    Legend.Image = "rbxassetid://131274953"
    Legend.Parent = Background

    local RecenterImage = Instance.new("ImageLabel")
    RecenterImage.BackgroundTransparency = 1
    RecenterImage.AnchorPoint = Vector2.new(0.5,1)
    RecenterImage.Size = UDim2.new(0.1 * (188/52),0,0.1,0)
    RecenterImage.SizeConstraint = Enum.SizeConstraint.RelativeYY
    RecenterImage.Position = UDim2.new(0.5,0,0.95,0)
    RecenterImage.ZIndex = 8
    RecenterImage.Visible = false
    RecenterImage.Parent = MapContainer
    local RecenterButton = WideTextButtonDecorator.new(RecenterImage,"RECENTER")
    self.RecenterImage = RecenterImage

    local LandmarkList = Instance.new("ScrollingFrame")
    LandmarkList.BackgroundTransparency = 1
    LandmarkList.BorderSizePixel = 0
    LandmarkList.AnchorPoint = Vector2.new(1,0)
    LandmarkList.Position = UDim2.new(0.94,12,0.07,0)
    LandmarkList.Size = UDim2.new(0.25 * (1/4) * (188/52),12,0.25,0)
    LandmarkList.TopImage = "rbxassetid://5706837205"
    LandmarkList.MidImage = "rbxassetid://5706836960"
    LandmarkList.BottomImage = "rbxassetid://5706836746"
    LandmarkList.Parent = Background

    --Initialize the maps.
    local MapPlayerData = PlayerData.GetPlayerData(Players.LocalPlayer)
    local DiscoveredCellsBoolGrid = BoolGrid.new(200,200)

    local MiniMap = Map.new(MiniMapContainer,9,DiscoveredCellsBoolGrid)
    self.MiniMap = MiniMap
    local FullMap = Map.new(MapContainer,19,DiscoveredCellsBoolGrid)
    FullMap:EnableWarping()
    self.FullMap = FullMap

    --Set up updating the visibility.
    DiscoveredCellsBoolGrid:LoadFromString(MapPlayerData:GetValue("DiscoveredMapCells"))
    MapPlayerData:GetValueChangedSignal("DiscoveredMapCells"):Connect(function()
        DiscoveredCellsBoolGrid:LoadFromString(MapPlayerData:GetValue("DiscoveredMapCells"))
        MiniMap:UpdateCells()
        FullMap:UpdateCells()
    end)

    --Sort the landmark names by alphabetical order.
    local LandmarkNames = {}
    for LandmarkName,_ in pairs(Landmarks) do
        table.insert(LandmarkNames,LandmarkName)
    end
    table.sort(LandmarkNames)

    --Add the landmarks to the list.
    LandmarkList.CanvasSize = UDim2.new(0,0,(0.25/4) * #LandmarkNames,0)
    local CurrentTween
    for i,LandmarkName in pairs(LandmarkNames) do
        --Create the button.
        local LandmarkImage = Instance.new("ImageLabel")
        LandmarkImage.BackgroundTransparency = 1
        LandmarkImage.Size = UDim2.new(1,-12,1/#LandmarkNames,0)
        LandmarkImage.Position = UDim2.new(0,0,(i - 1)/#LandmarkNames,0)
        LandmarkImage.Parent = LandmarkList
        local LandmarkButton = WideTextButtonDecorator.new(LandmarkImage,LandmarkName)

        --Connect clicking the button.
        local LandmarkData = Landmarks[LandmarkName]
        local DB = true
        LandmarkButton.Button.MouseButton1Down:Connect(function()
            if DB then
                DB = false

                --Calculate the tween.
                local StartX,StartY = FullMap.LastX,FullMap.LastY
                local DeltaX,DeltaY = LandmarkData[1] - StartX,LandmarkData[2] - StartY
                local TravelDistance = ((DeltaX ^ 2) + (DeltaY ^ 2)) ^ 0.5
                local TravelTime = TravelDistance / MAP_LANDMARK_MAX_MOVE_SPEED

                --Tween the map to the target while it isn't being dragged or recentered.
                local StartTime = tick()
                CurrentTween = StartTime
                self.MainMapAttached = false
                RecenterImage.Visible = true
                while not self.DraggingMainMap and not self.MainMapAttached and CurrentTween == StartTime and tick() - StartTime <= TravelTime do
                    --Determine and smooth the delta.
                    local Delta = (tick() - StartTime)/TravelTime
                    Delta = (1 - math.cos(Delta * math.pi))/2

                    --Move the map.
                    local X,Y = StartX + (DeltaX * Delta),StartY + (DeltaY * Delta)
                    FullMap:SetCenter(X,Y)
                    RunService.RenderStepped:Wait()
                end

                DB = true
            end
        end)
    end

    --Set up opening and closing the map.
    local GuiOpenStatesFolder = script.Parent.Parent:WaitForChild("GuiOpenStates")
    local MapOpenState = Instance.new("BoolValue")
    MapOpenState.Name = "Map"
    MapOpenState.Value = false
    MapOpenState.Parent = GuiOpenStatesFolder
    DisplayOrderController:Register(MapScreenGui,MapOpenState)

    local DB = true
    MapOpenState.Changed:Connect(function()
        Background:TweenPosition(UDim2.new(0.5,0,MapOpenState.Value and 0.5 or 1.5),"Out","Quad",0.5,true)
    end)
    MiniMapContainer.MouseButton1Down:Connect(function()
        if DB then
            DB = false
            MapOpenState.Value = not MapOpenState.Value
            wait()
            DB = true
        end
    end)
    MapCloseButton.Button.MouseButton1Down:Connect(function()
        if DB then
            DB = false
            MapOpenState.Value = false
            wait()
            DB = true
        end
    end)

    --Connect the main map events.
    local CurrentZoom = 6
    local LastMousePosition
    self.DraggingMainMap = false
    self.MainMapAttached = true
    ZoomInButton.Button.MouseButton1Down:Connect(function()
        if DB then
            DB = false
            wait()
            CurrentZoom = math.clamp(CurrentZoom - 2,6,16)
            FullMap:SetViewableWidth(CurrentZoom)
            DB = true
        end
    end)
    ZoomOutButton.Button.MouseButton1Down:Connect(function()
        if DB then
            DB = false
            wait()
            CurrentZoom = math.clamp(CurrentZoom + 2,6,16)
            FullMap:SetViewableWidth(CurrentZoom)
            DB = true
        end
    end)
    MapContainer.InputBegan:Connect(function(Input,Processed)
        if not Processed and not self.DraggingMainMap and (Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.Touch) then
            LastMousePosition = Input.Position
            self.DraggingMainMap = true
            self.MainMapAttached = false
            RecenterImage.Visible = true
        end
    end)
    UserInputService.InputEnded:Connect(function(Input)
        if self.DraggingMainMap and (Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.Touch) then
            self.DraggingMainMap = false
        end
    end)
    UserInputService.InputChanged:Connect(function(Input)
        if self.DraggingMainMap and (Input.UserInputType == Enum.UserInputType.MouseMovement or Input.UserInputType == Enum.UserInputType.Touch) then
            --Determine the delta.
            local MouseDelta = Input.Position - LastMousePosition
            local PixelsPerCell = MapContainer.AbsoluteSize.X/CurrentZoom
            local CellDeltaX,CellDeltaY = MouseDelta.X/PixelsPerCell,MouseDelta.Y/PixelsPerCell
            LastMousePosition = Input.Position

            --Move the map.
            FullMap:SetCenter(FullMap.LastX + CellDeltaY,FullMap.LastY - CellDeltaX)
        end
    end)
    RecenterButton.Button.MouseButton1Down:Connect(function()
        if DB and not self.DraggingMainMap then
            DB = false
            self.MainMapAttached = true
            RecenterImage.Visible = false
            wait()
            DB = true
        end
    end)

    --Connect players being added and removed.
    for _,Player in pairs(Players:GetPlayers()) do
        coroutine.wrap(function()
            self:PlayerAdded(Player)
        end)()
    end
    Players.PlayerAdded:Connect(function(Player)
        self:PlayerAdded(Player)
    end)
    Players.PlayerRemoving:Connect(function(Player)
        self.MiniMap:RemoveCharacterIndicator(Player)
        self.FullMap:RemoveCharacterIndicator(Player)
    end)

    --Register a toggle command for the map confidence data.
    coroutine.wrap(function()
        local NexusAdminAPI = ReplicatedStorageProject:GetResource("NexusAdminClient")
        
        NexusAdminAPI.Registry:LoadCommand({
            Keyword = "showmapconfidence",
            Prefix = NexusAdminAPI.Configuration.CommandPrefix,
            Category = "GameDebug",
            Description = "Displays the confidence of the map data. Green is confirmed by video, red is not confirmed, and blue is arbitrary.",
            AdminLevel = -1,
            Arguments = {
                {
                    Type = "boolean",
                    Name = "Show",
                    Default = true,
                    Description = "Whether the confidence values should be shown.",
                },
            },
            Run = function(_,CommandContext,ShowMapConfidence)
                self.MiniMap:SetMapConfidence(ShowMapConfidence)
                self.FullMap:SetMapConfidence(ShowMapConfidence)
                return "Confidence toggled."
            end,
        })
    end)()
end

--[[
Invoked when a player is added.
--]]
function CornerMap:PlayerAdded(Player)
    Player.CharacterAdded:Connect(function(Character)
        self:CharacterAdded(Character,Player)
    end)
    if Player.Character then
        self:CharacterAdded(Player.Character,Player)
    end
end

--[[
Invoked when a character is added.
--]]
function CornerMap:CharacterAdded(Character,Player)
    local Head = Character:WaitForChild("Head")

    --Add the character indicators.
    self.MiniMap:AddCharacterIndicator(Player)
    self.FullMap:AddCharacterIndicator(Player)

    --Set up updating the map.
    if Player == Players.LocalPlayer then
        while Character.Parent do
            local PosX,PosY = Head.CFrame.X/100,Head.CFrame.Z/100
            self.MiniMap:SetCenter(PosX,PosY)
            if self.MainMapAttached then
                self.FullMap:SetCenter(PosX,PosY) 
            end
            wait()
        end
    end
end



return CornerMap