Skip to content

Commit

Permalink
as-is, from video demo
Browse files Browse the repository at this point in the history
  • Loading branch information
benbrimeyer committed Mar 3, 2024
1 parent 47492c6 commit 1f8dfab
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 87 deletions.
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

0 comments on commit 1f8dfab

Please sign in to comment.