Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System search bar #113

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ The format is based on [Keep a Changelog][kac], and this project adheres to

## [Unreleased]

### Added

- Better assertions / error messages added to `World` methods that accept
variadic component arguments. At least 1 component must be provided. These
assertions have been added to `get` `insert` `replace` `remove`
- Ability to sort the world inspect table by clicking the table headers (entity
count and component name)

- Ability to search through systems in the **client debugger** system list.
- This is not yet possible in the **server debugger**.

### Changed

- The alt-hover tooltip's text is smaller and the background is slightly darker
for improved legibility.
- Component data now has syntax highlighting applied. This is present in the
**alt-hover tooltip** and the **entity inspector panel** in the debugger.

### Fixed

- The alt-hover tooltip now displays component data properly, with each
component being displayed on a new line.
- Removed extra new-lines in component data strings within the debugger entity
inspect tables.
- Fixed alt-hover erroring when hovered entity is despawned.

## [0.8.3] - 2024-07-02

### Fixed
Expand Down
41 changes: 31 additions & 10 deletions lib/debugger/clientBindings.luau
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
local UserInputService = game:GetService("UserInputService")
local CollectionService = game:GetService("CollectionService")

local tags = {
system = "MatterDebuggerTooltip_System",
altHover = "MatterDebuggerTooltip_AltHover",
}

local fromOffset = UDim2.fromOffset
Nidoxs marked this conversation as resolved.
Show resolved Hide resolved

local function getOffset(mousePos: Vector2, tag: string): UDim2
if tag == tags.altHover then
return fromOffset(mousePos.X + 20, mousePos.Y)
elseif tag == tags.system then
return fromOffset(mousePos.X + 20, mousePos.Y + 10)
end

return fromOffset(mousePos.X, mousePos.Y + 10)
end

local function clientBindings(debugger)
local connections = {}

Expand All @@ -21,20 +39,23 @@ local function clientBindings(debugger)

local mousePosition = UserInputService:GetMouseLocation()

for _, gui in CollectionService:GetTagged("MatterDebuggerTooltip") do
gui.Position = UDim2.new(0, mousePosition.X + 20, 0, mousePosition.Y)
for _, tag in tags do
for _, gui in CollectionService:GetTagged(tag) do
gui.Position = getOffset(mousePosition, tag)
end
end
end)
)

table.insert(
connections,
CollectionService:GetInstanceAddedSignal("MatterDebuggerTooltip"):Connect(function(gui)
local mousePosition = UserInputService:GetMouseLocation()

gui.Position = UDim2.new(0, mousePosition.X + 20, 0, mousePosition.Y)
end)
)
for _, tag in tags do
table.insert(
connections,
CollectionService:GetInstanceAddedSignal(tag):Connect(function(gui)
local mousePosition = UserInputService:GetMouseLocation()
gui.Position = getOffset(mousePosition, tag)
end)
)
end

return connections
end
Expand Down
1 change: 1 addition & 0 deletions lib/debugger/debugger.luau
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ local customWidgetConstructors: { [string]: any } = {
queryInspect = require(script.Parent.widgets.queryInspect),
codeText = require(script.Parent.widgets.codeText),
errorInspect = require(script.Parent.widgets.errorInspect),
textField = require(script.Parent.widgets.textField),
}

local IS_SERVER = RunService:IsServer()
Expand Down
189 changes: 142 additions & 47 deletions lib/debugger/ui.luau
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local RunService = game:GetService("RunService")
local World = require(script.Parent.Parent.World)
local rollingAverage = require(script.Parent.Parent.rollingAverage)

local match, lower = string.match, string.lower

local function systemName(system)
local systemFn = if type(system) == "table" then system.system else system
local name = debug.info(systemFn, "n")
Expand Down Expand Up @@ -29,10 +31,12 @@ end

local IS_SERVER = RunService:IsServer()
local IS_CLIENT = RunService:IsClient()
local LONG_SYSTEM_NAME = 24

local function ui(debugger, loop)
local plasma = debugger.plasma
local custom = debugger._customWidgets
local skipSystems = loop._skipSystems

plasma.setStyle({
primaryColor = Color3.fromHex("bd515c"),
Expand All @@ -48,6 +52,8 @@ local function ui(debugger, loop)
end
end

local hoveredSystem

custom.container(function()
if debugger:_isServerView() then
return
Expand Down Expand Up @@ -124,10 +130,19 @@ local function ui(debugger, loop)

plasma.space(15)
plasma.heading("SYSTEMS")

local searchFilter = ""
if IS_CLIENT then
plasma.space(5)
local textField = custom.textField("Search...")
searchFilter = textField:text()
searchFilter = string.gsub(searchFilter, "%s+", "")
end

plasma.space(10)

local durations = {}
local longestDuration = 0
local searchResults = {}
local noResults = true

for _, eventName in debugger._eventOrder do
local systems = loop._orderedSystemsByEvent[eventName]
Expand All @@ -136,65 +151,128 @@ local function ui(debugger, loop)
continue
end

plasma.heading(eventName, {
font = Enum.Font.Gotham,
})
plasma.space(5)
for _, system in systems do
local nameOfSystem = systemName(system)
local noMatch = searchFilter ~= "" and not match(lower(nameOfSystem), lower(searchFilter))

local items = {}
if noMatch then
continue
end

for _, system in systems do
local samples = loop.profiling[system]
if samples then
local duration = rollingAverage.getAverage(samples)
durations[system] = duration
longestDuration = math.max(longestDuration, duration)
if searchResults[eventName] == nil then
searchResults[eventName] = {}
end

searchResults[eventName][nameOfSystem] = true
noResults = false
end
end

for index, system in systems do
local averageFrameTime = ""
local icon
if noResults then
plasma.label("No search results")
else
local durations = {}
local longestDuration = 0

local duration = durations[system] or 0
local humanDuration, unit = formatDuration(duration)
averageFrameTime = string.format("%.0f%s", humanDuration, unit)
for _, eventName in debugger._eventOrder do
local systems = loop._orderedSystemsByEvent[eventName]
local searchResultsForEvent = searchResults[eventName]

if duration > 0.004 then -- 4ms
icon = "\xe2\x9a\xa0\xef\xb8\x8f"
if not systems or searchResultsForEvent == nil then
continue
end

if loop._systemErrors[system] then
icon = "\xf0\x9f\x92\xa5"
plasma.heading(eventName, {
font = Enum.Font.Gotham,
})
plasma.space(5)

local listOfSystems = {}

for _, system in systems do
local samples = loop.profiling[system]
if samples then
local duration = rollingAverage.getAverage(samples)
durations[system] = duration
longestDuration = math.max(longestDuration, duration)
end
end

table.insert(items, {
text = systemName(system),
sideText = averageFrameTime,
selected = debugger.debugSystem == system,
system = system,
icon = icon,
barWidth = duration / longestDuration,
index = index,
})
end
for index, system in systems do
local nameOfSystem = systemName(system)

if searchResultsForEvent[nameOfSystem] == nil then
continue
end

local selected = custom.selectionList(items):selected()
if selected then
if selected.system == debugger.debugSystem then
debugger.debugSystem = nil
local averageFrameTime = ""
local icon

local duration = durations[system] or 0
local humanDuration, unit = formatDuration(duration)
averageFrameTime = string.format("%.0f%s", humanDuration, unit)

if duration > 0.004 then -- 4ms
icon = "\xe2\x9a\xa0\xef\xb8\x8f"
end

if loop._systemErrors[system] then
icon = "\xf0\x9f\x92\xa5"
end

local barWidth
if longestDuration == 0 then
barWidth = 0
else
barWidth = duration / longestDuration
end

local systemIsDisabled = skipSystems[system]
local systemName = systemName(system)
local length = string.len(systemName)

if systemIsDisabled then
length += 4
end

table.insert(listOfSystems, {
text = if systemIsDisabled then `<i><s>{systemName}</s></i>` else systemName,
sideText = if systemIsDisabled then `<b>{"(disabled)"}</b>` else averageFrameTime,
selected = debugger.debugSystem == system,
system = system,
icon = icon,
barWidth = barWidth,
index = index,
})
end

local systemList = custom.selectionList(listOfSystems, custom)
local selected = systemList:selected()
local rightClicked = systemList:rightClicked()
hoveredSystem = systemList:hovered()

if selected then
local selectedSystem = selected.system
if selectedSystem == debugger.debugSystem then
debugger.debugSystem = nil
else
debugger.debugSystem = selectedSystem
end
elseif rightClicked then
local rightClickedSystem = rightClicked.system
if rightClickedSystem then
skipSystems[rightClickedSystem] = not skipSystems[rightClickedSystem]
end
end

if debugger.debugSystem then
debugger.debugSystemRuntime = durations[debugger.debugSystem]
else
debugger.debugSystem = selected.system
debugger.debugSystemRuntime = nil
end
end

if debugger.debugSystem then
debugger.debugSystemRuntime = durations[debugger.debugSystem]
else
debugger.debugSystemRuntime = nil
plasma.space(10)
end

plasma.space(10)
end
end)

Expand Down Expand Up @@ -246,7 +324,7 @@ local function ui(debugger, loop)
end
end)

local currentlyDisabled = loop._skipSystems[debugger.debugSystem]
local currentlyDisabled = skipSystems[debugger.debugSystem]

if
plasma
Expand All @@ -255,7 +333,7 @@ local function ui(debugger, loop)
})
:clicked()
then
loop._skipSystems[debugger.debugSystem] = not currentlyDisabled
skipSystems[debugger.debugSystem] = not currentlyDisabled
end
end)
:closed()
Expand Down Expand Up @@ -311,6 +389,23 @@ local function ui(debugger, loop)
direction = Enum.FillDirection.Horizontal,
padding = 0,
})

if hoveredSystem and hoveredSystem.system then
local hoveredSystemName = systemName(hoveredSystem.system)
local length = string.len(hoveredSystemName)
local systemDisabled = skipSystems[hoveredSystem.system]

if systemDisabled then
length += 2
end

if length >= LONG_SYSTEM_NAME then
custom.tooltip(`<b>{hoveredSystemName}{if systemDisabled then " (disabled)" else ""}</b>`, {
tag = "MatterDebuggerTooltip_System",
backgroundTransparency = 0,
})
end
end
end

return ui
5 changes: 4 additions & 1 deletion lib/debugger/widgets/hoverInspect.luau
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ return function(plasma)
end
end

custom.tooltip(str)
custom.tooltip(str, {
tag = "MatterDebuggerTooltip_AltHover",
backgroundTransparency = 0.15,
})
end)
end
Loading
Loading