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

Replace debugger getEntity calls #129

Merged
merged 2 commits into from
Oct 22, 2024
Merged
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
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
Loading