Skip to content

Commit

Permalink
Merge branch 'main' into changelog-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio authored Aug 13, 2024
2 parents 9c457d3 + 39f758c commit ce40f55
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
7 changes: 5 additions & 2 deletions lib/debugger/ui.luau
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ local function ui(debugger, loop)

local objectStack = plasma.useState({})
local worldViewOpen, setWorldViewOpen = plasma.useState(false)
local worldExists = debugger.debugWorld ~= nil

if debugger.hoverEntity then
custom.hoverInspect(debugger.debugWorld, debugger.hoverEntity, custom)
if debugger.hoverEntity and worldExists then
if debugger.debugWorld:contains(debugger.hoverEntity) then
custom.hoverInspect(debugger.debugWorld, debugger.hoverEntity, custom)
end
end

custom.container(function()
Expand Down
56 changes: 41 additions & 15 deletions lib/debugger/widgets/worldInspect.luau
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
local formatTableModule = require(script.Parent.Parent.formatTable)
local formatTable = formatTableModule.formatTable

local BY_COMPONENT_NAME = "ComponentName"
local BY_ENTITY_COUNT = "EntityCount"

return function(plasma)
return plasma.widget(function(debugger, objectStack)
local style = plasma.useStyle()

local world = debugger.debugWorld

local cache, setCache = plasma.useState()
-- TODO #97 Implement sorting by descending as well.
local ascendingOrder, _ = plasma.useState(false)

local sortType, setSortType = plasma.useState(BY_COMPONENT_NAME)
local isAscendingOrder, setIsAscendingOrder = plasma.useState(true)

local skipIntersections, setSkipIntersections = plasma.useState(true)
local debugComponent, setDebugComponent = plasma.useState()

Expand Down Expand Up @@ -71,26 +76,47 @@ return function(plasma)
})
end

local indexForSort = if sortType == BY_ENTITY_COUNT then 1 else 2

table.sort(items, function(a, b)
if ascendingOrder then
return a[1] < b[1]
if isAscendingOrder then
return a[indexForSort] < b[indexForSort]
end

-- Default to alphabetical
return a[2] < b[2]
return a[indexForSort] > b[indexForSort]
end)

table.insert(items, 1, { "Count", "Component" })
local arrow = if isAscendingOrder then "▲" else "▼"
local countHeading = `{if sortType == BY_ENTITY_COUNT then arrow else ""} Count `
local componentHeading = `{if sortType == BY_COMPONENT_NAME then arrow else ""} Component`
local headings = { countHeading, componentHeading }
table.insert(items, 1, headings)

plasma.row({ padding = 30 }, function()
local selectedRow = plasma
.table(items, {
width = 200,
headings = true,
selectable = true,
font = Enum.Font.Code,
})
:selected()
local worldInspectTable = plasma.table(items, {
width = 200,
headings = true,
selectable = true,
font = Enum.Font.Code,
})

local selectedHeading = worldInspectTable:selectedHeading()

if headings[selectedHeading] == headings[1] then
if sortType == BY_ENTITY_COUNT then
setIsAscendingOrder(not isAscendingOrder)
else
setSortType(BY_ENTITY_COUNT)
end
elseif headings[selectedHeading] == headings[2] then
if sortType == BY_COMPONENT_NAME then
setIsAscendingOrder(not isAscendingOrder)
else
setSortType(BY_COMPONENT_NAME)
end
end

local selectedRow = worldInspectTable:selected()

if selectedRow then
setDebugComponent(selectedRow.component)
Expand Down

0 comments on commit ce40f55

Please sign in to comment.