Skip to content

Commit

Permalink
Replace debugger getEntity calls (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
memorycode authored Oct 22, 2024
1 parent cad64b2 commit ad1714a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
19 changes: 19 additions & 0 deletions lib/debugger/getAllComponentData.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local function getAllComponentData(world, entity: number): { [{ [any]: any }]: { [any]: any } }
local componentToData = {}

local location = world.allEntities[entity]
local archetype = location.archetype
local indexInArchetype = location.indexInArchetype

for index, field in archetype.fields do
local componentId = archetype.componentIds[index]
local component = world.componentIdToComponent[componentId]
local data = field[indexInArchetype]

componentToData[component] = data
end

return componentToData
end

return getAllComponentData
14 changes: 3 additions & 11 deletions lib/debugger/widgets/entityInspect.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local formatTableModule = require(script.Parent.Parent.formatTable)
local getAllComponentData = require(script.Parent.Parent.getAllComponentData)
local formatTable = formatTableModule.formatTable
local FormatMode = formatTableModule.FormatMode

Expand Down Expand Up @@ -38,19 +39,10 @@ return function(plasma)
end

local items = { { "Component", "Data" } }

local location = world.allEntities[debugger.debugEntity]
local archetype = location.archetype
local indexInArchetype = location.indexInArchetype

for index, field in archetype.fields do
local componentId = archetype.componentIds[index]
local component = world.componentIdToComponent[componentId]
local data = field[indexInArchetype]

for component, componentData in getAllComponentData(world, debugger.debugEntity) do
table.insert(items, {
tostring(component),
formatTable(data, FormatMode.Long),
formatTable(componentData, FormatMode.Long),
})
end

Expand Down
3 changes: 2 additions & 1 deletion lib/debugger/widgets/hoverInspect.luau
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
local formatTableModule = require(script.Parent.Parent.formatTable)
local getAllComponentData = require(script.Parent.Parent.getAllComponentData)
local formatTable = formatTableModule.formatTable
local FormatMode = formatTableModule.FormatMode

return function(plasma)
return plasma.widget(function(world, id, custom)
local entityData = world:_getEntity(id)
local entityData = getAllComponentData(world, id)

local str = "<b>Entity " .. id .. "</b>\n\n"

Expand Down
3 changes: 2 additions & 1 deletion lib/debugger/widgets/worldInspect.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local formatTableModule = require(script.Parent.Parent.formatTable)
local getAllComponentData = require(script.Parent.Parent.getAllComponentData)
local formatTable = formatTableModule.formatTable

local BY_COMPONENT_NAME = "ComponentName"
Expand Down Expand Up @@ -140,7 +141,7 @@ return function(plasma)
continue
end

for component, value in world:_getEntity(entityId) do
for component, value in getAllComponentData(world, entityId) do
if component == debugComponent then
continue
end
Expand Down

0 comments on commit ad1714a

Please sign in to comment.