Skip to content
Draft
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
8 changes: 8 additions & 0 deletions example/src/shared/start.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ local function start(containers)
loop:scheduleSystems(firstRunSystems)
firstRunSystems = nil

debugger.queryForWatchedEntities = function(world)
return world:query(components.Model)
end

debugger.labelForWatchedEntities = function(entityId)
return world:get(entityId, components.Model).model.Name
end

debugger:autoInitialize(loop)

-- Begin running our systems
Expand Down
214 changes: 127 additions & 87 deletions lib/debugger/widgets/worldInspect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ return function(plasma)
-- TODO #97 Implement sorting by descending as well.
local ascendingOrder, _ = plasma.useState(false)
local skipIntersections, setSkipIntersections = plasma.useState(true)
local filterForWatched, setFilteredForWatched = plasma.useState(false)
local debugComponent, setDebugComponent = plasma.useState()

local closed = plasma
Expand Down Expand Up @@ -53,136 +54,175 @@ return function(plasma)
key = "Raw World",
}
end
end)

plasma.row({ padding = 15 }, function()
if plasma.checkbox("Show intersections", { checked = not skipIntersections }):clicked() then
setSkipIntersections(not skipIntersections)
if plasma.checkbox("Filter watched", { checked = filterForWatched }):clicked() then
setFilteredForWatched(not filterForWatched)
end
end)

local items = {}
for component, count in cache.uniqueComponents do
table.insert(items, {
count,
tostring(component),
selected = debugComponent == component,
component = component,
})
if not filterForWatched then
plasma.row({ padding = 15 }, function()
if plasma.checkbox("Show intersections", { checked = not skipIntersections }):clicked() then
setSkipIntersections(not skipIntersections)
end
end)
end

table.sort(items, function(a, b)
if ascendingOrder then
return a[1] < b[1]
if filterForWatched then
local items = {}
local shouldShowLabels = debugger.labelForWatchedEntities ~= nil

for entityId, _ in debugger.queryForWatchedEntities(debugger.debugWorld) do
table.insert(items, {
entityId,
if shouldShowLabels then debugger.labelForWatchedEntities(entityId) else nil,
selected = debugger.debugEntity == entityId,
})
end
table.sort(items, function(a, b)
return a[1] < b[1]
end)

-- Default to alphabetical
return a[2] < b[2]
end)
table.insert(items, 1, { "Entity ID", if shouldShowLabels then "Label" else nil })

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

plasma.row({ padding = 30 }, function()
local selectedRow = plasma
.table(items, {
width = 200,
headings = true,
selectable = true,
font = Enum.Font.Code,
if selectedRow then
debugger.debugEntity = selectedRow[1]
end
end)
else
local items = {}
for component, count in cache.uniqueComponents do
table.insert(items, {
count,
tostring(component),
selected = debugComponent == component,
component = component,
})
:selected()

if selectedRow then
setDebugComponent(selectedRow.component)
end

if debugComponent then
local items = { { "Entity ID", tostring(debugComponent) } }
local intersectingComponents = {}
table.sort(items, function(a, b)
if ascendingOrder then
return a[1] < b[1]
end

local intersectingData = {}
-- Default to alphabetical
return a[2] < b[2]
end)

for entityId, data in world:query(debugComponent) do
table.insert(items, {
entityId,
formatTable(data),
table.insert(items, 1, { "Count", "Component" })

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

intersectingData[entityId] = {}
if selectedRow then
setDebugComponent(selectedRow.component)
end

if skipIntersections then
continue
end
if debugComponent then
local items = { { "Entity ID", tostring(debugComponent) } }
local intersectingComponents = {}

for component, value in world:_getEntity(entityId) do
if component == debugComponent then
local intersectingData = {}

for entityId, data in world:query(debugComponent) do
table.insert(items, {
entityId,
formatTable(data),

selected = debugger.debugEntity == entityId,
})

intersectingData[entityId] = {}

if skipIntersections then
continue
end

local index = table.find(intersectingComponents, component)
for component, value in world:_getEntity(entityId) do
if component == debugComponent then
continue
end

if not index then
table.insert(intersectingComponents, component)
local index = table.find(intersectingComponents, component)

index = #intersectingComponents
end
if not index then
table.insert(intersectingComponents, component)

intersectingData[entityId][index] = value
end
end
index = #intersectingComponents
end

for i, item in items do
if i == 1 then
for _, component in intersectingComponents do
table.insert(item, tostring(component))
intersectingData[entityId][index] = value
end

continue
end

for i = 1, #intersectingComponents do
local data = intersectingData[item[1]][i]
for i, item in items do
if i == 1 then
for _, component in intersectingComponents do
table.insert(item, tostring(component))
end

table.insert(item, if data then formatTable(data) else "")
end
end
continue
end

plasma.useKey(tostring(debugComponent))
for i = 1, #intersectingComponents do
local data = intersectingData[item[1]][i]

local tableWidget = plasma.table(items, {
font = Enum.Font.Code,
selectable = true,
headings = true,
})
table.insert(item, if data then formatTable(data) else "")
end
end

local selectedRow = tableWidget:selected()
local hovered = tableWidget:hovered()
plasma.useKey(tostring(debugComponent))

if selectedRow then
debugger.debugEntity = selectedRow[1]
end
local tableWidget = plasma.table(items, {
font = Enum.Font.Code,
selectable = true,
headings = true,
})

if hovered then
local entityId = hovered[1]
local selectedRow = tableWidget:selected()
local hovered = tableWidget:hovered()

if debugger.debugEntity == entityId or not world:contains(entityId) then
return
if selectedRow then
debugger.debugEntity = selectedRow[1]
end

if debugger.findInstanceFromEntity then
local model = debugger.findInstanceFromEntity(entityId)
if hovered then
local entityId = hovered[1]

if debugger.debugEntity == entityId or not world:contains(entityId) then
return
end

if debugger.findInstanceFromEntity then
local model = debugger.findInstanceFromEntity(entityId)

if model then
plasma.highlight(model, {
fillColor = style.primaryColor,
})
if model then
plasma.highlight(model, {
fillColor = style.primaryColor,
})
end
end
end
end
end
end)
end)
end
end)
:closed()

Expand Down