Skip to content

Commit

Permalink
Sort systems by duration in Debugger (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackTabsCode committed Dec 8, 2024
1 parent 03e6dd6 commit 77cfe2a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog][kac], and this project adheres to

## [Unreleased]

### Added

- Added a button to the Debugger's system list to sort by run time.

### Fixed

- The debugger now gracefully handles cyclic tables.
Expand Down
17 changes: 16 additions & 1 deletion lib/debugger/ui.luau
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ local function ui(debugger, loop)
end
end

local sortByDuration, setSortByDuration = plasma.useState(false)

plasma.space(15)
plasma.heading("SYSTEMS")
plasma.row({ verticalAlignment = Enum.VerticalAlignment.Center }, function()
plasma.heading("SYSTEMS")

if plasma.button(`sort by: {sortByDuration and "duration" or "order"}`):clicked() then
setSortByDuration(not sortByDuration)
end
end)

plasma.space(10)

local durations = {}
Expand Down Expand Up @@ -198,6 +207,12 @@ local function ui(debugger, loop)
})
end

if sortByDuration then
table.sort(listOfSystems, function(a, b)
return (durations[a.system] or 0) > (durations[b.system] or 0)
end)
end

local systemList = custom.selectionList(listOfSystems, custom)
local selected = systemList:selected()
local rightClicked = systemList:rightClicked()
Expand Down
3 changes: 2 additions & 1 deletion lib/debugger/widgets/selectionList.luau
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ return function(Plasma)

Plasma.useEffect(function()
refs.mainText.Text = text
refs.index.Text = index or ""
refs.button.container.Icon.Text = icon or ""
refs.button.container.Icon.Visible = icon ~= nil
end, text, icon)
end, text, icon, index)

refs.button.container.sideText.Visible = sideText ~= nil
refs.button.container.sideText.Text = if sideText ~= nil then sideText else ""
Expand Down

0 comments on commit 77cfe2a

Please sign in to comment.